:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e4e1db;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #7a4b00;
  --warn-line: #f0c454;
  --danger: #b42318;
  --aside: #8a857c;
  --outside: 0.4;
  --radius: 10px;
  color-scheme: light;
}

/* Dark colors: used when the device is in dark mode (unless Light is picked
   in the app), or whenever Dark is picked. The two blocks must match. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #211f1d;
    --text: #ecebe8;
    --muted: #a19d96;
    --line: #36332f;
    --accent: #5b8def;
    --accent-text: #0b1220;
    --warn-bg: #3a2e12;
    --warn-text: #f5d58a;
    --warn-line: #8a6a1c;
    --danger: #f97066;
    --aside: #8f8a82;
    --outside: 0.35;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161514;
  --surface: #211f1d;
  --text: #ecebe8;
  --muted: #a19d96;
  --line: #36332f;
  --accent: #5b8def;
  --accent-text: #0b1220;
  --warn-bg: #3a2e12;
  --warn-text: #f5d58a;
  --warn-line: #8a6a1c;
  --danger: #f97066;
  --aside: #8f8a82;
  --outside: 0.35;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { line-height: 1.2; margin: 0 0 0.4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 0.6em; }

button, select, input, textarea { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.45em 0.9em;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.quiet { background: transparent; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }

select, input[type="text"], textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4em 0.6em;
  max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.brand { font-weight: 700; letter-spacing: 0.01em; color: inherit; text-decoration: none; }
.brand:hover { color: var(--accent); }
.theme-pick { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.theme-pick select { font-size: 0.85rem; padding: 0.25em 0.4em; color: var(--text); }

main { padding: 1.25rem 1rem 4rem; max-width: 1200px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.small { font-size: 0.85rem; color: var(--muted); }
.big { display: block; font-size: 1.15rem; font-weight: 600; margin-bottom: 0.4rem; }
.lead { color: var(--muted); max-width: 40rem; }
.buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---------------------------------------------------------------- load */

#load-screen { max-width: 760px; margin: 0 auto; }
.load-options { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.load-options .card { margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.drop-zone {
  align-items: center;
  justify-content: center;
  text-align: center;
  border-style: dashed;
  border-width: 2px;
  min-height: 12rem;
  cursor: pointer;
}
.drop-zone.dragging { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.library { margin-bottom: 2rem; }
.script-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.script-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; margin-bottom: 0.6rem; }
.script-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 16rem; }
.script-info strong { word-break: break-word; }
.library:not([hidden]) ~ #load-heading { font-size: 1.25rem; }
.status { margin-top: 1rem; font-weight: 600; }
.status.error { color: var(--danger); }
#load-anyway { margin-top: 0.25rem; }
.privacy { margin-top: 1.5rem; }

/* ---------------------------------------------------------------- check */

/* The top of the Script overview and the setup screen: the title on the
   left, All scripts on the right, in the same place on both. */
.screen-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 0.5rem; }
.screen-head h1 { word-break: break-word; }
.eyebrow { margin: 0 0 0.2rem; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.summary { color: var(--muted); }
.unsure { color: var(--warn-text); background: var(--warn-bg); padding: 0 0.4em; border-radius: 4px; font-weight: 600; }
.all-clear { color: var(--muted); }
.warning { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-line); border-radius: 8px; padding: 0.6rem 0.8rem; }

.check-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; align-items: start; }
.side { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.side label { display: block; margin-bottom: 0.6rem; }
.side label[hidden] { display: none; }
.side select { display: block; width: 100%; margin-top: 0.25rem; }
.range-info p { margin: 0 0 0.3em; font-size: 0.9rem; }
.quote { color: var(--muted); font-style: italic; }
.checkbox { display: flex !important; gap: 0.5rem; align-items: center; }

.characters summary { cursor: pointer; list-style: none; }
.characters summary::-webkit-details-marker { display: none; }
.characters summary h2 { display: inline; }
.characters summary::after { content: " ▾"; color: var(--muted); }
.characters:not([open]) summary::after { content: " ▸"; }
#character-list { list-style: none; padding: 0; margin: 0; }
.char { padding: 0.55rem 0; border-top: 1px solid var(--line); }
.char.no-lines { opacity: 0.7; }
.char-head { display: flex; align-items: center; gap: 0.5rem; }
.dot { width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--who); flex: none; }
.char-name { font-weight: 600; flex: 1; word-break: break-word; }
.count { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.char .small { margin: 0.25rem 0 0 1.3rem; }
.suggest { margin: 0.4rem 0 0 1.3rem; padding: 0.5rem 0.6rem; background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; font-size: 0.9rem; }
.suggest p { margin: 0 0 0.4rem; }
.suggest button, .suggest select { font-size: 0.85rem; margin: 0 0.3rem 0.3rem 0; }
.merged { margin: 0.3rem 0 0 1.3rem; }
.merged .small { margin: 0 0 0.2rem; }
.merged ul { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; }
.merged li { display: flex; gap: 0.5rem; align-items: baseline; color: var(--muted); }
.merged button.link { font-size: 0.85rem; margin-left: auto; }

.lines-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.4rem; }
.lines-toolbar label { flex: 1; min-width: 12rem; }
.lines-toolbar select { max-width: 100%; }
.tip { margin-bottom: 0.8rem; }

