/* ==========================================================================
   Noumatron — design tokens
   A stage, not a chatbox: ink-black/paper base, two accent voices (cool vs
   warm) meeting at a neutral spine. App shell: fixed viewport, sidebar +
   main pane, everything scrolls internally — nothing ever scrolls the page.
   ========================================================================== */

:root, [data-theme="light"] {
  --bg: #f1f2f5;
  --paper: #ffffff;
  --fg: #14171c;
  --fg-dim: color-mix(in srgb, var(--fg) 62%, transparent);
  --surface-alt: #e6e8ed;
  --border-fade: color-mix(in srgb, var(--fg) 14%, transparent);
  --border-strong: color-mix(in srgb, var(--fg) 28%, transparent);

  --voice-a: #0e7490;
  --voice-a-soft: #cffafe;
  --voice-b: #b45309;
  --voice-b-soft: #ffedd5;
  --neutral-voice: #6b7280;

  --accent-strong: #7c3aed;
  --danger: #b3261e;
  --danger-fg: #ffffff;

  --btn-solid-bg: var(--fg);
  --btn-solid-fg: var(--bg);
  --nav-bg: color-mix(in srgb, var(--bg) 80%, transparent);
  --nav-border: color-mix(in srgb, var(--fg) 10%, transparent);

  --sidebar-w: 264px;
  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-mono: "Space Mono", "Courier New", monospace;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  /* native <select> chevron, redrawn to match the hand-drawn icon set instead
     of whatever the OS/browser combo would otherwise render */
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2314171c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c10;
    --paper: #14171e;
    --fg: #e9ebef;
    --fg-dim: color-mix(in srgb, var(--fg) 58%, transparent);
    --surface-alt: #1b1f28;
    --border-fade: color-mix(in srgb, var(--fg) 14%, transparent);
    --border-strong: color-mix(in srgb, var(--fg) 30%, transparent);

    --voice-a: #22d3ee;
    --voice-a-soft: #113a44;
    --voice-b: #fb923c;
    --voice-b-soft: #402312;
    --neutral-voice: #9ca3af;

    --accent-strong: #a78bfa;
    --danger: #f2685e;
    --danger-fg: #1a0d0c;

    --btn-solid-bg: #ffffff;
    --btn-solid-fg: #0a0c10;
    --nav-bg: color-mix(in srgb, var(--bg) 75%, transparent);
    --nav-border: color-mix(in srgb, var(--fg) 8%, transparent);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e9ebef' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  }
}

