/* ============================================================
   Simul Interpreter — design system v2
   Translation is the hero. Source is metadata. Stacked default.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  /* Palette — light. 宣纸墨朱, matching addsum.top: paper ground, ink text,
     seal red as the only accent. Every text/background pair below clears
     WCAG AA (4.5:1); re-check before changing any of them. */
  --bg:            #f6f2ea;        /* 宣纸 — same paper as addsum.top */
  --bg-elev:       #fdfbf7;
  --surface:       #fdfbf7;
  --surface-2:     #f9f6ef;
  --surface-sunk:  #efe9dd;        /* paper-deep */
  --border:        #e2dbcc;
  --border-strong: #d0c7b4;
  --hairline:      rgba(29, 27, 22, 0.16);

  --text:          #1d1b16;        /* 墨 — 15.4:1 on paper */
  --text-2:        #5c574c;        /* ink-soft — 6.4:1 */
  --text-3:        #6f6757;        /* ink-faint — 5.0:1 */
  --text-on-accent:#ffffff;

  --accent:        #b13a24;        /* 朱印 — 5.4:1 on paper, 6.0:1 under white */
  --accent-hover:  #93301e;        /* seal-deep */
  --accent-soft:   #f4e6e1;
  --accent-ring:   rgba(177, 58, 36, 0.30);

  --success:       #1f5d3f;
  --success-soft:  #e4efe8;
  --warning:       #7a4f06;
  --warning-soft:  #f7eeda;
  --danger:        #a8211a;
  --danger-soft:   #f7e4e1;

  /* Speaker accent stripes (cycle per detected speaker / lang change).
     Kept inside the ink/mineral-pigment family so a multi-speaker transcript
     still reads as one document rather than a highlighter set. */
  --speaker-1: var(--accent);
  --speaker-2: #2f6152;            /* 石绿 */
  --speaker-3: #6f4a1c;            /* 赭石 */
  --speaker-4: #3f5170;            /* 黛蓝 */

  /* Type — serif for display (Songti, as on addsum.top), sans for UI chrome. */
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 30px;
  /* v2: translation is the hero now; source becomes small metadata. */
  --fs-translation: 24px;
  --fs-source:      14px;

  --lh-tight: 1.25;
  --lh-snug:  1.4;
  --lh-base:  1.55;
  --lh-loose: 1.7;

  /* Radius / shadows / motion.
     Corners are near-square: this design language is cut paper and carved
     seals, not rounded SaaS panels. Genuine pills (language toggle, status
     chips) set border-radius: 999px directly and are unaffected by this scale.
     Shadows are warm-tinted and very shallow — paper resting on paper. */
  --r-xs: 2px;
  --r-sm: 3px;
  --r-md: 4px;
  --r-lg: 6px;
  --r-xl: 10px;

  --shadow-sm: 0 1px 2px rgba(29, 27, 22, 0.05);
  --shadow-md: 0 1px 2px rgba(29, 27, 22, 0.06), 0 8px 24px -14px rgba(29, 27, 22, 0.16);
  --shadow-lg: 0 2px 4px rgba(29, 27, 22, 0.05), 0 20px 40px -18px rgba(29, 27, 22, 0.22);

  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 360ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark = ink ground, paper text. Same seal accent, lightened just enough
       to clear AA on the dark surfaces. */
    --bg:            #14120e;
    --bg-elev:       #1a1712;
    --surface:       #1e1b15;
    --surface-2:     #242019;
    --surface-sunk:  #17140f;
    --border:        #353027;
    --border-strong: #4b4438;
    --hairline:      rgba(246, 242, 234, 0.10);

    --text:          #f2ece0;       /* 14.6:1 on --surface */
    --text-2:        #d3cab5;       /* 10.5:1 on --surface */
    --text-3:        #9c9480;       /* 5.7:1 on --surface, 6.2:1 on --bg */
    --text-on-accent:#ffffff;

    --accent:        #e08a69;       /* seal, lightened — 6.6:1 on --surface */
    --accent-hover:  #eda183;
    --accent-soft:   #33201a;
    --accent-ring:   rgba(224, 138, 105, 0.36);

    --success:       #7fd3a6;
    --success-soft:  #14291f;
    --warning:       #e8bd76;
    --warning-soft:  #2b2313;
    --danger:        #f0908a;
    --danger-soft:   #2c1614;

    --speaker-1: var(--accent);
    --speaker-2: #79c4b0;           /* 石绿 */
    --speaker-3: #d9a878;           /* 赭石 */
    --speaker-4: #9fb4d8;           /* 黛蓝 */

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 1px 2px rgba(0,0,0,0.4), 0 12px 28px -14px rgba(0,0,0,0.6);
    --shadow-lg: 0 2px 4px rgba(0,0,0,0.5), 0 24px 48px -18px rgba(0,0,0,0.7);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); transition: border-color var(--dur) var(--ease); }
