/* Live Translator - phone-first. Tokens on :root, dark redefinitions below. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #16191d;
  --muted: #5d6670;
  --line: #e2ded6;
  --a: #2f6fd6;          /* turns spoken by me (A) */
  --a-soft: #e6eefb;
  --b: #c46a12;          /* turns spoken by them (B) */
  --b-soft: #fbefe2;
  --live: #d33a3a;
  --warn: #b7791f;
  --ok: #2f8f5b;
  /* TEXT colours for the three signals: --live/--warn as text measured 4.31:1 and 2.62:1 on --bg
     (audit 2026-10-05); these reach 4.5:1 on --bg, --surface and the amber banner, in both themes. */
  --live-ink: #b42323;
  --warn-ink: #8a5a12;
  --chip: #ece8e0;
  --chrome: #ffffff;      /* header + controls: raised above the conversation */
  --divider: #cfc8bb;     /* face to face: the line between the two halves */
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  --radius: 14px;
  --tr-size: clamp(1.7rem, 6.5vw, 2.4rem);
  --hero-size: clamp(1.9rem, 7.5vw, 2.6rem); /* the newest turn - read at arm's length */
  --card-line: transparent;
  --src-size: clamp(.92rem, 3.6vw, 1.05rem);
  color-scheme: light dark;
  accent-color: var(--a);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418; --surface: #181d23; --ink: #eef1f4; --muted: #96a0ab; --line: #262d35;
    --a: #7aa7ff; --a-soft: #1b2738; --b: #f0a35e; --b-soft: #2f2318; --chip: #2b333d; --chrome: #1d232a; --divider: #3d4652;
    --live-ink: #ff7b7b; --warn-ink: #f0b45e; --muted: #a3adb8; --card-line: #262d35;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #101418; --surface: #181d23; --ink: #eef1f4; --muted: #96a0ab; --line: #262d35;
  --a: #7aa7ff; --a-soft: #1b2738; --b: #f0a35e; --b-soft: #2f2318; --chip: #2b333d; --chrome: #1d232a; --divider: #3d4652;
  --live-ink: #ff7b7b; --warn-ink: #f0b45e; --muted: #a3adb8; --card-line: #262d35;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Thai", "Noto Sans SC", "Noto Sans TC", sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------------------------------------------------------------- top bar */
