/* Table Read styles.
   Tokens first, components after. Every color comes from a token so the light
   and dark themes each resolve as a set. The script itself is set in Courier
   Prime because screenplays are set in Courier; the chrome is IBM Plex Sans.
   The current line gets a highlighter-yellow wash, the way actors mark their
   own lines. */

:root {
  color-scheme: light;
  --paper: #FAF9F6;
  --surface: #FFFFFF;
  --surface-2: #F1EFE9;
  --ink: #1E1C19;
  --muted: #6E6A62;
  --rule: #E4E0D7;
  --rule-strong: #CBC6BB;
  --accent: #2B5C8A;
  --accent-ink: #FFFFFF;
  --accent-press: #1F4568;
  --accent-soft: #E4EDF6;
  --hl: #FFF3A3;
  --hl-edge: #E8C300;
  --hl-word: #FFD93B;
  --bad-soft: #F8E6E2;
  --shadow: 0 1px 2px rgba(30, 28, 25, .06), 0 10px 30px rgba(30, 28, 25, .08);
  --shadow-sm: 0 1px 2px rgba(30, 28, 25, .10);
  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-script: "Courier Prime", "Courier New", Courier, monospace;
  --transport-h: 136px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #1B1A17;
    --surface: #252420;
    --surface-2: #2E2D28;
    --ink: #ECE9E2;
    --muted: #A8A399;
    --rule: #383630;
    --rule-strong: #4C4A43;
    --accent: #8DB8E6;
    --accent-ink: #0F1A26;
    --accent-press: #A9CBEF;
    --accent-soft: #24313E;
    --hl: #3F3910;
    --hl-edge: #E8C300;
    --hl-word: #7A6A0E;
    --bad-soft: #3B2421;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1B1A17;
  --surface: #252420;
  --surface-2: #2E2D28;
  --ink: #ECE9E2;
  --muted: #A8A399;
  --rule: #383630;
  --rule-strong: #4C4A43;
  --accent: #8DB8E6;
  --accent-ink: #0F1A26;
  --accent-press: #A9CBEF;
  --accent-soft: #24313E;
  --hl: #3F3910;
  --hl-edge: #E8C300;
  --hl-word: #7A6A0E;
  --bad-soft: #3B2421;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--transport-h) + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top);
}
.brand { padding: 14px 0 10px; }
h1 { margin: 0; font: 600 21px/1.2 var(--font-ui); letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px;
  padding: 3px; margin: 0 0 10px;
  background: var(--surface-2); border-radius: 11px;
}
.tabs [role="tab"] {
  border: 0; background: transparent; color: var(--muted);
  font-weight: 500; font-size: 14px; padding: 9px 0; border-radius: 9px;
}
.tabs [aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- panels ---------- */
main { padding-top: 16px; }
[role="tabpanel"] { display: grid; gap: 14px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; margin-bottom: 14px; }
.notice.bad { background: var(--bad-soft); }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; margin: 0; }

.field-label, .field > span {
  display: flex; justify-content: space-between; align-items: baseline;
  font: 600 12px/1.2 var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.field { display: grid; gap: 6px; }
.field output { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; color: var(--ink); font-weight: 500; }

textarea {
  width: 100%; min-height: 42vh; resize: vertical;
  padding: 14px; border: 1px solid var(--rule-strong); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font: 400 16px/1.55 var(--font-script);
}
textarea::placeholder { color: var(--muted); opacity: .9; }
@media (min-width: 720px) { textarea { min-height: 52vh; } }

.script-tools { display: flex; gap: 8px; }
.ghost {
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 10px;
  padding: 9px 14px; font-size: 14px; font-weight: 500;
}
.ghost:active { background: var(--surface-2); }
.filepick { cursor: pointer; display: inline-flex; align-items: center; }
.filepick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--font-script); }
body.dragging::after {
  content: "Drop the file to load it";
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--ink); font-weight: 600;
  border: 3px dashed var(--accent); pointer-events: none;
}