a:hover { border-bottom-color: var(--accent); }

button { font-family: inherit; }

/* Focus rings — visible on keyboard nav, suppressed on mouse */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.hidden { display: none !important; }

/* ---------- App shell ---------- */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ============================================================
   SETUP VIEW
   ============================================================ */
.view-setup {
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 5vw, 48px);
  background:
    radial-gradient(1100px 600px at 80% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 60%),
    var(--bg);
}

/* Tone the radial gradients down on small screens — at 360px a 1100px glow
   becomes a muddy wash, not a tasteful accent. */
@media (max-width: 480px) {
  .view-setup {
    background:
      radial-gradient(420px 260px at 90% 0%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 70%),
      var(--bg);
  }
}

.setup-shell {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Top bar above the brand: holds the UI-language toggle. Right-aligned so it
   sits out of the way of the brand mark without competing for visual weight. */
.setup-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: -8px; /* tighten the visual gap to setup-brand below */
}

/* Segmented pill — two buttons sharing a single rounded surface. Active
   segment is filled with the accent; inactive segment is transparent so the
   pill reads as one control rather than two competing chips. */
.ui-lang-toggle {
  display: inline-flex;
  align-items: stretch;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.ui-lang-btn {
  appearance: none;
  background: transparent;
  border: 0;
  margin: 0;
  padding: 5px 14px;
  font: 600 var(--fs-xs) / 1 var(--font-sans);
  letter-spacing: 0.02em;
  color: var(--text-3);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  min-width: 44px;
}
.ui-lang-btn:hover {
  color: var(--text);
}
.ui-lang-btn.is-active {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 1px 3px rgba(20, 18, 10, 0.10);
}
.ui-lang-btn:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

.setup-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
/* v3: the mark is a 朱印 — a flat seal-red square, no gradient, no rounding.
   Matches the 增和 seal on addsum.top. The glyph inside is still the
   translation mark "A → 文", set in the serif so it reads as carved. */
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 2px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: var(--text-on-accent);
}
/* Two characters stacked inside the seal, the way 增和 is set on addsum.top.
   line-height 1 and the tight font-size keep both glyphs inside the 40px
   square — a larger size clips the lower character. */
.brand-glyph {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.02;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; gap: 2px; }
.brand-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: var(--fs-lg);
  letter-spacing: 0.01em;
}
/* Letterspaced subtitle under the name, as on the addsum.top wordmark. Kept
   sentence case: the English string is long enough that uppercase plus wide
   tracking would outrun the header on narrow screens. */
.brand-tag {
  font-size: var(--fs-xs);
  color: var(--text-3);
  letter-spacing: 0.1em;
}

/* Paper card: hairline rule and a nearly square corner, not a rounded SaaS
   panel. The shadow stays very shallow so the card reads as a sheet lying on
   the paper ground rather than a floating element. */
.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: clamp(20px, 4vw, 36px);
  box-shadow: var(--shadow-sm);
}