[data-theme="dark"] {
  --bg: #0a0c10;
  --paper: #14171e;
  --fg: #e9ebef;
  --fg-dim: color-mix(in srgb, var(--fg) 58%, transparent);
  --surface-alt: #1b1f28;
  --border-fade: color-mix(in srgb, var(--fg) 14%, transparent);
  --border-strong: color-mix(in srgb, var(--fg) 30%, transparent);

  --voice-a: #22d3ee;
  --voice-a-soft: #113a44;
  --voice-b: #fb923c;
  --voice-b-soft: #402312;
  --neutral-voice: #9ca3af;

  --accent-strong: #a78bfa;
  --danger: #f2685e;
  --danger-fg: #1a0d0c;

  --btn-solid-bg: #ffffff;
  --btn-solid-fg: #0a0c10;
  --nav-bg: color-mix(in srgb, var(--bg) 75%, transparent);
  --nav-border: color-mix(in srgb, var(--fg) 8%, transparent);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e9ebef' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- hard viewport lock: nothing ever scrolls the page itself ---------- */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

::selection { background: var(--accent-strong); color: #fff; }

.mono { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.72rem; }
a { color: inherit; }

/* ---------- generic small icon button (theme toggle, back link, close, gear) ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; border-radius: 8px; flex-shrink: 0;
  border: 1px solid var(--border-fade); background: transparent; color: var(--fg);
  cursor: pointer; text-decoration: none; font-size: 0.95rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.icon-btn:hover { border-color: var(--border-strong); background: var(--surface-alt); }
.icon-btn svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle-btn .icon-sun, .theme-toggle-btn .icon-moon { display: none; }
.theme-toggle-btn[data-show="sun"] .icon-sun, .theme-toggle-btn[data-show="moon"] .icon-moon { display: block; }

/* eye / eye-off toggle on the API-key field — same show/hide-by-data-attr
   trick as the theme toggle above, so the whole icon set stays one language */
.btn-icon svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.visibility-toggle-btn .icon-eye, .visibility-toggle-btn .icon-eye-off { display: none; }
.visibility-toggle-btn[data-show="closed"] .icon-eye, .visibility-toggle-btn[data-show="open"] .icon-eye-off { display: block; }

/* small inline gear next to the account name — not a button, just a hint */
.sidebar-account-gear { display: inline-flex; color: var(--fg-dim); }
.sidebar-account-gear svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity 0.7s cubic-bezier(.22,1,.36,1), transform 0.7s cubic-bezier(.22,1,.36,1); }
.reveal.in { opacity: 1; transform: translateY(0); }

/* ==========================================================================
   PRE-APP: landing / onboarding / auth — full viewport, own scroll, no
   sidebar. A real in-flow topbar instead of floating corner buttons.
   ========================================================================== */

#pre-app { height: 100dvh; display: flex; flex-direction: column; }
#pre-app[hidden] { display: none; }

.pre-app-topbar {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 32px); border-bottom: 1px solid var(--border-fade);
}
.pre-app-back { text-decoration: none; color: var(--fg-dim); font-size: 0.68rem; transition: color 0.2s ease; }
.pre-app-back:hover { color: var(--fg); }

.pre-app-content { flex: 1; min-height: 0; overflow-y: auto; }

/* justify-content:center on a scrollable flex column clips the top of any
   content taller than the viewport (the classic flexbox-centering-vs-scroll
   bug) — so centering is opt-in via .view-narrow, and panels/hero center
   themselves with margin:auto instead, which stays scroll-safe either way. */
.view { display: flex; flex-direction: column; align-items: center; min-height: 100%; padding: 40px clamp(20px, 6vw, 80px) 56px; }
.view[hidden] { display: none; }
.view-narrow { justify-content: center; }

/* ---------- hero / landing ---------- */
.hero { max-width: 780px; text-align: center; display: flex; flex-direction: column; align-items: center; margin: auto; }

.wordmark { display: flex; align-items: center; gap: 12px; margin-bottom: 2.2rem; }
.wm-glyph { position: relative; width: 34px; height: 20px; display: inline-flex; align-items: center; justify-content: center; }
.wm-dot { width: 8px; height: 8px; border-radius: 50%; position: absolute; }
.wm-dot.a { left: 0; background: var(--voice-a); }
.wm-dot.b { right: 0; background: var(--voice-b); }
.wm-arc { position: absolute; left: 8px; right: 8px; top: 50%; height: 1px; background: linear-gradient(90deg, var(--voice-a), var(--voice-b)); }
.wm-text { font-family: var(--font-mono); font-weight: 700; letter-spacing: 0.22em; font-size: 0.85rem; }

h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(2.1rem, 5.2vw, 3.6rem); line-height: 1.08; }
h1 em { font-style: italic; background: linear-gradient(90deg, var(--voice-a), var(--voice-b)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.hero-lead { margin-top: 1.4rem; max-width: 56ch; font-size: clamp(0.95rem, 1.4vw, 1.08rem); line-height: 1.6; color: var(--fg-dim); }

@keyframes caret-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 2.4rem; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-sans); font-weight: 600; font-size: 0.86rem;
  padding: 0.85rem 1.5rem; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 0.5rem; justify-content: center;
  transition: transform 0.2s cubic-bezier(.22,1,.36,1), background 0.18s ease, color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn .arrow { transition: transform 0.3s cubic-bezier(.22,1,.36,1); }
.btn:hover:not(:disabled) .arrow { transform: translateX(3px); }
.btn-solid { background: var(--btn-solid-bg); color: var(--btn-solid-fg); }
.btn-solid:hover:not(:disabled) { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: var(--danger-fg); }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--fg-dim); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { color: var(--fg); }
.btn-icon { background: transparent; border: 1px solid var(--border-fade); border-radius: 8px; width: 2.1rem; height: 2.1rem; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--fg); font-size: 0.95rem; flex-shrink: 0; }
.btn-icon:hover { border-color: var(--border-strong); }
.file-btn { position: relative; overflow: hidden; cursor: pointer; text-align: center; }

