:root {
  --bg: #0e1013;
  --panel: #161a1f;
  --panel-2: #1d2228;
  --line: #2a3038;
  --text: #e8eaed;
  --muted: #8b939e;
  --accent: #f5c84c;      /* tally-light amber */
  --accent-ink: #1a1400;
  --rec: #ff4d4f;
  --emph: #ffd76a;
  --cue: #6fb3ff;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 13px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #3b434e; background: #232931; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 3px 8px; font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { width: 11px; height: 11px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 0 3px rgba(255,77,79,.18); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 10px; }
.login-card .brand { font-size: 20px; }
.login-card p { margin: 0 0 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.err { color: var(--rec); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- Editor ---------- */
.editor-view { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.stats { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); font-weight: 600; }
.stats .over { color: var(--rec); }
.stats .ok { color: #7bd88f; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.save-state { font-size: 12px; color: var(--muted); min-width: 60px; text-align: right; }
.select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; max-width: 190px; }

.workspace { flex: 1; display: flex; min-height: 0; }
.edit-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hint { display: flex; gap: 18px; flex-wrap: wrap; padding: 8px 20px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); align-items: center; }
.hint code { font-family: var(--mono); color: var(--accent); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.wpm { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.wpm input { width: 58px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
#script {
  flex: 1; resize: none; border: 0; outline: none; background: var(--bg);
  padding: 28px max(20px, calc((100% - 760px) / 2)); font-size: 18px; line-height: 1.75;
  font-family: var(--font);
}

/* ---------- AI pane ---------- */
.ai-pane { width: min(440px, 42vw); border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.ai-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.ai-head .btn { margin-left: auto; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.quick button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; }
.quick button:hover { border-color: var(--accent); color: var(--accent); }
.ai-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.ai-empty { font-size: 13px; }
.msg { padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.55; }
.msg.user { background: #2a2414; border: 1px solid #4a3d16; align-self: flex-end; max-width: 92%; }
.msg.assistant { background: var(--panel-2); border: 1px solid var(--line); }
.msg.error { border-color: var(--rec); color: #ffb3b3; }
.msg.pending { color: var(--muted); font-style: italic; }
.proposal { margin-top: 8px; border: 1px solid #4a3d16; border-radius: 8px; overflow: hidden; }
.proposal pre { margin: 0; padding: 10px; max-height: 240px; overflow: auto; white-space: pre-wrap; font: 13px/1.5 var(--font); background: var(--bg); }
.proposal .bar { display: flex; gap: 8px; align-items: center; padding: 6px 8px; background: #221d10; font-size: 12px; }
.proposal .bar .btn { padding: 3px 10px; font-size: 12px; }
.proposal .bar span { margin-right: auto; color: var(--muted); }
.ai-form { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.ai-form textarea { flex: 1; resize: none; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-height: 160px; }

@media (max-width: 820px) {
  .workspace { flex-direction: column; }
  .ai-pane { width: 100%; border-left: 0; border-top: 1px solid var(--line); height: 55%; }
  #script { font-size: 16px; padding: 18px 16px; }
  .wpm { margin-left: 0; }
}

/* ---------- Prompter ---------- */
.prompter-view { position: fixed; inset: 0; background: #000; color: #fff; overflow: hidden; user-select: none; }
.stage { position: absolute; inset: 0; }
.scroller { position: absolute; inset: 0; overflow: hidden; }
.prompt-text {
  --size: 64px; --width: 80%;
  width: var(--width); margin: 0 auto; font-size: var(--size); line-height: 1.38;
  font-weight: 600; letter-spacing: .005em; will-change: transform;
  padding: 45vh 0 100vh;
}
.prompt-text.mirror { transform-origin: center; }
.prompt-text p { margin: 0 0 .7em; }
.prompt-text em { font-style: normal; color: var(--emph); }
.prompt-text .pause { display: inline-block; color: var(--rec); font-size: .55em; vertical-align: middle; letter-spacing: .1em; margin: 0 .25em; opacity: .9; }
.prompt-text .cue { font-size: max(16px, .32em); color: var(--cue); text-transform: uppercase; letter-spacing: .18em; font-weight: 700; margin: 1.2em 0 .5em; opacity: .85; }
.prompt-text.no-cues .cue { display: none; }
.prompt-text .end { text-align: center; color: #555; font-size: .4em; letter-spacing: .3em; margin-top: 2em; }

.guide { position: absolute; left: 0; right: 0; top: 38%; height: 0; pointer-events: none; border-top: 2px solid rgba(245,200,76,.25); }
.guide-arrow { position: absolute; left: 1.2vw; top: -0.62em; color: var(--accent); font-size: 28px; }
.fade { position: absolute; left: 0; right: 0; pointer-events: none; }
.fade.top { top: 0; height: 22%; background: linear-gradient(#000, rgba(0,0,0,0)); }
.fade.bottom { bottom: 0; height: 25%; background: linear-gradient(rgba(0,0,0,0), #000); }

.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28vh; font-weight: 800; color: var(--accent); background: rgba(0,0,0,.55); }

.hud {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 16px 12px;
  background: rgba(14,16,19,.92); border-top: 1px solid var(--line); transition: opacity .3s, transform .3s;
}
.prompter-view.playing.idle .hud { opacity: 0; transform: translateY(100%); }
.prompter-view.playing.idle { cursor: none; }
.hud-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.hbtn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 6px 11px; cursor: pointer; min-width: 38px; }
.hbtn:hover { border-color: #3b434e; }
.hbtn.sm { padding: 4px 8px; min-width: 32px; font-size: 13px; }
.hbtn.play { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; min-width: 52px; }
.hbtn.tog[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ctl output { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
.fit { width: 54px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; text-align: center; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; }
.timer small { font-size: 12px; font-weight: 500; color: var(--muted); }
.timer.over span { color: var(--rec); }
.progress { height: 3px; background: var(--line); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); }
.keys { font-size: 11px; margin-top: 6px; }
@media (max-width: 820px) { .keys { display: none; } .prompt-text { --width: 92%; } }

/* Selection mode */
.sel-chip { margin: 10px 14px 0; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 8px; background: #221d10; font-size: 13px; }
.sel-top { display: flex; align-items: center; gap: 8px; }
.sel-top strong { color: var(--accent); font-weight: 600; }
.sel-top .btn:first-of-type { margin-left: auto; }
.sel-text { margin-top: 4px; color: var(--text); opacity: .85; font-style: italic; overflow-wrap: anywhere; }
.ai-pane.sel-mode .quick button { border-color: #4a3d16; }
.msg .quote { font-size: 12.5px; color: var(--muted); border-left: 2px solid var(--accent); padding-left: 8px; margin-bottom: 6px; font-style: italic; }