.setup-title {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: var(--fs-3xl);
  font-weight: 600;
  letter-spacing: 0;
  line-height: var(--lh-tight);
}
.setup-sub {
  margin: 0 0 24px;
  font-size: var(--fs-sm);
  color: var(--text-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Optional glossary / context disclosure on the setup card. */
.context-field { margin-bottom: 16px; }
.context-field summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--accent);
  padding: 4px 0;
  user-select: none;
  list-style-position: inside;
}
.context-field summary:hover { color: var(--accent-hover); }
.context-field textarea {
  width: 100%;
  margin-top: 8px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: var(--fs-md);
  line-height: 1.45;
  resize: vertical;
  min-height: 56px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.context-field textarea:hover { border-color: var(--border-strong); }
.context-field textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
  outline: none;
}
.context-field textarea::placeholder { color: var(--text-3); }
.field-hint { margin: 6px 0 0; font-size: var(--fs-xs); color: var(--text-3); line-height: 1.45; }

.lang-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.lang-row .field { margin-bottom: 0; }
.lang-arrow {
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--text-3);
  padding-bottom: 2px;
}
@media (max-width: 460px) {
  .lang-row { grid-template-columns: 1fr; gap: 12px; }
  .lang-arrow { display: none; }
}

/* Select control */
.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -6px;
  border-right: 1.5px solid var(--text-3);
  border-bottom: 1.5px solid var(--text-3);
  transform: rotate(45deg);
  pointer-events: none;
}
select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 36px 10px 12px;
  font-size: var(--fs-md);
  line-height: 1.4;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
select:hover { border-color: var(--border-strong); }
select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
  outline: none;
}
select option:disabled { color: var(--text-3); }

.link-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--fs-sm);
  padding: 4px 0;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease);
}
.link-btn:hover { border-bottom-color: var(--accent); }
.link-btn-center {
  align-self: center;
  margin-top: 8px;
}

/* Buttons */
.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(0.5px); }

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
  font-weight: 600;
  padding: 12px 16px;
  font-size: var(--fs-md);
  /* v2: dropped the skeuomorphic inset highlight; flat aesthetic now consistent. */
  box-shadow: var(--shadow-sm);
}
.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:not(:disabled):hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.btn-danger:not(:disabled):hover {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
}

.hint {
  margin: 10px 0 0;
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.error {
  margin: 10px 0 0;
  font-size: var(--fs-sm);
  color: var(--danger);
}

.privacy-note {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: var(--lh-snug);
}
.privacy-lead { color: var(--text-2); font-weight: 600; display: block; margin-bottom: 2px; }

.setup-foot {
  display: flex;
  justify-content: center;
  font-size: var(--fs-xs);
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* ============================================================
   TRANSLATE VIEW
   ============================================================ */
.view-translate {
  background: var(--bg);
}

.session-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(16px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--hairline);
}
.session-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.session-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Status pill */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.status-listening { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, var(--border)); }
.status-listening .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent);
  animation: pulse 1.8s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  70%  { box-shadow: 0 0 0 8px color-mix(in srgb, var(--success) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 0%, transparent); }
}

.status-paused      { background: var(--warning-soft) !important; color: var(--warning) !important; border-color: color-mix(in srgb, var(--warning) 30%, var(--border)) !important; }
.status-paused .status-dot { background: var(--warning); animation: none; }
.status-reconnecting{ background: var(--danger-soft) !important; color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 30%, var(--border)) !important; }
.status-reconnecting .status-dot { background: var(--danger); animation: pulse 1.2s var(--ease) infinite; }
/* v3: Connecting — shown while the WS+OpenAI handshake completes and the
   AudioWorklet finishes compiling. Avoids users speaking too early into a
   not-yet-ready pipeline (the "first utterance felt slow" complaint). */
.status-connecting  { background: var(--accent-soft) !important; color: var(--accent) !important; border-color: color-mix(in srgb, var(--accent) 30%, var(--border)) !important; }
.status-connecting .status-dot { background: var(--accent); animation: pulse 1.2s var(--ease) infinite; }
/* Terminal state after auto-reconnect gives up: muted, no pulse. */
.status-disconnected { background: var(--danger-soft) !important; color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 30%, var(--border)) !important; }
.status-disconnected .status-dot { background: var(--danger); }

/* v2: lang-pair is now a readable tag, not a 11px-mono whisper.
   In v3 it doubles as the trigger for the mid-session language switcher. */
.lang-pair {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  letter-spacing: 0.04em;
  color: var(--text-2);
  padding: 5px 10px;
  border-radius: var(--r-xs);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
}
.lang-pair-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.lang-pair-btn:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}
.lang-pair-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.lang-switch-wrap { position: relative; }