/* ---------- panels / forms (auth, apikey, seed, settings) ---------- */
.panel { width: 100%; max-width: 460px; background: var(--paper); border: 1px solid var(--border-fade); border-radius: 20px; padding: clamp(24px, 4vw, 38px); box-shadow: 0 20px 60px -30px rgba(0,0,0,0.35); margin: auto; }
.panel-title { font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; margin-bottom: 0.6rem; }
.fineprint { font-size: 0.8rem; line-height: 1.55; color: var(--fg-dim); margin-bottom: 1.4rem; }
.fineprint a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }

.panel-tabs { display: flex; gap: 4px; margin-bottom: 1.4rem; background: var(--surface-alt); padding: 4px; border-radius: 999px; }
.panel-tabs .tab { flex: 1; border: none; background: transparent; padding: 0.6rem 0.8rem; border-radius: 999px; cursor: pointer; color: var(--fg-dim); font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; transition: background 0.2s ease, color 0.2s ease; }
.panel-tabs .tab.active { background: var(--paper); color: var(--fg); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form[hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field > span { color: var(--fg-dim); }
input[type=text], input[type=password], input[type=number], select, textarea {
  font-family: var(--font-sans); font-size: 0.95rem; padding: 0.75rem 0.9rem;
  border-radius: 10px; border: 1px solid var(--border-fade); background: var(--bg); color: var(--fg);
  transition: border-color 0.2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-strong); }
textarea { resize: vertical; font-family: var(--font-sans); line-height: 1.5; }

/* redraw the <select> chevron ourselves — the native one is a different
   shape/weight on every OS and is the one place a browser default control
   was poking through the hand-set type system */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: var(--select-arrow); background-repeat: no-repeat;
  background-position: right 0.85rem center; background-size: 1rem;
  padding-right: 2.5rem; cursor: pointer;
}

.field-error { color: var(--danger); font-size: 0.8rem; }
.field-error[hidden] { display: none; }

.auth-sep { display: flex; align-items: center; gap: 12px; margin: 1.4rem 0 1rem; color: var(--fg-dim); }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: var(--border-fade); }
.guest-note { margin-top: 0.8rem; margin-bottom: 0; text-align: center; }
.guest-note[hidden] { display: none; }

.check-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; margin: 1rem 0; cursor: pointer; }

/* custom checkbox — same reasoning as the <select> chevron above: the OS
   checkbox widget was the other browser-default control breaking the
   hand-set look, so it's redrawn with the same border/radius/accent
   language as everything else (buttons, inputs, the model-picker dots) */
.check-row input[type=checkbox] {
  appearance: none; -webkit-appearance: none; margin: 0; font-size: 1rem;
  width: 1.15em; height: 1.15em; flex-shrink: 0;
  border: 1.5px solid var(--border-strong); border-radius: 5px; background: var(--paper);
  display: grid; place-content: center; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.check-row input[type=checkbox]::after {
  content: ""; width: 0.62em; height: 0.62em; background: #fff; transform: scale(0);
  transition: transform 0.12s cubic-bezier(.22,1,.36,1);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 45% 68%);
}
.check-row input[type=checkbox]:checked { background: var(--accent-strong); border-color: var(--accent-strong); }
.check-row input[type=checkbox]:checked::after { transform: scale(1); }
.check-row input[type=checkbox]:hover { border-color: var(--accent-strong); }
.check-row input[type=checkbox]:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; min-width: 0; }