/* Header and controls sit on a raised surface so they read as chrome, not as conversation
   (2026-10-05: the header had no differentiation from the translated area). */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px 16px;
  min-width: 0;
  background: var(--chrome); box-shadow: 0 1px 0 var(--line), 0 2px 8px rgb(0 0 0 / .06);
  z-index: 2;
}
.chip {
  border: 0; border-radius: 999px; background: var(--chip);
  padding: 6px 12px; font-size: .95rem; white-space: nowrap;
}
.chip.engine { font-size: .8rem; color: var(--muted); padding: 5px 10px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chip.pair, .badge.hybrid { flex-shrink: 0; }
/* Under 375 px the flags alone name the pair: "EN" / "TH" would push the gear off the screen. */
/* Header: pair + HYBRID + four icons (relationship, help, layout, settings). Icons are 38 px wide
   (44 tall); with HYBRID showing, the pair's letter codes give way to the flags below 430 px;
   below 360 px the help icon leaves the bar - it is still at the top of Settings. */
/* Header icons: one family of drawn icons on tonal rounded squares (the text glyphs ? ⇅ ⚙ rendered
   differently per phone, and ⇅ read like a language swap). Layout is a toggle: filled = face to face. */
.bar .icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--chip); color: var(--ink); }
.bar .icon-btn svg { width: 22px; height: 22px; }
.bar .icon-btn[aria-pressed="true"] { background: var(--ink); color: var(--chrome); }
.bar .rel-btn.unset { color: var(--muted); }
@media (max-width: 429px) { .bar:has(#hybridBadge:not([hidden])) .pair-code { display: none; } }
@media (max-width: 374px) {
  .chip.pair .pair-code { display: none; }
  .bar { gap: 4px; }
}
@media (max-width: 359px) { .bar #helpBtn { display: none; } .controls .lock { flex-wrap: nowrap; gap: 3px; } .controls .lock button { padding: 4px 6px; } }
/* HYBRID: the 'realtime' mode kept an undocumented (beta) direction on engine A. Tap = settings. */
.badge.hybrid {
  border: 1px solid var(--warn-ink); border-radius: 6px; background: transparent; color: var(--warn-ink);
  font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 6px; margin-left: -4px; cursor: pointer;
}
.badge.hybrid[hidden] { display: none; }
.conn { flex: 1; min-width: 0; font-size: .8rem; color: var(--warn-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: transparent;
}
body[data-listening="true"] .bar::after, body[data-listening="true"] .controls::before { background: var(--live); animation: pulse 1.4s ease-in-out infinite; }
body[data-listening="paused"] .bar::after, body[data-listening="paused"] .controls::before,
body[data-conn="reconnecting"] .bar::after, body[data-conn="reconnecting"] .controls::before { background: var(--warn); animation: none; }
body[data-conn="failed"] .bar::after, body[data-conn="failed"] .controls::before { background: var(--live-ink); animation: none; }
@keyframes pulse { 50% { opacity: .35; } }
/* Reconnecting / failed / errors: an amber banner hanging under the header (the header itself
   has no room for it at phone width - measured: it truncated to "Re"). */
.bar { position: relative; }
.conn:not(:empty) {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5;
  max-width: calc(100% - 32px); padding: .3rem .8rem; border-radius: 999px; font-weight: 600;
  background: color-mix(in srgb, var(--warn) 22%, var(--bg)); border: 1px solid color-mix(in srgb, var(--warn) 60%, transparent);
}
/* Face to face: the banner hangs over the far half, upside down for its reader and in English;
   it is for the owner, so it sits just above the controls instead. */
body[data-layout="face"] .conn:not(:empty) { position: fixed; top: auto; bottom: calc(80px + env(safe-area-inset-bottom)); }
.conn.live:not(:empty) { color: #fff; background: var(--live-ink); border-color: var(--live-ink); }
.row.presets { grid-template-columns: 1fr auto; align-items: end; }
.presets button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 14px; }
.presets button:disabled { opacity: .45; cursor: default; }
.icon-btn {
  flex-shrink: 0; border: 0; background: transparent; width: 44px; height: 44px; border-radius: 50%;
  font-size: 1.25rem; display: grid; place-items: center; color: var(--muted);
}
.icon-btn:active { background: var(--chip); }

/* ---------------------------------------------------------------- stage */
#stage { min-height: 0; display: grid; grid-template-rows: 1fr; }
.pane { min-height: 0; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.pane.far { display: none; }
body[data-layout="face"] #stage { grid-template-rows: 1fr 1fr; }
/* The far half is rotated, so its border-TOP is the one drawn in the middle of the screen (a
   border-bottom landed under the header - the stray dashed line, 2026-10-05). */
body[data-layout="face"] .pane.far { display: flex; transform: rotate(180deg); border-top: 1px solid var(--divider); }

.empty { margin: auto 0; text-align: center; color: var(--muted); padding: 24px 8px; }
.brand { margin: 0 0 14px; font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.empty-title { font-size: 1.3rem; color: var(--ink); margin: 0 0 6px; }
.empty-sub { margin: 0; max-width: 32ch; margin-inline: auto; }
.empty-pair { margin: 0 0 14px; color: var(--ink); font-size: .95rem; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.empty-pair .flag { width: 22px; height: 16px; }
.pane.far .empty-title { font-size: 1.4rem; line-height: 1.5; max-width: 22ch; margin-inline: auto; }

/* ---------------------------------------------------------------- turns */
.turn {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px 12px; border: 1px solid var(--card-line); border-left: 5px solid var(--a);
  animation: rise .18s ease-out; transition: border-color .25s, opacity .25s;
}
/* Newest turn = the hero; earlier turns compact to their translation (tap one to see it all). */
.pane .turn:last-of-type .tr { font-size: var(--hero-size); }
.pane .turn:not(:last-of-type):not(.expanded):not(.error) { padding-block: 8px; }
.pane .turn:not(:last-of-type):not(.expanded):not(.error) .tr { font-size: 1.05rem; font-weight: 500; }
.pane .turn:not(:last-of-type):not(.expanded):not(.error) .src,
.pane .turn:not(:last-of-type):not(.expanded):not(.error) .meta:not(:has(.unsure)) { display: none; }
.pane .turn:not(:last-of-type) { cursor: pointer; }
/* Face-to-face: a turn the READER spoke features their own words, never its translation. */
.pane .turn.own:last-of-type .tr { font-size: 1rem; }
.pane .turn.own:last-of-type .src { font-size: 1.15rem; color: var(--ink); }
.pane .turn.own:not(:last-of-type):not(.expanded):not(.error) .src { display: block; color: var(--ink); }
.pane .turn.own:not(:last-of-type):not(.expanded):not(.error) .tr { display: none; }
/* Live / translating / final: one signal each. */
.turn.status-live { border-left-color: var(--live); animation: rise .18s ease-out, pulse-border 1.2s ease-in-out infinite; }
@keyframes pulse-border { 50% { border-left-color: transparent; } }
.turn.status-committed.empty-tr .tr {
  display: block; min-height: 1.2em; width: 70%; border-radius: 6px;
  background: linear-gradient(90deg, var(--chip) 25%, var(--line) 50%, var(--chip) 75%); background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.turn.by-b { border-left-color: var(--b); }
.turn .meta { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: .75rem; color: var(--muted); }
.turn .dir {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 10px; font-size: .8rem; color: var(--muted); min-height: 30px;
}
.turn .dir .flag { width: 18px; height: 13px; }
.turn .dir .flip { opacity: .7; }
.turn .edit { margin-left: auto; }
.turn .edit + .dismiss { margin-left: 8px; } /* 14 px apart: the 7 px hit areas meet, never overlap */
.turn .edit, .turn .dismiss {
  margin-left: auto; position: relative; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: .9rem; line-height: 1; display: grid; place-items: center;
}
.turn .edit::after, .turn .dismiss::after { content: ""; position: absolute; inset: -7px; }
.turn .edit:active, .turn .dismiss:active { background: var(--chip); }
#typeText {
  width: 100%; box-sizing: border-box; margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; resize: vertical;
}
.type-lang { display: flex; gap: 6px; margin-top: 8px; }
.type-lang button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px;
  font-size: .85rem; color: var(--muted); min-height: 36px;
}
.type-lang button[aria-checked="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.type-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.type-send {
  min-height: 44px; padding: 0 20px; border-radius: 12px; border: 0; background: var(--ink); color: var(--bg);
  font-weight: 700; font-size: 1rem;
}
.turn .dir:active { background: var(--chip); }
.turn .badge { border-radius: 999px; padding: 1px 7px; background: var(--chip); }
/* Fixed fills, same in both themes: white on them is 5.9:1 and 5.7:1 (--warn/--ok gave 3.6/4.0). */
.turn .badge.unsure { background: #8a5a12; color: #fff; font-weight: 700; }
.turn .badge.fixed { background: #24744a; color: #fff; }
.turn .badge:not(.unsure):not(.fixed) { display: none; } /* engine badges (B, A↺): the exported log keeps them */
.turn .src { margin: 0; font-size: var(--src-size); color: var(--muted); overflow-wrap: anywhere; }
.turn .tr { margin: 2px 0 0; font-size: var(--tr-size); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
/* Tentative: muted + dotted underline - synthetic italic is ugly on Thai/CJK (no real italic there). */
.turn.tentative .tr { color: var(--muted); text-decoration: underline dotted; text-underline-offset: .2em; text-decoration-thickness: 1px; }
/* D2: script-aware metrics. Stacked Thai tone marks and Vietnamese double diacritics clip at 1.3. */
.turn .tr, .turn .src { font-synthesis: none; }
/* Settings -> Text size: scales the conversation only, never the UI (2026-10-05). zoom keeps
   every turn rule (hero, compact, Thai, own) in proportion without touching each one. */
#stage .turn { zoom: var(--text-scale, 1); }
.text-size-row { display: grid; grid-template-columns: auto 1fr auto 3.2em; align-items: center; gap: 10px; margin-top: 6px; }
.text-size-row .big-a { font-size: 1.4rem; }
.text-size-row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.turn :lang(th) { font-size: 1.12em; line-height: 1.6; }
.turn .tr:lang(th) { font-size: calc(var(--tr-size) * 1.12); }
.pane .turn:last-of-type .tr:lang(th) { font-size: calc(var(--hero-size) * 1.12); }
.turn :lang(vi) { line-height: 1.5; }
.turn :is(:lang(zh), :lang(ja), :lang(ko)) { line-height: 1.5; letter-spacing: .01em; line-break: strict; }
.turn.live .src::after { content: " ▍"; color: var(--live); animation: blink 1s steps(2) infinite; }
.turn.error .tr { color: var(--live-ink); font-size: 1rem; font-weight: 400; }
.turn .retry { border: 0; background: var(--chip); border-radius: 8px; padding: 4px 10px; margin-top: 6px; min-height: 44px; min-width: 64px; }
/* Small controls keep their look but get a 44 px tall hit area (audit 2026-10-05: 21-30 px). */
.turn .dir, .lock button, .badge.hybrid { position: relative; }
.turn .dir::after, .lock button::after, .badge.hybrid::after { content: ""; position: absolute; inset: -10px -2px; }
.turn.empty-tr .tr { display: none; }

/* Face-to-face: each pane emphasises what ITS reader needs. */
.turn.own .tr { font-size: 1rem; opacity: .7; font-weight: 400; }
.turn.own .src { font-size: 1rem; }
.pane.far .turn .dir { pointer-events: none; }
.pane.far .turn:not(.own) .src { display: none; } /* they said it in English: only the translation helps them */
/* D14: face-to-face - the owner's newest turn sits at the centre line too, facing theirs. */
body[data-layout="face"] .pane.near { flex-direction: column-reverse; justify-content: flex-end; }

@keyframes rise { from { transform: translateY(6px); opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- controls */
.controls {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; /* the flat mic centres in what the sides leave */
  padding: 8px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--chrome); position: relative;
}
.controls::before { content: ""; position: absolute; left: 0; right: 0; top: -2px; height: 3px; background: transparent; }
.lock { display: flex; gap: 4px; flex-wrap: wrap; justify-self: start; }
.lock button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 9px; font-size: .78rem; color: var(--muted);
}
.lock button[aria-checked="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.mic-wrap { display: flex; align-items: center; gap: 8px; justify-self: center; }
.type-btn {
  width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); display: grid; place-items: center; flex-shrink: 0;
}
.type-btn svg { width: 26px; height: 26px; }
.type-btn:active { background: var(--chip); }
/* Idle mic = the glyph alone (the words "Tap to talk" were not needed); listening adds "Stop". */

.mic {
  position: relative; min-width: 88px; height: 48px; border-radius: 14px; border: 0; padding: 0 18px;
  background: var(--ink); color: var(--bg); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: border-radius .18s, background-color .18s;
}
.mic .glyph { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.mic .stop-glyph { display: none; }
.mic[aria-pressed="true"] { background: var(--live); color: #fff; }
.mic[aria-pressed="true"] .mic-glyph { display: none; }
.mic[aria-pressed="true"] .stop-glyph { display: block; }

@media (max-width: 359px) { .mic { min-width: 0; padding: 0 12px; gap: 6px; } }

.mic .ring {
  position: absolute; inset: -6px; border-radius: inherit; border: 3px solid var(--live); will-change: transform;
  opacity: 0; transform: scale(1); transition: transform 80ms linear, opacity .2s;
}
.mic[aria-pressed="true"] .ring { opacity: .9; }
/* Status = an icon both people can read (2026-10-05): words only for warnings meant for the speaker.
   ready/stopped: nothing. connecting/stopping: a spinning ring. listening: moving bars (amber while
   reconnecting). warn/error: a ⚠ and the text. The label stays for screen readers (sr-only). */
.state { margin: 0; justify-self: end; display: flex; align-items: center; gap: 6px; min-height: 24px; font-size: .82rem; color: var(--muted); max-width: 16ch; text-align: right; }
.state-icon { display: none; width: 22px; height: 18px; flex-shrink: 0; align-items: flex-end; justify-content: center; gap: 3px; }
.state-icon i { display: none; width: 4px; height: 17px; border-radius: 2px; background: var(--live); transform-origin: bottom; animation: bars 1s ease-in-out infinite; }
.state-icon i:nth-child(2) { animation-delay: -.33s; } .state-icon i:nth-child(3) { animation-delay: -.66s; }
@keyframes bars { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } } /* transform: no layout per frame */
.state-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.state[data-kind="listening"] .state-icon { display: flex; }
.state[data-kind="listening"] .state-icon i { display: block; }
body[data-conn="reconnecting"] .state[data-kind="listening"] .state-icon i { background: var(--warn); animation-duration: 2s; }
.state[data-kind="connecting"] .state-icon, .state[data-kind="stopping"] .state-icon {
  display: block; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* A warning for the speaker sits in a full-width strip just above the controls (positioned against
   .controls): in the status slot it ran off a 320 px screen. */
.state[data-kind="warn"] .state-label, .state[data-kind="error"] .state-label {
  position: absolute; left: 16px; right: 16px; bottom: calc(100% + 6px); width: auto; height: auto; overflow: visible; clip: auto;
  white-space: normal; text-align: center; padding: 6px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
}
.state[data-kind="warn"]::before, .state[data-kind="error"]::before { content: "⚠"; font-size: 1rem; }
.state[data-kind="error"] { color: var(--live-ink); font-weight: 600; }
/* Who-is-talking chips: flags, "both flags" = Auto */
.lock button, .type-lang button { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; }
.lock button .flag, .type-lang button .flag { width: 20px; height: 15px; }
.both-flags { display: inline-flex; }
.both-flags .flag + .flag { margin-left: -7px; margin-top: 6px; }
.help-flags { display: inline-flex; gap: 4px; padding: 2px 6px; }
.type-title svg { width: 26px; height: 26px; display: block; }
.type-send { display: grid; place-items: center; width: 56px; padding: 0; }
.type-send svg { width: 24px; height: 24px; }
.other-hint { margin-top: 18px; }
body[data-layout="face"] .other-hint { display: none; } /* face to face: their half greets them */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- settings sheet */
dialog#settings, dialog#personSheet {
  width: min(560px, 100vw); max-width: 100vw; max-height: 92dvh; margin: auto auto 0;
  border: 0; border-radius: 18px 18px 0 0; padding: 0; background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }

/* Flags are images (flags/*.svg, flag-icons, MIT): Windows renders flag emoji as letters. */
.flag { display: inline-block; vertical-align: -2px; border-radius: 2px; box-shadow: 0 0 0 1px rgb(0 0 0 / .25); object-fit: cover; }
.chip.pair { display: inline-flex; align-items: center; gap: 5px; }
.chip.pair .flag { width: 20px; height: 15px; }
.pair-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.pair-row .flag { width: 24px; height: 18px; }

/* Language picker - opened from the header pill */
dialog#pairPicker, dialog#relSheet, dialog#helpSheet, dialog#typeSheet {
  width: min(420px, 100vw); max-width: 100vw; max-height: 92dvh; margin: auto auto 0;
  border: 0; border-radius: 18px 18px 0 0; padding: 0 16px max(20px, env(safe-area-inset-bottom)); background: var(--surface); color: var(--ink);
}
.pair-list { display: grid; gap: 8px; margin-top: 8px; }
.pair-opt {
  display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.pair-opt .flag { width: 32px; height: 24px; }
.pair-opt[aria-current="true"] { border-color: var(--a); box-shadow: inset 0 0 0 1px var(--a); }
.pair-opt:disabled { opacity: .5; cursor: not-allowed; }
.pair-name { font-weight: 600; }
.pair-native { color: var(--muted); font-size: .9rem; }
.link-btn { margin-top: 12px; border: 0; background: none; color: var(--muted); text-decoration: underline; font: inherit; font-size: .9rem; padding: 8px 0; cursor: pointer; }
#settingsForm, #personForm { padding: 0 16px max(24px, env(safe-area-inset-bottom)); scroll-padding-top: 56px; }
.row-link {
  display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 48px;
  border: 0; border-top: 1px solid var(--line); background: none; padding: 12px 0; text-align: left; font-weight: 600;
}
.picker-engine { margin: 12px 0 0; }
.rel-btn { font-size: 1.25rem; }
.rel-btn.unset { opacity: .8; }
.rel-list { display: grid; gap: 6px; margin-top: 8px; }
.rel-opt {
  display: grid; grid-template-columns: 2rem 1fr; column-gap: 10px; align-items: center; text-align: left;
  min-height: 52px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1rem;
}
.rel-opt .e { font-size: 1.5rem; grid-row: span 2; text-align: center; }
.rel-opt .d { color: var(--muted); font-size: .85rem; line-height: 1.3; }
.rel-opt[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.help-key svg { width: 18px; height: 18px; display: block; }
dl.help { margin: 8px 0 0; }
dl.help dt { font-weight: 700; margin-top: 14px; display: flex; align-items: center; gap: 6px; }
dl.help dd { margin: 4px 0 0; color: var(--muted); line-height: 1.45; }
.help-key {
  display: inline-block; min-width: 1.6em; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line);
  font-size: .8rem; text-align: center; color: var(--ink);
}
.mic-key { width: 18px; height: 18px; min-width: 0; padding: 0; border-radius: 50%; background: var(--ink); }
details.saved-people { border-top: 1px solid var(--line); padding-top: 8px; }
.picker-engine .chip.engine { display: inline-block; white-space: normal; text-align: left; }
.picker-links { display: flex; justify-content: space-between; gap: 12px; }
.sheet-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; justify-content: space-between; padding: 12px 0 6px; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0; display: grid; gap: 10px; min-width: 0; }
legend { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0; }
label { display: grid; gap: 4px; font-size: .9rem; min-width: 0; }
label.check { display: flex; align-items: center; gap: 8px; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; min-width: 0; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: max(16px, 1rem); /* under 16 px iOS Safari zooms the page on focus and stays zoomed */
}
input[type="file"] { padding: 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.buttons { grid-template-columns: repeat(3, 1fr); }
.row.buttons button, .dirs select { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 6px; }
.person { display: grid; gap: 8px; padding: 10px; border-radius: 12px; background: var(--bg); }
.person h3 { margin: 0; font-size: .95rem; }
.person small { color: var(--muted); font-weight: 400; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: .85rem; min-height: 44px; }
.dirs { display: grid; gap: 8px; }
.dirs label { grid-template-columns: 1fr 1fr; align-items: center; }
.hint { margin: 0; font-size: .8rem; color: var(--muted); }
.hint.bad { color: var(--live-ink); }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; padding: 4px 0; }
details[open] { display: grid; gap: 10px; }

@media (min-width: 720px) {
  dialog#settings, dialog#pairPicker, dialog#personSheet, dialog#relSheet, dialog#helpSheet, dialog#typeSheet { margin: auto; border-radius: 18px; }
  .pane { padding-inline: max(16px, calc(50vw - 380px)); }
}

/* D11: motion that respects the reader. Smooth scrolling while a turn is still streaming stutters
   on older iPhones (each new card both rises and scrolls). */
.pane:has(.status-live) { scroll-behavior: auto; }
@media (prefers-reduced-motion: reduce) {
  .turn, .turn.status-live, .turn.status-committed.empty-tr .tr { animation: none; }
  .pane { scroll-behavior: auto; }
  .ring, .mic, .bar::after, .controls::before { animation: none !important; transition: none; }
  /* Still tell the states apart: three still bars of different heights, a still partial ring. */
  .state-icon, .state-icon i, .turn.live .src::after { animation: none !important; }
  .state-icon i:nth-child(1) { transform: scaleY(.45); } .state-icon i:nth-child(2) { transform: scaleY(1); } .state-icon i:nth-child(3) { transform: scaleY(.7); }
}