.popover {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 14px;
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.popover-title {
  margin: 0 0 10px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}
.popover .field { margin-bottom: 10px; }
.popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* v2: Display toggle group (translation-only + stacked/side-by-side). */
.view-toggles {
  display: inline-flex;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
  white-space: nowrap;
}
.toggle-btn:hover { color: var(--text); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.toggle-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

/* Export menu */
.export-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.menu button:hover { background: var(--surface-sunk); }
.menu-sep { height: 1px; background: var(--hairline); margin: 4px 2px; }
.menu-danger { color: var(--danger) !important; }
.menu-danger:hover { background: var(--danger-soft) !important; }

.chev { transition: transform var(--dur) var(--ease); }
#export-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

/* Warning banner */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px clamp(16px, 3vw, 28px);
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 25%, var(--border));
  font-size: var(--fs-sm);
}
.banner svg { flex-shrink: 0; }
.banner-text { flex: 1; }
.banner-dismiss {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
  color: var(--warning);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.banner-dismiss:hover { background: color-mix(in srgb, var(--warning) 12%, transparent); }
/* Primary call-to-action inside the banner (e.g. "Add your key" when a free
   session ends) — filled so it reads as the main next step. */
.banner-action {
  background: var(--warning);
  color: var(--text-on-accent);
  border: 1px solid var(--warning);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--r-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: filter var(--dur) var(--ease);
}
.banner-action:hover { filter: brightness(1.08); }

/* Stage / transcript */
.stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Live caption: a transient, dimmed preview of the current speech (opt-in),
   below the committed rows. Visually secondary so it never reads as the record. */
.live-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed color-mix(in srgb, var(--accent) 30%, var(--border));
  color: var(--text-2);
  font-style: italic;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.live-caption.hidden { display: none; }
.live-caption .live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s var(--ease) infinite;
  flex-shrink: 0;
}
.live-caption-text { min-width: 0; }

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 32px) 120px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}

.transcript::-webkit-scrollbar { width: 10px; }
.transcript::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-3) 30%, transparent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.transcript::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-3) 50%, transparent);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(40px, 10vh, 100px) 20px;
  color: var(--text-3);
  gap: 12px;
}
.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.empty-title { margin: 0; font-size: var(--fs-lg); font-weight: 500; color: var(--text-2); }
.empty-sub { margin: 0; font-size: var(--fs-sm); color: var(--text-3); max-width: 320px; }
.transcript:has(.utt-block) .empty-state { display: none; }

/* ============================================================
   v2 Utterance block — translation is the hero
   Markup (app.js): translation on top, source reference below.
     <div class="utt-block" data-speaker="N">
       <div class="utt-meta">
         <span class="utt-speaker">Speaker 1</span>
         <span class="utt-lang">EN</span>
         <span class="utt-time">10:42:13</span>
       </div>
       <div class="utt-tgt">translated text…</div>
       <div class="utt-src">original transcribed text…</div>
     </div>
   ============================================================ */
.utt-block {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  animation: utt-in 120ms var(--ease) both;
  /* Accent stripe on the left edge, color cycles per speaker — gives the eye
     an instant "same speaker / new speaker" cue down a column of blocks. */
  border-left: 3px solid var(--accent);
}
.utt-block[data-speaker="1"] { border-left-color: var(--speaker-1); }
.utt-block[data-speaker="2"] { border-left-color: var(--speaker-2); }
.utt-block[data-speaker="3"] { border-left-color: var(--speaker-3); }
.utt-block[data-speaker="4"] { border-left-color: var(--speaker-4); }
.utt-block[data-speaker="5"] { border-left-color: var(--speaker-1); }
.utt-block[data-speaker="6"] { border-left-color: var(--speaker-2); }

