:root {
  --bg: #f7f3ec; --surface: #fffdf9; --surface-2: #f1ebe0; --ink: #23201b; --muted: #6f675b;
  --line: #e2d9ca; --accent: #6b3fa0; --accent-ink: #fff; --accent-soft: #ece4f6; --warn: #b4581c; --warn-soft: #fbeadd;
  --ok: #2f7a4b; --ok-soft: #e1f1e6; --hl: #fff1c2; --radius: 14px; --shadow: 0 1px 2px rgba(40,30,10,.06), 0 6px 24px rgba(40,30,10,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15131a; --surface: #1e1b24; --surface-2: #27232f; --ink: #ece7f2; --muted: #a49cb0; --line: #34303d;
    --accent: #b28cf0; --accent-ink: #1a1222; --accent-soft: #2e2640; --warn: #f0a46b; --warn-soft: #3a2a1e;
    --ok: #7fd09c; --ok-soft: #1d3326; --hl: #4a3f1a; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #15131a; --surface: #1e1b24; --surface-2: #27232f; --ink: #ece7f2; --muted: #a49cb0; --line: #34303d;
  --accent: #b28cf0; --accent-ink: #1a1222; --accent-soft: #2e2640; --warn: #f0a46b; --warn-soft: #3a2a1e;
  --ok: #7fd09c; --ok-soft: #1d3326; --hl: #4a3f1a; --shadow: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 Inter, system-ui, sans-serif; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 30px; } h2 { font-size: 22px; } h3 { font-size: 17px; }
a { color: var(--accent); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.brand { font-family: Fraunces, serif; font-weight: 700; letter-spacing: .08em; color: var(--ink); text-decoration: none; }
.brand .mark { color: var(--accent); }
#nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
main { max-width: 1040px; margin: 0 auto; padding: 28px 16px 80px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.cols { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
[hidden] { display: none !important; }  /* .row and other display rules must not reveal hidden boxes */
.spread { justify-content: space-between; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px;
  border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--warn); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
label.field { display: grid; gap: 6px; font-weight: 500; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: 13px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.choice { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; font-weight: 400; }
.choice input { width: auto; margin-top: 4px; }
.auth { max-width: 400px; margin: 6vh auto; }
.hero { text-align: center; margin-bottom: 22px; }
.hero p { font-family: Fraunces, serif; font-size: 18px; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.note.warn { background: var(--warn-soft); }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 20px; }
.steps a { text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line); font-size: 14px; }
.steps a.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.steps a .n { opacity: .6; margin-right: 4px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.char { display: grid; gap: 10px; align-content: start; }
.char .desc { font-size: 13px; color: var(--muted); max-height: 4.5em; overflow: hidden; }
.voice-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 13px; padding: 5px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.lines { display: grid; gap: 2px; }
.line { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 8px 10px; border-radius: 10px; align-items: start; }
.line:hover { background: var(--surface-2); }
.line .ctx { font-size: 13px; color: var(--muted); }
.line.uncertain { background: var(--warn-soft); }
.transcript { max-height: 56vh; overflow: auto; padding-right: 6px; }
.tl { padding: 6px 10px; border-radius: 8px; cursor: pointer; display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.tl.narr .who { visibility: hidden; }
.tl.narr .txt { color: var(--muted); }
.tl.on { background: var(--hl); }
.tl.on .txt { color: var(--ink); }
.who { font-size: 12px; font-weight: 600; color: var(--accent); padding-top: 2px; }
audio { width: 100%; margin: 8px 0 14px; }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }
.empty { text-align: center; padding: 48px 16px; }
.scenes { list-style: none; margin: 10px 0 0; padding: 0; }
.scene { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.scene:first-child { border-top: 0; }
.scene .when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; padding-top: 2px; }
.scene .ctl { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.scene .ctl select { width: auto; max-width: 220px; }
.card.book { display: flex; flex-direction: column; gap: 0; }
.card.book .cover { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; margin-bottom: 10px; }
.cover-sm { width: 72px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; box-shadow: var(--shadow); }
.scene .when { display: flex; flex-direction: column; gap: 6px; }
.char-img { float: right; width: 84px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; margin: 0 0 8px 12px; box-shadow: var(--shadow); }
.scene-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; }
.scene { grid-template-columns: 140px 1fr auto; }
@media (max-width: 640px) {
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .brand { white-space: nowrap; }
  #nav { gap: 6px; }
  #nav .btn, #nav button, #nav select { padding: 5px 9px; font-size: 13px; }
  .line, .tl { grid-template-columns: 1fr; gap: 4px; }
  .scene { grid-template-columns: 96px 1fr; }
  .scene .ctl { grid-column: 2; align-items: flex-start; }
  h1 { font-size: 24px; }
}
.engine { gap: 6px; align-items: center; }
.flagbox { gap: 6px; }
.lex { padding: 4px 0; border-bottom: 1px solid var(--line, rgba(127,127,127,.15)); }
video::cue { font-size: 0.95em; }
