:root {
  color-scheme: dark;
  --bg: #0c0d0e;
  --panel: #121416;
  --panel-2: #171a1d;
  --panel-3: #1d2023;
  --line: #292d31;
  --line-strong: #3b4146;
  --muted: #92999f;
  --text: #ece9e2;
  --accent: #d7ff72;
  --accent-ink: #111509;
  --warm: #d7a67c;
  --danger: #ff8e83;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 18% 2%, rgba(215, 255, 114, .055), transparent 28rem),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-wrap: anywhere;
}
button, input, textarea, select { font: inherit; }
button, select, summary { cursor: pointer; touch-action: manipulation; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(185px, .75fr) minmax(460px, 1.7fr) minmax(170px, .65fr);
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 13, 14, .88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 11px; letter-spacing: .01em; min-width: 0; }
.brand-mark { color: var(--accent); font-size: 28px; line-height: 1; flex: 0 0 auto; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .04em; white-space: nowrap; }
.campaign-controls { display: grid; grid-template-columns: minmax(130px, .8fr) minmax(190px, 1.15fr) minmax(125px, .65fr) auto 112px; align-items: end; gap: 8px; min-width: 0; }
.compact-field { display: grid; gap: 2px; min-width: 0; }
.compact-field > span { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding-left: 2px; }
.compact-field select { width: 100%; min-width: 0; }
.token-field input { min-width: 0; }
.campaign-controls > .button { min-height: 44px; }
.compact-toggle { min-height: 44px; display: flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--panel-2); font-size: 11px; white-space: nowrap; }
.compact-toggle input, .sheet-toggle input { width: 20px; min-height: 20px; flex: 0 0 20px; padding: 0; accent-color: var(--accent); }
.compact-toggle:has(input:checked) { color: var(--text); border-color: #4a5238; }
.status-chips { justify-self: end; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { border: 1px solid var(--line); color: var(--muted); border-radius: 99px; padding: 5px 9px; font-size: 11px; background: var(--panel); white-space: nowrap; }
.mobile-bar { display: none; }
.mobile-icon-button { width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--text); background: var(--panel-2); }
.mobile-icon-button svg, .send-icon { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.send-icon { display: none; }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) 292px; min-height: calc(100vh - 76px); min-height: calc(100dvh - 76px); }
.story-panel { min-width: 0; display: grid; grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); }
.empty-state, .messages { grid-area: 1 / 1; }
.composer-wrap { grid-area: 2 / 1; }
.side-panel { border-left: 1px solid var(--line); background: rgba(18, 20, 22, .62); }
.side-details { height: 100%; }
.side-details > summary { display: none; }
.side-content { height: 100%; padding: 34px 24px; display: flex; flex-direction: column; gap: 28px; }
.side-panel h2 { margin: 4px 0 8px; font-size: 19px; }
.side-panel p { color: var(--muted); margin: 0; font-size: 13px; }
.side-actions { display: grid; gap: 8px; }
.protocol-card { margin-top: auto; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.protocol-card strong { font-size: 13px; }
.protocol-card p { margin-top: 8px; }
code { color: var(--accent); background: rgba(215, 255, 114, .07); border-radius: 5px; padding: 1px 4px; }

.empty-state { align-self: center; justify-self: center; width: min(650px, calc(100% - 48px)); padding: 70px 0; }
.empty-state h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(34px, 5vw, 64px); line-height: 1.03; letter-spacing: -.035em; margin: 10px 0 20px; }
.empty-state p { color: var(--muted); max-width: 560px; font-size: 17px; margin: 0 0 28px; }
.eyebrow { color: var(--accent); text-transform: uppercase; font-size: 10px; font-weight: 700; letter-spacing: .16em; }