@keyframes utt-in {
  /* Start at 0.4 (not 0) so a freshly-painted translation is legible on the
     first frame instead of invisible until the fade completes — the fade is a
     subtle settle, not a reveal that gates readability. */
  from { opacity: 0.4; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Per-utterance attribution row */
.utt-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.utt-speaker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.utt-speaker::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.utt-block[data-speaker="1"] .utt-speaker::before { background: var(--speaker-1); }
.utt-block[data-speaker="2"] .utt-speaker::before { background: var(--speaker-2); }
.utt-block[data-speaker="3"] .utt-speaker::before { background: var(--speaker-3); }
.utt-block[data-speaker="4"] .utt-speaker::before { background: var(--speaker-4); }
.utt-block[data-speaker="5"] .utt-speaker::before { background: var(--speaker-1); }
.utt-block[data-speaker="6"] .utt-speaker::before { background: var(--speaker-2); }

.utt-lang {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 1px 6px;
}
.utt-time {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-3);
  letter-spacing: 0.02em;
  margin-left: auto;
}
/* "Refined" marker — the parallel verify pass corrected this row's translation. */
.utt-refined {
  font-size: 11px;
  line-height: 1;
  color: var(--accent);
  cursor: default;
  user-select: none;
}

/* One-shot highlight when a correction lands, so the swap is noticeable but not
   disruptive. Applied to the block in JS, then left in place (harmless). */
.utt-block.just-refined {
  animation: refine-flash 1.4s var(--ease);
}
@keyframes refine-flash {
  0%   { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
  100% { background: var(--surface);     border-color: var(--border); }
}

/* Source: small reference line below the translation */
.utt-src {
  font-size: var(--fs-source);
  line-height: var(--lh-snug);
  color: var(--text-3);
  font-style: normal;
  word-break: break-word;
  padding-top: 8px;
  border-top: 1px dashed var(--hairline);
}

/* Translation: the hero */
.utt-tgt {
  font-family: var(--font-serif);
  font-size: var(--fs-translation);
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
  letter-spacing: -0.005em;
  word-break: break-word;
}

/* Sub-turn clause DRAFT: an early mid-speech translation that the committed-audio
   authority will replace. Visibly provisional — muted + italic — so settled-looking
   prose never silently rewrites itself. */
.utt-tgt.draft {
  opacity: 0.66;
  font-style: italic;
}

/* Side-by-side layout (opt-in). Source and translation share a row but the
   translation still gets the serif/large treatment, source stays small. */
.transcript.layout-sbs .utt-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  grid-template-areas:
    "meta meta"
    "src  tgt";
  column-gap: 22px;
  row-gap: 8px;
  padding: 14px 22px 18px;
}
.transcript.layout-sbs .utt-meta { grid-area: meta; }
.transcript.layout-sbs .utt-src {
  grid-area: src;
  border-bottom: none;
  padding-bottom: 0;
  padding-right: 16px;
  border-right: 1px solid var(--hairline);
  align-self: center;
}
.transcript.layout-sbs .utt-tgt {
  grid-area: tgt;
  align-self: center;
}
/* On narrow widths SBS reverts to stacked regardless of toggle — the
   side-by-side reading is unusable below ~720px. */
@media (max-width: 720px) {
  .transcript.layout-sbs .utt-block {
    display: flex;
    flex-direction: column;
  }
  .transcript.layout-sbs .utt-src {
    padding-right: 0;
    border-right: none;
    padding-top: 8px;
    border-top: 1px dashed var(--hairline);
  }
}

/* Translation-only: collapse the source row entirely. */
.transcript.hide-source .utt-src { display: none; }
.transcript.hide-source .utt-block { padding-bottom: 16px; }

/* Partial / placeholder / error states */
.utt-src.partial { color: var(--text-2); }
.utt-src.partial::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 1em;
  margin-left: 3px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 1px;
  /* v2: smooth opacity fade instead of stepped blink — feels modern, not 90s terminal. */
  animation: caret 1.1s ease-in-out infinite;
}
@keyframes caret {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 0.1; }
}

/* "Translating…" with subtle 3-dot animation while we wait. */
.utt-tgt.empty {
  font-family: var(--font-sans);
  font-style: italic;
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-3);
}
.utt-tgt.empty::before {
  content: attr(data-translating);
}
.utt-tgt.empty::after {
  content: "";
  display: inline-block;
  width: 1.5em;
  text-align: left;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}