.key-status { min-height: 1.4em; margin: 1rem 0; }
.key-status.ok { color: var(--voice-a); }
.key-status.err { color: var(--danger); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0.9rem 0 1.4rem; }
.chip { border: 1px solid var(--border-fade); background: var(--surface-alt); border-radius: 999px; padding: 0.4rem 0.85rem; font-size: 0.78rem; cursor: pointer; color: var(--fg-dim); transition: border-color 0.2s ease, color 0.2s ease; }
.chip:hover { border-color: var(--border-strong); color: var(--fg); }

/* ---------- onboarding ---------- */
.onboarding { max-width: 520px; }
.slides { position: relative; min-height: 220px; }
.slide { display: none; text-align: center; animation: slide-in 0.4s cubic-bezier(.22,1,.36,1); }
.slide.active { display: block; }
@keyframes slide-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.slide-glyph { font-size: 2.4rem; margin-bottom: 1.2rem; }
.slide h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.5rem; margin-bottom: 0.8rem; line-height: 1.25; }
.slide p { color: var(--fg-dim); line-height: 1.6; font-size: 0.92rem; }
.onboarding-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 2rem; }
.dots { display: flex; gap: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); transition: background 0.2s ease, transform 0.2s ease; }
.dot.active { background: var(--accent-strong); transform: scale(1.3); }
.onboarding-actions { display: flex; align-items: center; gap: 1rem; }

/* ==========================================================================
   APP SHELL: sidebar + main pane, locked to the viewport height.
   ========================================================================== */

#app-shell { height: 100dvh; display: flex; }
#app-shell[hidden] { display: none; }

.sidebar-backdrop { display: none; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; background: var(--paper);
  border-right: 1px solid var(--border-fade);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 4px; }
.sidebar-logo { letter-spacing: 0.16em; }
.sidebar-close-mobile { display: none; }

.sidebar-new-btn { margin: 14px; width: calc(100% - 28px); justify-content: flex-start; }

.sidebar-section-label { padding: 0 18px; margin-top: 18px; margin-bottom: 8px; color: var(--fg-dim); }

.sidebar-convos { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-convo {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 10px; border: none; background: transparent; color: var(--fg);
  cursor: pointer; font-size: 0.8rem; transition: background 0.15s ease;
}
.sidebar-convo:hover { background: var(--surface-alt); }
.sidebar-convo-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-convo-del { flex-shrink: 0; opacity: 0; background: none; border: none; color: var(--fg-dim); cursor: pointer; font-size: 0.8rem; padding: 2px 4px; }
.sidebar-convo:hover .sidebar-convo-del { opacity: 1; }
.sidebar-convo-del:hover { color: var(--danger); }
.sidebar-convos-empty { padding: 10px 18px; font-size: 0.78rem; color: var(--fg-dim); }

.sidebar-footer { border-top: 1px solid var(--border-fade); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-account {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 10px;
  border: none; background: transparent; cursor: pointer; color: var(--fg); text-align: left;
  transition: background 0.15s ease;
}
.sidebar-account:hover { background: var(--surface-alt); }
.sidebar-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-strong); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; flex-shrink: 0; }
.sidebar-account-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.82rem; }
.sidebar-account-gear { color: var(--fg-dim); }
.sidebar-footer-row { display: flex; gap: 8px; }

.main-pane { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; }

.mobile-topbar { display: none; }