.summary-line { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--rule); font-size: 13px; font-weight: 500;
}
.chip em { font-style: normal; color: var(--muted); font-weight: 400; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; background: var(--muted); }
/* one colour per character, in order of first appearance; wraps after twelve */
.dot.cn { background: var(--muted); }
.dot.c0 { background: #2F6DB5; }
.dot.c1 { background: #C2452D; }
.dot.c2 { background: #2E8B57; }
.dot.c3 { background: #8E44AD; }
.dot.c4 { background: #D68910; }
.dot.c5 { background: #16A085; }
.dot.c6 { background: #C0397B; }
.dot.c7 { background: #5D6D7E; }
.dot.c8 { background: #7D6608; }
.dot.c9 { background: #E74C3C; }
.dot.c10 { background: #1ABC9C; }
.dot.c11 { background: #34495E; }

.help { border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); padding: 0 14px; }
.help summary { padding: 12px 0; font-weight: 500; cursor: pointer; }
.help pre {
  margin: 0 0 12px; white-space: pre-wrap; overflow-x: auto;
  font: 400 14px/1.5 var(--font-script);
  background: var(--surface-2); padding: 12px; border-radius: 8px;
}
.help p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

/* ---------- inbox ---------- */
.inbox { display: grid; gap: 10px; }
.inbox-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inbox-head h2 { margin: 0; font: 600 15px/1.2 var(--font-ui); letter-spacing: .02em; }
.inbox-tools { display: flex; gap: 8px; align-items: center; }
.ghost.small { padding: 6px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 6px 4px; }
#inbox-key p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--rule-strong); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 400 16px/1.3 var(--font-ui);
}
#inbox-list { display: grid; gap: 6px; }
.inbox-row { display: flex; align-items: stretch; gap: 6px; }
.inbox-open {
  flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left;
  padding: 9px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface-2);
}
.inbox-open:active { background: var(--rule); }
.inbox-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.inbox-del { width: 40px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); color: var(--muted); font-size: 18px; }
.inbox-del:active { background: var(--surface-2); }
.empty.small { padding: 8px; font-size: 14px; text-align: left; }

/* ---------- voices ---------- */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 14px; }
.settings { display: grid; gap: 12px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; flex: none; }
select {
  width: 100%; appearance: none; -webkit-appearance: none;
  padding: 11px 38px 11px 12px;
  border: 1px solid var(--rule-strong); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'><path d='M4 6l4 4 4-4' fill='none' stroke='%236E6A62' stroke-width='1.8' stroke-linecap='round'/></svg>") no-repeat right 12px center;
  color: var(--ink); font: 400 16px/1.3 var(--font-ui);
}
select:disabled { opacity: .6; }
input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); height: 28px; }
#cast { display: grid; gap: 12px; }
.cast-card { display: grid; gap: 12px; }
.cast-head { display: flex; align-items: center; gap: 10px; }
.cast-name {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 8px 10px; margin: -8px 0 -8px -10px; border: 0; background: transparent; border-radius: 10px;
}
.cast-name:active { background: var(--surface-2); }
.cast-name:disabled { opacity: .6; cursor: default; }
.cast-text { display: grid; gap: 1px; min-width: 0; }
.cast-title { font: 600 16px/1.2 var(--font-ui); letter-spacing: .02em; overflow-wrap: anywhere; }
.cast-voice { color: var(--accent); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 24px; line-height: 1; margin-left: auto; padding-left: 6px; }

/* ---------- voice picker sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .42); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 680px; margin: 0 auto;
  max-height: 85vh; max-height: 85dvh; display: flex; flex-direction: column;
  background: var(--paper); border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-titles { min-width: 0; }
.sheet-head h2 { margin: 0; font: 600 17px/1.2 var(--font-ui); }
.sheet-head .hint { margin: 2px 0 0; }
.sheet-tools { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.sheet-tools input[type="search"] {
  flex: 1; min-width: 0; padding: 9px 12px; -webkit-appearance: none; appearance: none;
  border: 1px solid var(--rule-strong); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 400 16px/1.3 var(--font-ui);
}
.switch.small { font-size: 13px; white-space: nowrap; gap: 6px; }
.switch.small input { width: 18px; height: 18px; }
.voice-list { overflow-y: auto; display: grid; gap: 4px; padding-bottom: 4px; align-content: start; }
.vgroup { margin: 8px 0 2px; font: 600 11px/1.2 var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.vrow { display: flex; gap: 6px; }
.vpick {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); font-size: 15px;
}
.vpick:active { background: var(--surface-2); }
.vrow.selected .vpick { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.vname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtag { color: var(--muted); font-size: 12px; font-weight: 400; border: 1px solid var(--rule-strong); border-radius: 999px; padding: 1px 7px; flex: none; }
.vplay {
  width: 44px; flex: none; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--accent); display: inline-flex; align-items: center; justify-content: center;
}
.vplay svg { width: 20px; height: 20px; fill: currentColor; }
.vplay:active { background: var(--surface-2); }
body.sheet-open { overflow: hidden; }
.hear {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 999px;
  padding: 7px 12px 7px 9px; font-size: 13px; font-weight: 500;
}
.hear svg { width: 18px; height: 18px; fill: currentColor; }
.hear:active { background: var(--surface-2); }
.hint { margin: -4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- reader ---------- */
.page { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 12px 14px; }
.cue {
  padding: 10px 12px 10px 14px; margin: 0 -4px; border-radius: 8px;
  box-shadow: inset 4px 0 0 transparent; cursor: pointer;
  transition: background .2s, box-shadow .2s;
}
.cue + .cue { margin-top: 2px; }
.cue:active { background: var(--surface-2); }
.cue.current { background: var(--hl); box-shadow: inset 4px 0 0 var(--hl-edge); }
.cue-speaker {
  display: flex; align-items: center; gap: 7px; margin-bottom: 2px;
  font: 700 13px/1.3 var(--font-script); letter-spacing: .06em; text-transform: uppercase;
}
.cue-text { font: 400 16px/1.55 var(--font-script); overflow-wrap: anywhere; }
.cue.narration .cue-text { font-style: italic; color: var(--muted); }
.cue.direction .cue-text { font-style: italic; color: var(--muted); font-size: 15px; }
.cue.current .cue-text, .cue.current .cue-speaker { color: var(--ink); }
.cue.skipped { opacity: .45; }
.ch.speaking { text-decoration: underline; text-decoration-color: var(--hl-edge); text-underline-offset: 3px; }
mark { background: var(--hl-word); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- transport ---------- */
.transport {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--rule);
  padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .06);
}
.now {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-bottom: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums;
}
#who { color: var(--ink); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controls { display: flex; justify-content: center; align-items: center; gap: 14px; }
.tbtn {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--rule-strong); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
}
.tbtn svg { width: 24px; height: 24px; fill: currentColor; }
.tbtn:active { background: var(--surface-2); }
.tbtn:disabled { opacity: .4; cursor: default; }
.tbtn.small { width: 44px; height: 44px; }
.tbtn.small svg { width: 20px; height: 20px; }
.tbtn.primary { width: 68px; height: 68px; background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: var(--shadow); }
.tbtn.primary svg { width: 30px; height: 30px; }
.tbtn.primary:active { background: var(--accent-press); }
.tbtn.primary:disabled { box-shadow: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--transport-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 999px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