#lines { display: flex; flex-direction: column; gap: 2px; }
.line {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  border-left: 4px solid var(--who);
  border-radius: 6px;
  cursor: pointer;
}
.line:hover { box-shadow: 0 0 0 1px var(--line); }
.line.open { box-shadow: 0 0 0 2px var(--accent); }
.line.outside { opacity: var(--outside); }
.line.flagged { background: color-mix(in srgb, var(--warn-bg) 55%, var(--surface)); }
.num { color: var(--muted); font-size: 0.8rem; text-align: right; font-variant-numeric: tabular-nums; }
.num .page { display: block; font-size: 0.7rem; }
.who { font-weight: 700; color: color-mix(in srgb, var(--who) 80%, var(--text)); font-size: 0.9rem; letter-spacing: 0.02em; }
.ext { font-weight: 400; color: var(--muted); }
.kind-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.text { word-break: break-word; }
.aside { color: var(--aside); font-style: italic; }
.kind-direction .text, .kind-note .text { color: var(--muted); font-style: italic; }
.kind-note { background: transparent; border: 1px dashed var(--line); border-left: 4px solid var(--line); }
.kind-heading .text { font-weight: 700; text-transform: none; letter-spacing: 0.02em; }
.kind-direction, .kind-heading { border-left-color: var(--line); }
.flag { margin: 0.35rem 0 0; font-size: 0.85rem; color: var(--warn-text); }
.flag .quick, .info .quick { font-size: 0.85rem; padding: 0.15em 0.6em; margin-left: 0.3rem; }
mark.check { background: none; color: inherit; text-decoration: underline wavy var(--warn-line); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.scan-warning { margin: 1em 0; }
.scan-warning p { margin: 0 0 0.5rem; }
.scan-warning button { font-size: 0.9rem; }
.info { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--muted); }
.range-mark { font-size: 0.8rem; font-weight: 700; color: var(--accent); padding: 0.5rem 0.2rem; }
.pick-scene { display: block; margin: 0.6rem 0; }
.pick-banner {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 8px;
  font-weight: 600;
}
.pick-banner[hidden] { display: none; }
.pick-banner p { margin: 0; }
.pick-banner button { color: var(--accent-text); border-color: currentColor; font-weight: 400; }
.lines-panel.picking .line:hover, .lines-panel.picking .line:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.line.picked { box-shadow: 0 0 0 2px var(--accent); }
.empty-list { color: var(--muted); padding: 1rem; }

.editor {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 0.9rem;
  margin: 0.2rem 0 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.editor label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; font-size: 0.9rem; }
.editor label[hidden] { display: none; }
.editor select { align-self: flex-start; }
.editor .small { margin: 0; }
.editor .spoken span { color: var(--text); }
.editor .hint { color: var(--warn-text); }
.editor .secondary button { font-size: 0.85rem; }

.rehearse-go { display: block; width: 100%; margin-top: 0.9rem; padding: 0.65em 0.9em; }

/* ---------------------------------------------------------------- setup */