.screen-host { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.screen-host .view { flex: 1; min-height: 0; overflow-y: auto; }
.screen-host .view-stage { overflow: hidden; }

.wrap-models { width: 100%; max-width: 920px; margin: auto; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 1rem 0 0; }
.filter-row .check-row { margin: 0; font-size: 0.8rem; }
.pairings { display: flex; flex-wrap: wrap; gap: 8px; margin: 1rem 0 1.6rem; }
.model-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.voice-head { display: flex; align-items: center; gap: 8px; margin-bottom: 0.7rem; }
.voice-dot { width: 10px; height: 10px; border-radius: 50%; }
.voice-dot.a { background: var(--voice-a); }
.voice-dot.b { background: var(--voice-b); }
.model-search { width: 100%; margin-bottom: 0.7rem; }
.model-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border-fade); border-radius: 14px; background: var(--paper); }
.model-item { padding: 0.7rem 0.9rem; cursor: pointer; border-bottom: 1px solid var(--border-fade); transition: background 0.15s ease; }
.model-item:last-child { border-bottom: none; }
.model-item:hover { background: var(--surface-alt); }
.model-item.selected { background: var(--surface-alt); box-shadow: inset 3px 0 0 var(--accent-strong); }
.model-item-name { font-size: 0.86rem; font-weight: 600; }
.model-item-meta { font-size: 0.72rem; color: var(--fg-dim); margin-top: 0.15rem; font-family: var(--font-mono); }
.model-empty { padding: 1.2rem; text-align: center; color: var(--fg-dim); font-size: 0.85rem; }
.model-chosen { margin-top: 0.7rem; padding: 0.6rem 0.8rem; border-radius: 10px; background: var(--surface-alt); font-size: 0.8rem; }
.model-chosen[hidden] { display: none; }

.advanced { margin-top: 1.8rem; border: 1px solid var(--border-fade); border-radius: 14px; padding: 1rem 1.2rem; }
.advanced summary { cursor: pointer; color: var(--fg-dim); }
.advanced-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
#temperature { width: 100%; accent-color: var(--accent-strong); }

.model-status { min-height: 1.4em; margin: 1.2rem 0; }
.model-status.err { color: var(--danger); }

/* ---------- stage ---------- */
.view-stage { display: flex; flex-direction: column; align-items: stretch; padding: 0; }
.stage-bar { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px clamp(16px, 3vw, 32px); border-bottom: 1px solid var(--border-fade); flex-wrap: wrap; }
.stage-seed { color: var(--fg-dim); max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.stage-bar-right { display: flex; align-items: center; gap: 16px; color: var(--fg-dim); }

.transcript { flex: 1; min-height: 0; overflow-y: auto; padding: 22px clamp(16px, 3vw, 32px) 20px; display: flex; flex-direction: column; gap: 18px; }

.bubble { max-width: 74ch; display: flex; flex-direction: column; gap: 6px; animation: bubble-in 0.35s cubic-bezier(.22,1,.36,1); }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.bubble.voice-a { align-self: flex-start; }
.bubble.voice-b { align-self: flex-end; }
.bubble.human { align-self: center; max-width: 60ch; }

.bubble-meta { display: flex; align-items: baseline; gap: 8px; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.06em; color: var(--fg-dim); }
.bubble.voice-b .bubble-meta { flex-direction: row-reverse; }
.bubble-avatar { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.65rem; flex-shrink: 0; }
.bubble.voice-a .bubble-avatar { background: var(--voice-a-soft); color: var(--voice-a); }
.bubble.voice-b .bubble-avatar { background: var(--voice-b-soft); color: var(--voice-b); }
.bubble.human .bubble-avatar { background: var(--surface-alt); color: var(--neutral-voice); }

.bubble-body { padding: 14px 18px; border-radius: 18px; line-height: 1.62; font-size: 0.94rem; border: 1px solid var(--border-fade); background: var(--paper); }
.bubble.voice-a .bubble-body { border-top-left-radius: 4px; box-shadow: inset 3px 0 0 var(--voice-a); }
.bubble.voice-b .bubble-body { border-top-right-radius: 4px; box-shadow: inset -3px 0 0 var(--voice-b); }
.bubble.human .bubble-body { background: var(--surface-alt); font-style: italic; text-align: center; }
.bubble.pending .bubble-body { color: var(--fg-dim); }
.bubble.error .bubble-body { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }

.bubble-body p { margin: 0 0 0.7em; }
.bubble-body p:last-child { margin-bottom: 0; }
.bubble-body ul { margin: 0 0 0.7em 1.2em; }
.bubble-body code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface-alt); padding: 0.1em 0.35em; border-radius: 4px; }
.bubble-body pre { background: var(--surface-alt); padding: 0.8em 1em; border-radius: 10px; overflow-x: auto; margin: 0.5em 0; }
.bubble-body pre code { background: none; padding: 0; }