.messages { width: min(820px, calc(100% - 42px)); margin: 0 auto; padding: 42px 0 180px; }
.message { margin: 0 0 28px; }
.message-label { color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 7px; }
.message.user { margin-left: clamp(28px, 9vw, 110px); padding: 15px 17px; border: 1px solid var(--line); border-radius: 15px 15px 3px 15px; background: var(--panel-2); }
.message.user .message-label { color: var(--warm); }
.message.author-note { border-left: 2px solid #6f7680; padding: 8px 0 8px 14px; color: var(--muted); font-size: 13px; }
.message.assistant { font-family: Georgia, "Times New Roman", serif; font-size: 18px; line-height: 1.72; letter-spacing: .003em; }
.message.assistant p { margin: 0 0 13px; white-space: pre-wrap; }
.message.assistant em { color: #d3d0c9; }
.pending-message { animation: pending-in .18s ease-out both; }
.typing-indicator { min-height: 30px; display: flex; align-items: center; gap: 9px; color: var(--muted); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 13px; }
.typing-label { white-space: nowrap; }
.typing-dots { display: inline-flex; align-items: center; gap: 4px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: typing-dot 1.05s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .14s; }
.typing-dots i:nth-child(3) { animation-delay: .28s; }
@keyframes pending-in { from { opacity: 0; translate: 0 5px; } }
@keyframes typing-dot { 0%, 60%, 100% { opacity: .28; translate: 0 0; } 30% { opacity: 1; translate: 0 -3px; } }

.composer-wrap { position: sticky; bottom: 0; z-index: 3; padding: 12px 22px calc(20px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 25%); }
.composer { max-width: 840px; margin: 0 auto; border: 1px solid #363b3f; border-radius: var(--radius); background: #16191b; box-shadow: 0 24px 60px rgba(0,0,0,.35); overflow: hidden; }
.composer textarea { width: 100%; resize: vertical; min-height: 92px; border: 0; outline: 0; padding: 18px 18px 8px; color: var(--text); background: transparent; line-height: 1.5; }
.composer textarea::placeholder { color: #666e74; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px 10px 18px; }
.format-hint, .turn-meta { color: var(--muted); font-size: 11px; }
.turn-meta { max-width: 840px; min-height: 18px; margin: 0 auto 5px; text-align: right; }

.button { min-height: 44px; border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; color: var(--text); background: transparent; font-weight: 650; font-size: 13px; }
.button:disabled { opacity: .36; cursor: not-allowed; }
.button.primary { color: var(--accent-ink); background: var(--accent); }
.button.primary:hover:not(:disabled) { background: #e1ff91; }
.button.secondary { border-color: var(--line); background: var(--panel-2); }
.button.secondary:hover:not(:disabled), .button.ghost:hover:not(:disabled) { border-color: #444b50; background: #1c2023; }
.button.ghost { border-color: transparent; color: var(--muted); }
.button:active, .icon-button:active, .remove-npc:active, .config-section > summary:active { opacity: .78; }
.side-actions .button { text-align: left; }
select, input, textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--text); padding: 9px 11px; outline: none; font-size: 15px; }
textarea { resize: vertical; }
select:focus, input:focus, textarea:focus { border-color: #69764d; box-shadow: 0 0 0 3px rgba(215,255,114,.07); }

.modal { width: min(900px, calc(100% - 28px)); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow: auto; border: 1px solid #383d42; border-radius: 18px; color: var(--text); background: #111315; padding: 24px; box-shadow: 0 30px 100px rgba(0,0,0,.7); }
.campaign-modal { width: min(1040px, calc(100% - 28px)); padding: 0; }
.campaign-modal form { min-height: 100%; }
.modal::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.sticky-head { position: sticky; top: 0; z-index: 3; margin: 0; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); background: rgba(17,19,21,.96); backdrop-filter: blur(12px); }
.modal h2 { margin: 3px 0 0; font-size: 24px; }
.icon-button { width: 44px; height: 44px; flex: 0 0 44px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: var(--panel-2); font-size: 24px; line-height: 1; }
.config-sections { display: grid; gap: 12px; padding: 18px 24px; }
.config-section { border: 1px solid var(--line); border-radius: 13px; background: #141719; overflow: clip; }
.config-section[open] { border-color: #353b3f; }
.config-section > summary { min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 12px 16px; list-style: none; user-select: none; }
.config-section > summary::-webkit-details-marker { display: none; }
.config-section > summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 22px; }
.config-section[open] > summary::after { content: "−"; }
.config-section > summary strong, .config-section > summary small { display: block; }
.config-section > summary strong { font-size: 14px; }
.config-section > summary small { margin-top: 1px; color: var(--muted); font-size: 11px; font-weight: 400; }
.step-number { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border: 1px solid #4a5238; border-radius: 99px; color: var(--accent); font-size: 12px; font-weight: 800; }
.section-body { padding: 4px 16px 18px; border-top: 1px solid var(--line); }
.form-grid, .profile-grid { display: grid; gap: 14px; }
.form-grid { grid-template-columns: 1fr 1fr; padding-top: 16px; }
.profile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid label, .profile-grid label { display: grid; align-content: start; gap: 6px; color: var(--muted); font-size: 12px; min-width: 0; }
.wide { grid-column: 1 / -1; }
.field-help { color: #747c82; font-size: 10px; }
.character-card { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.character-card-head { min-height: 32px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.character-card-head strong { font-size: 14px; }
.character-card-head span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.remove-npc { min-height: 44px; border: 0; padding: 5px 8px; border-radius: 7px; color: var(--muted); background: transparent; font-size: 11px; }
.remove-npc:hover { color: var(--danger); background: rgba(255,142,131,.07); }
.npc-profiles { display: grid; gap: 12px; }
.add-npc { width: 100%; margin-top: 12px; border-style: dashed; }
.section-note { margin: 12px 2px 0; color: var(--muted); font-size: 11px; }
.standalone-field { display: grid; gap: 6px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.check { display: flex !important; flex-direction: row; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.check input { width: 22px; min-height: 22px; margin: 1px 8px 0 0; flex: 0 0 22px; accent-color: var(--accent); }
.sticky-actions { position: sticky; bottom: 0; z-index: 3; display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 14px 24px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(17,19,21,.96); backdrop-filter: blur(12px); }
.memory-modal { width: min(900px, calc(100% - 28px)); }
.memory-content { display: grid; gap: 24px; }
.memory-section h3 { font-size: 13px; margin: 0 0 10px; color: var(--accent); }
.memory-row { display: grid; grid-template-columns: minmax(140px, .45fr) 1fr; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.memory-key { color: var(--muted); word-break: break-word; }
.event { padding: 12px 0; border-bottom: 1px solid var(--line); }
.event small { color: var(--muted); display: block; margin-bottom: 3px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); translate: -50% 12px; opacity: 0; pointer-events: none; max-width: min(560px, calc(100% - 28px)); padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: #202428; box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: .2s ease; }
.toast.visible { translate: -50% 0; opacity: 1; }
.toast.error { color: var(--danger); border-color: rgba(255,142,131,.4); }
.mobile-controls-dialog { color: var(--text); background: var(--panel); }
.mode-help { min-height: 18px; margin: -5px 0 2px; color: var(--muted); font-size: 11px; }
.logout-action { color: var(--danger); }

.auth-dialog {
  width: min(430px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid #3a4044;
  border-radius: 20px;
  color: var(--text);
  background: #111315;
  box-shadow: 0 34px 110px rgba(0,0,0,.78);
}
.auth-dialog::backdrop { background: rgba(0,0,0,.84); backdrop-filter: blur(8px); }
.auth-card { display: grid; gap: 28px; padding: 30px; }
.auth-brand { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 13px; letter-spacing: .02em; }
.auth-brand span { color: var(--accent); font-size: 24px; line-height: 1; }
.auth-copy h1 { margin: 5px 0 8px; font-family: Georgia, "Times New Roman", serif; font-size: 39px; font-weight: 400; line-height: 1; letter-spacing: -.025em; }
.auth-copy p { margin: 0; color: var(--muted); }
.auth-form { display: grid; gap: 15px; }
.auth-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.auth-error { min-height: 22px; color: var(--danger); font-size: 12px; line-height: 1.4; }
.auth-submit { width: 100%; }

@media (max-width: 1220px) {
  .topbar { grid-template-columns: minmax(170px, .55fr) minmax(620px, 1.9fr); }
  .status-chips { display: none; }
  .profile-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; gap: 9px 12px; padding: 10px 14px; }
  .campaign-controls { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, .8fr) minmax(0, 1.15fr) minmax(118px, .65fr) 105px auto; }
  .stage { grid-template-columns: 1fr; min-height: calc(100dvh - 132px); }
  .side-panel { border-left: 0; border-top: 1px solid var(--line); padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); }
  .side-details { height: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
  .side-details > summary { min-height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; color: var(--muted); font-size: 12px; list-style: none; }
  .side-details > summary::-webkit-details-marker { display: none; }
  .side-details > summary::after { content: "+"; font-size: 18px; }
  .side-details[open] > summary::after { content: "−"; }
  .side-content { height: auto; padding: 4px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .protocol-card { margin: 0; grid-column: 1 / -1; }
}

@media (max-width: 720px), (max-height: 520px) and (max-width: 960px) {
  html, body { width: 100%; height: 100%; overflow: hidden; }
  body { font-size: 16px; background: var(--bg); }
  select, input, textarea { font-size: 16px; }

  .app-shell { width: 100%; height: 100vh; height: 100dvh; min-height: 0; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
  .topbar {
    position: relative;
    min-height: 60px;
    display: block;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    border-bottom-color: rgba(41,45,49,.76);
    background: rgba(12,13,14,.94);
  }
  .brand, .campaign-controls, .status-chips { display: none; }
  .mobile-bar { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .mobile-brand { min-width: 0; display: flex; align-items: center; gap: 10px; }
  .mobile-brand-mark { color: var(--accent); font-size: 25px; line-height: 1; }
  .mobile-brand strong { min-width: 0; max-width: min(54vw, 320px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; letter-spacing: -.01em; }
  .mobile-bar-actions { display: flex; gap: 8px; }
  .mobile-icon-button { background: #151719; }

  .stage { display: block; height: 100%; min-height: 0; overflow: hidden; }
  .story-panel { height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .side-panel { display: none; }
  .empty-state { width: calc(100% - 34px); min-height: 0; flex: 1; align-self: auto; justify-self: auto; margin: auto; padding: 38px 0; overflow-y: auto; }
  .empty-state h1 { font-size: clamp(31px, 10vw, 44px); }
  .empty-state p { font-size: 16px; }

  .messages {
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
    margin: 0;
    padding: 24px 17px 18px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
  }
  .message { margin-bottom: 25px; }
  .message.user { width: fit-content; max-width: 88%; margin-left: auto; padding: 12px 15px; border-radius: 20px 20px 5px 20px; font-size: 16px; }
  .message-label { display: none; }
  .message.author-note { width: fit-content; max-width: 88%; margin: -9px 0 25px auto; padding: 11px 15px; border: 1px solid #41464b; border-radius: 20px 20px 5px 20px; color: #d8d9da; background: #292c2f; font-size: 15px; }
  .message.assistant { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 17px; line-height: 1.66; letter-spacing: 0; }
  .message.assistant p { margin-bottom: 15px; }
  .typing-indicator { margin: -5px 0 18px; font-size: 13px; }

  .composer-wrap { position: relative; bottom: auto; z-index: 3; flex: 0 0 auto; padding: 8px 9px calc(9px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 18%); }
  .turn-meta, .format-hint { display: none; }
  .composer { position: relative; border-color: #393d42; border-radius: 25px; background: rgba(28,30,33,.97); box-shadow: 0 14px 42px rgba(0,0,0,.42); }
  .composer textarea { max-height: 150px; min-height: 72px; resize: none; padding: 15px 66px 14px 16px; line-height: 1.45; }
  .composer-footer { position: absolute; right: 10px; bottom: 10px; display: block; padding: 0; }
  .send-button { width: 48px; height: 48px; min-height: 48px; display: grid; place-items: center; padding: 0; border-radius: 50%; }
  .send-button #send-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .send-icon { display: block; }
  .send-button.loading .send-icon { opacity: .45; }

  .mobile-controls-dialog[open] {
    position: fixed;
    inset: auto 0 0;
    width: min(100%, 620px);
    max-width: 100%;
    max-height: min(82vh, 720px);
    max-height: min(82dvh, 720px);
    display: block;
    margin: 0 auto;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border: 1px solid #3b4045;
    border-bottom: 0;
    border-radius: 24px 24px 0 0;
    background: #131517;
    box-shadow: 0 -24px 80px rgba(0,0,0,.62);
  }
  .mobile-controls-dialog::backdrop { background: rgba(0,0,0,.68); backdrop-filter: blur(4px); }
  .sheet-handle { width: 42px; height: 4px; margin: 0 auto 10px; border-radius: 99px; background: #4b5055; }
  .mobile-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
  .mobile-sheet-head h2 { margin: 2px 0 0; font-size: 21px; }
  .mobile-sheet-body { display: grid; gap: 12px; }
  .sheet-field { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
  .sheet-toggle { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
  .sheet-toggle span, .sheet-toggle strong, .sheet-toggle small { display: block; }
  .sheet-toggle strong { font-size: 13px; }
  .sheet-toggle small { margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 400; }
  .mobile-sheet-divider { height: 1px; margin: 3px 0; background: var(--line); }
  .mobile-memory-actions { display: grid; }
  .sheet-action { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 4px; border: 0; border-bottom: 1px solid var(--line); color: var(--text); background: transparent; text-align: left; }
  .sheet-action:disabled { opacity: .38; }
  .sheet-chevron { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .mobile-protocol-note { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

  .modal, .campaign-modal, .memory-modal {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .modal:not(.campaign-modal) { padding: 16px; }
  .sticky-head { padding: calc(14px + env(safe-area-inset-top)) 14px 12px; }
  .modal h2 { font-size: 21px; }
  .config-sections { gap: 9px; padding: 12px; }
  .config-section > summary { min-height: 62px; padding: 10px 12px; }
  .config-section > summary small { max-width: 245px; }
  .section-body { padding: 3px 11px 14px; }
  .form-grid, .profile-grid { grid-template-columns: 1fr; gap: 12px; }
  .wide { grid-column: auto; }
  .character-card { padding: 12px; }
  .sticky-actions { justify-content: stretch; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .sticky-actions .button { flex: 1; }
  .memory-row { grid-template-columns: 1fr; gap: 3px; }
  .toast { bottom: calc(100px + env(safe-area-inset-bottom)); }

  .auth-dialog {
    width: calc(100% - 24px);
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 18px;
  }
  .auth-card { gap: 24px; padding: 25px 20px calc(25px + env(safe-area-inset-bottom)); }
  .auth-copy h1 { font-size: 35px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .typing-dots i { animation: none; opacity: .65; }
}