.utt-tgt.no-translation {
  font-family: var(--font-sans);
  color: var(--text-3);
  font-style: italic;
  font-size: var(--fs-sm);
  font-weight: 400;
}
.utt-tgt.error {
  font-family: var(--font-sans);
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 500;
}

/* Mobile: translation slightly smaller but still the largest thing on screen. */
@media (max-width: 720px) {
  .utt-block { padding: 12px 16px 16px; }
  .utt-tgt { font-size: var(--fs-xl); }
}
@media (max-width: 380px) {
  .utt-tgt { font-size: 19px; }
  .utt-time { display: none; }   /* timestamp is noise at 360px */
}

/* Scroll-to-bottom pill */
.scroll-pill {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-on-accent);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
  animation: pill-in 240ms var(--ease) both;
}
.scroll-pill:hover {
  background: var(--accent-hover);
  transform: translateX(-50%) translateY(-1px);
}
@keyframes pill-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Compact session bar on narrow screens ---------- */
@media (max-width: 720px) {
  .session-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .session-bar-right { width: 100%; justify-content: flex-end; }
  .btn { padding: 7px 12px; font-size: var(--fs-xs); }
  /* On small screens, hide the toggle text labels — icons only — to keep the
     bar from wrapping into multiple rows that eat the transcript. */
  .toggle-btn .toggle-label { display: none; }
  .toggle-btn { padding: 5px 8px; }
}

/* ============================================================
   History drawer
   ============================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 10, 0.32);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 40;
  animation: overlay-in var(--dur) var(--ease) both;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  animation: drawer-in 280ms var(--ease) both;
}
@keyframes drawer-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
}
.drawer-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  padding: 6px;
  border-radius: var(--r-xs);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-sunk); color: var(--text); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-foot {
  display: flex;
  justify-content: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--hairline);
}

.history-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-3);
}
.history-empty .empty-title { margin: 0 0 6px; font-size: var(--fs-md); color: var(--text-2); }
.history-empty .empty-sub { margin: 0; font-size: var(--fs-sm); color: var(--text-3); }

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.history-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.history-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-item-langs {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  color: var(--text-2);
  padding: 2px 8px;
  border-radius: var(--r-xs);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
}
.history-item-time {
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.history-item-preview {
  font-size: var(--fs-sm);
  color: var(--text-2);
  line-height: var(--lh-snug);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.history-item-meta {
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.history-item-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.history-item-actions .btn { padding: 6px 10px; font-size: var(--fs-xs); }

/* ---------- Settings top-bar layout + modal ---------- */
.setup-topbar { justify-content: space-between; align-items: center; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  animation: drawer-in 240ms var(--ease) both;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hairline);
}
.modal-body { padding: 16px 18px; }
.modal-lead {
  margin: 0 0 18px;
  font-size: var(--fs-sm);
  line-height: 1.55;
  color: var(--text-2);
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--hairline);
}
.modal-foot-right { display: inline-flex; gap: 8px; }
.modal-foot-stack { flex-direction: column; align-items: stretch; gap: 8px; }

.free-status {
  margin: 0 0 10px;
  font-size: var(--fs-sm);
  color: var(--text-2);
  text-align: center;
}
.free-status.none { color: var(--danger); }

/* ---------- Billing: buy panel packs + top-bar balance pill ---------- */
/* Balance pill sits beside #status-pill in the session bar — same pill chrome
   (the base .status rule) so the two read as a matched pair. */
#balance-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
}
/* The buy panel uses a plain content card (no modal-head/-body/-foot split,
   unlike settings/session-end) — give it its own padding + heading style. */
.modal-card { padding: 18px; }
.modal-card h2 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.buy-packs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0;
}
.buy-pack-btn { width: 100%; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Auth gate + profile chip ---------- */
.auth-card { text-align: center; }
.auth-card .setup-sub { margin-bottom: 20px; }
.auth-privacy {
  margin: 14px 0 0;
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: var(--lh-snug);
}
#signin-google { gap: 8px; }

.setup-topbar { gap: 10px; }
.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-2);
}
.profile-email { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip .link-btn { padding: 0; font-size: var(--fs-xs); }
