:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1b1f1d;
  --muted: #5d6762;
  --line: #e2ded4;
  --brand: #0f6b4f;
  --brand-ink: #ffffff;
  --sun: #f2b705;
  --agent: #ffffff;
  --user: #dcefe6;
  --coach: #fff4d6;
  --fix: #fdeceb;
  --fix-ink: #9b2c22;
  --said: #9aa39e;
  --hl: #0f6b4f;
  --rec: #d93a2b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101412; --surface: #181d1b; --ink: #edf1ee; --muted: #a0aaa5; --line: #2a312e;
    --brand: #2fa77c; --brand-ink: #06140e; --agent: #1b211f; --user: #173a2d; --coach: #3a3218;
    --fix: #3b1d1a; --fix-ink: #ffb4aa; --said: #6d7772; --hl: #5fd3a6; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101412; --surface: #181d1b; --ink: #edf1ee; --muted: #a0aaa5; --line: #2a312e;
  --brand: #2fa77c; --brand-ink: #06140e; --agent: #1b211f; --user: #173a2d; --coach: #3a3218;
  --fix: #3b1d1a; --fix-ink: #ffb4aa; --said: #6d7772; --hl: #5fd3a6; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { margin: 0 0 .25rem; font-size: 1.8rem; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.error { color: var(--fix-ink); }
.flag { font-size: .75rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; background: var(--sun); color: #2b2100; vertical-align: middle; }

.screen { min-height: 100%; }
#gate, #setup { display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px 20px; width: 100%; }
.narrow { max-width: 420px; }
label { display: block; margin: 16px 0 0; font-weight: 600; font-size: .9rem; }
select, input {
  display: block; width: 100%; margin-top: 6px; padding: 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
button { font: inherit; cursor: pointer; border: 0; color: inherit; background: none; }
.primary { background: var(--brand); color: var(--brand-ink); padding: 12px 18px; border-radius: 12px; font-weight: 600; }
.primary.big { width: 100%; margin-top: 24px; padding: 16px; font-size: 1.1rem; }
#gate-form { display: grid; gap: 12px; margin-top: 12px; }
.ghost { padding: 8px 12px; border-radius: 10px; color: var(--muted); }
.toggle[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* Call layout: header, scrolling log, fixed controls */
#call { display: flex; flex-direction: column; height: 100dvh; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.bar-title { font-weight: 600; font-size: .95rem; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.bubble { max-width: 92%; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--line); }
.bubble.agent { background: var(--agent); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.agent.coach { background: var(--coach); }
.bubble.user { background: var(--user); align-self: flex-end; border-bottom-right-radius: 6px; border-color: transparent; }
.bubble .tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.say { font-size: 1.25rem; line-height: 1.5; }
.say .w { transition: color .12s; }
.say.playing .w { color: var(--said); }
.say.playing .w.done { color: var(--ink); }
.say.playing .w.now { color: var(--hl); text-decoration: underline; text-underline-offset: 4px; }
.bubble .actions { display: flex; gap: 6px; margin-top: 8px; }
.chip { font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--surface); }
.translation { margin-top: 6px; color: var(--muted); font-size: .95rem; font-style: italic; }

.suggestions { display: grid; gap: 8px; margin-top: 10px; }
.sugg { text-align: left; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.sugg .pt { font-weight: 600; font-size: 1.1rem; display: block; }
.sugg .en { color: var(--muted); font-size: .88rem; }
.sugg::after { content: "▶ tap to hear"; display: block; font-size: .72rem; color: var(--brand); margin-top: 2px; }

.fix { align-self: flex-end; max-width: 92%; background: var(--fix); color: var(--fix-ink); border-radius: 12px; padding: 8px 12px; font-size: .92rem; }
.fix s { opacity: .75; }
.fix b { display: block; font-size: 1.05rem; }

.controls { border-top: 1px solid var(--line); background: var(--surface); padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px); }
.status { text-align: center; margin: 0 0 8px; color: var(--muted); font-size: .9rem; min-height: 1.3em; }
.row { display: flex; align-items: center; justify-content: center; gap: 28px; }
.round { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; }
.round svg { width: 26px; height: 26px; fill: currentColor; }
.round.small { border: 1px solid var(--line); font-weight: 700; }
.mic { width: 84px; height: 84px; background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.mic svg { width: 38px; height: 38px; }
.mic:disabled { opacity: .45; }
.mic.rec { background: var(--rec); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,58,43,.45); } 50% { box-shadow: 0 0 0 14px rgba(217,58,43,0); } }
#text-form { display: flex; gap: 8px; margin-top: 10px; }
#text-form input { margin: 0; }