.setup-body { max-width: 640px; }
.role-list { list-style: none; padding: 0; margin: 0 0 0.4rem; }
.role { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.2rem; border-top: 1px solid var(--line); cursor: pointer; }
.role input, .radio input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); flex: none; }
.radio { display: flex; gap: 0.6rem; align-items: center; padding: 0.35rem 0; cursor: pointer; }
.voice-list { list-style: none; padding: 0; margin: 0 0 0.4rem; }
.voice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.6rem; padding: 0.55rem 0.2rem; border-top: 1px solid var(--line); }
.voice-row .char-name { flex: 1 1 8rem; }
.voice-row .count { font-weight: 400; margin-left: 0.3rem; }
.voice-row select { flex: 0 1 13rem; min-width: 0; }
.voice-row .hear { flex: none; min-width: 5.8rem; }
.voice-row .hear.playing { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.voice-row.narrator .dot { background: var(--aside); }
.setup-summary { font-weight: 600; }
#setup-voice:empty { display: none; }
.natural { border-top: 1px solid var(--line); padding-top: 0.6rem; margin-bottom: 0.4rem; }
.natural p { margin: 0 0 0.5rem; }
.natural progress { display: block; width: 100%; height: 0.6rem; margin: 0 0 0.6rem; accent-color: var(--accent); }
button.start { font-size: 1.1rem; padding: 0.7em 1.4em; }

/* ---------------------------------------------------------------- rehearse */

#rehearse-screen { max-width: 760px; margin: 0 auto; padding-bottom: 8rem; touch-action: manipulation; }
#rehearse-screen h1 { word-break: break-word; }
.rehearse-lines { display: flex; flex-direction: column; gap: 2px; }
.rehearse-lines .line { cursor: default; grid-template-columns: 2.4rem 1fr; transition: opacity 0.2s, background-color 0.2s; }
.rehearse-lines .line:hover { box-shadow: none; }
.rehearse-lines .kind-speech .text { font-size: 1.1rem; }
.rehearse-lines .line.past { opacity: 0.55; }
.rehearse-lines .line.current { box-shadow: 0 0 0 2px var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); opacity: 1; }
.rehearse-lines.jumpable .line { cursor: pointer; }
.rehearse-lines.jumpable .line:hover { box-shadow: 0 0 0 1px var(--muted); }
.rehearse-lines.jumpable .line.current:hover { box-shadow: 0 0 0 2px var(--accent); }
.rehearse-lines .line.waiting { box-shadow: 0 0 0 3px var(--who); background: color-mix(in srgb, var(--who) 14%, var(--surface)); }
.live-tag {
  margin-left: 0.4rem;
  padding: 0.05em 0.45em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--who) 20%, transparent);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: 0.1em;
}
.your-turn { margin: 0.5rem 0 0; font-weight: 600; color: color-mix(in srgb, var(--who) 70%, var(--text)); }
.your-turn .peek { margin-left: 0.6rem; font-size: 0.85rem; padding: 0.25em 0.8em; font-weight: 600; }

/* Your lines on First word or Hide: a live line not yet said shows its
   masked version instead of the full text. */
.rehearse-lines .text.mask { display: none; }
.rehearse-lines[data-lines="hint"] .line.masked .text.full,
.rehearse-lines[data-lines="hide"] .line.masked .text.full { display: none; }
.rehearse-lines[data-lines="hint"] .line.masked .mask-hint,
.rehearse-lines[data-lines="hide"] .line.masked .mask-hide { display: block; }
.hidden-words { color: var(--muted); font-style: italic; }
.mask-hide .hidden-words {
  display: inline-block;
  padding: 0 0.6em;
  border: 1px dashed var(--line);
  border-radius: 6px;
  font-size: 0.9rem;
}

.rehearse-tools {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.2rem;
  margin: 0 0 0.8rem;
  padding: 0.5rem 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.line-mode { display: flex; align-items: center; gap: 0; border: 0; margin: 0; padding: 0; }
.line-mode[hidden] { display: none; }
.line-mode legend { float: left; margin-right: 0.5rem; padding: 0; font-size: 0.9rem; color: var(--muted); }
.line-mode label { cursor: pointer; }
.line-mode input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.line-mode span { display: block; padding: 0.3em 0.8em; border: 1px solid var(--line); background: var(--surface); font-size: 0.9rem; }
.line-mode label:first-of-type span { border-radius: 8px 0 0 8px; }
.line-mode label:last-of-type span { border-radius: 0 8px 8px 0; }
.line-mode label + label span { border-left: 0; }
.line-mode input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.line-mode input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pauses { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--muted); }
.pauses select { font-size: 0.9rem; padding: 0.25em 0.4em; color: var(--text); }
.keys { margin: 0 0 0 auto; font-size: 0.8rem; color: var(--muted); }
@media (hover: none) { .keys { display: none; } }

.play-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
  padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom));
}
.play-bar-inner { max-width: 1000px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; }
.play-status { flex: 1 1 14rem; margin: 0; font-weight: 600; min-height: 1.5em; }
.play-status.your-cue { color: var(--accent); }
.play-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; flex: none; }
.play-buttons button { min-width: 5.6rem; padding: 0.65em 0.9em; font-size: 1rem; }

@media (max-width: 860px) {
  .check-layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; overflow: visible; }
  .characters:not([open]) { padding-bottom: 1rem; }
}

@media (max-width: 600px) {
  main { padding: 1rem 1rem 3rem; }
  .load-options { grid-template-columns: 1fr; }
  .drop-zone { min-height: 8rem; }
  .screen-head { flex-direction: column; }
  .line { grid-template-columns: 2.4rem 1fr; padding: 0.5rem; gap: 0.45rem; }
  h1 { font-size: 1.35rem; }
  .play-bar-inner { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .play-status { flex: none; text-align: center; }
  #rehearse-screen { padding-bottom: 12rem; }
  .play-buttons button { flex: 1 1 4.5rem; min-width: 0; padding: 0.65em 0.4em; font-size: 0.9rem; }
  .voice-row select { flex: 1 1 10rem; }
}