.stream-caret { display: inline-block; width: 7px; height: 1em; background: currentColor; vertical-align: text-bottom; margin-left: 1px; animation: caret-blink 0.9s steps(1) infinite; }

.typing-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.4; animation: typing-bounce 1.1s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.retry-btn { margin-top: 0.5rem; font-size: 0.75rem; }

.scroll-pill { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); border-radius: 999px; padding: 8px 16px; font-size: 0.78rem; cursor: pointer; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.scroll-pill[hidden] { display: none; }

.stage-controls { flex-shrink: 0; display: flex; gap: 10px; flex-wrap: wrap; padding: 12px clamp(16px, 3vw, 32px); border-top: 1px solid var(--border-fade); }
.stage-controls .btn { padding: 0.65rem 1.1rem; font-size: 0.8rem; }

.intervene-bar { flex-shrink: 0; display: flex; gap: 8px; padding: 0 clamp(16px, 3vw, 32px) 14px; }
.intervene-bar[hidden] { display: none; }
.intervene-bar input { flex: 1; min-width: 0; }

/* ---------- settings modal ---------- */
.saved-runs, .settings-block .saved-runs { display: flex; flex-direction: column; gap: 8px; }
.saved-run-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0.7rem 0.9rem; border: 1px solid var(--border-fade); border-radius: 10px; font-size: 0.82rem; }
.saved-run-item button { flex-shrink: 0; }
.saved-runs-empty { color: var(--fg-dim); font-size: 0.85rem; }

.settings-block { width: 100%; padding: 1.3rem 0; border-bottom: 1px solid var(--border-fade); }
.settings-block:last-child { border-bottom: none; padding-bottom: 0.2rem; }
.settings-block h3 { margin-bottom: 0.7rem; color: var(--fg-dim); }

.settings-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.settings-modal-head .panel-title { margin-bottom: 0; }
.settings-modal-body { max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.settings-box { max-width: 480px; }

/* ---------- toasts + generic modal ---------- */
/* Top, not bottom: the stage has a control bar and an intervene input
   docked at the bottom, so a bottom-anchored toast would sit on top of
   whatever button the user just clicked. */
#toast-root { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 0.82rem; box-shadow: 0 10px 30px rgba(0,0,0,0.3); animation: toast-in 0.25s cubic-bezier(.22,1,.36,1); }
.toast.err { background: var(--danger); color: var(--danger-fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

#modal-root:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop[hidden] { display: none; }
.modal-box { background: var(--paper); border-radius: 18px; padding: 1.8rem; max-width: 420px; width: 100%; box-shadow: 0 30px 80px rgba(0,0,0,0.4); max-height: 86vh; overflow-y: auto; }
.modal-box h3 { font-family: var(--font-display); font-weight: 400; font-size: 1.3rem; margin-bottom: 0.8rem; }
.modal-box p { color: var(--fg-dim); font-size: 0.88rem; line-height: 1.55; margin-bottom: 1.4rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .mobile-topbar {
    flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid var(--border-fade);
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 250; width: min(var(--sidebar-w), 82vw);
    transform: translateX(-100%); transition: transform 0.25s cubic-bezier(.22,1,.36,1);
    box-shadow: 20px 0 60px rgba(0,0,0,0.25);
  }
  #app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close-mobile { display: inline-flex; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 240;
  }
  #app-shell.sidebar-open .sidebar-backdrop { display: block; }
}

@media (max-width: 720px) {
  .model-cols { grid-template-columns: 1fr; }
  .advanced-grid { grid-template-columns: 1fr; }
  .stage-bar-right { gap: 10px; }
  .stage-seed { max-width: 30ch; }
  .bubble { max-width: 92%; }
  .stage-controls { justify-content: center; }
}
