/* Layout: a cutting-room desk. The picture stays put on the left; the script
   scrolls on the right as two facing columns, original and translation. */
:root {
  --bg: #f3f5f9; --surface: #ffffff; --ink: #18212f; --muted: #5d6979; --line: #d8dee8;
  --accent: #3346c4; --accent-ink: #ffffff; --shade: #e9edf3; --now: #fff3bd;
  --ok: #1c7f47; --warn: #a25f00; --bad: #b83227; --ok-bg: #dff3e7; --warn-bg: #fdeccb; --bad-bg: #fbe0dc;
  --text: "Sofia Sans", "Segoe UI", Arial, sans-serif;
  --label: "Sofia Sans Condensed", "Arial Narrow", Arial, sans-serif;
  --data: "JetBrains Mono", Consolas, "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141b; --surface: #181f2a; --ink: #e5e9f0; --muted: #98a4b5; --line: #2a3443;
    --accent: #9aa9ff; --accent-ink: #10141b; --shade: #141a24; --now: #3b3411;
    --ok: #62d091; --warn: #f1b651; --bad: #ff8b7d; --ok-bg: #16331f; --warn-bg: #3a2c0d; --bad-bg: #3d1a16;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--text); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1 { font: 700 28px/1.15 var(--label); margin: 0; text-wrap: balance; }
h2 { font: 700 14px/1.2 var(--label); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.data { font-family: var(--data); font-variant-numeric: tabular-nums; }

.btn { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 6px 12px; font: 600 16px/1.2 var(--label); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input[type="text"], input[type="search"], textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 6px 9px; }

/* Episode list */
.home { max-width: 1000px; margin: 0 auto; padding: 28px 16px 60px; display: flex; flex-direction: column; gap: 20px; }
.home header { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.home header p { color: var(--muted); max-width: 60ch; }
.episodes { display: flex; flex-direction: column; border: 1px solid var(--line); background: var(--surface); }
.episode { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 16px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.episode:last-child { border-bottom: 0; }
.episode:hover { background: var(--shade); }
.episode strong { font: 700 20px/1.2 var(--label); display: block; overflow-wrap: anywhere; }
.badges { display: flex; gap: 4px; }
.badge { font: 600 12px/1 var(--label); letter-spacing: .06em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 3px; padding: 3px 6px; color: var(--muted); }
.badge.on { color: var(--ok); border-color: var(--ok); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(10 14 20 / .55); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font: 600 15px/1.3 var(--label); }
dialog label small { font: 400 13px/1.3 var(--text); color: var(--muted); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
.error { color: var(--bad); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* Workspace */
.work { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.bar .title { font: 700 20px/1.2 var(--label); border: 1px solid transparent; background: none; padding: 3px 6px; min-width: 0; flex: 1 1 220px; }
.bar .title:hover, .bar .title:focus { border-color: var(--line); background: var(--bg); }
.saved { font: 400 13px/1 var(--data); color: var(--muted); min-width: 96px; text-align: right; }
.saved.busy { color: var(--warn); } .saved.fail { color: var(--bad); }
.split { display: grid; grid-template-columns: minmax(320px, 38%) minmax(0, 1fr); min-height: 0; }
.side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--surface); }
.screen { background: #000; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.screen video { width: 100%; height: 100%; display: block; }
.screen .novideo { color: #c9d1dc; text-align: center; padding: 16px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.screen .novideo .btn { background: #1d2532; border-color: #3a4658; color: #e5e9f0; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 12px 14px; }
.controls label { display: flex; align-items: center; gap: 6px; font: 600 15px/1.2 var(--label); }
.controls .nudge { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex-basis: 100%; }
.controls p { flex-basis: 100%; font-size: 15px; }
.cast { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cast label, .field { display: flex; flex-direction: column; gap: 3px; font: 600 14px/1.3 var(--label); }
.cast textarea { min-height: 150px; font: 400 15px/1.4 var(--text); }
.castbox { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 14px; }
.castbox > summary { cursor: pointer; font: 600 16px/1.3 var(--label); }
.castbox[open] { display: flex; flex-direction: column; gap: 10px; }
.castbox textarea, .castbox input { width: 100%; }
.castbox .field textarea { min-height: 70px; resize: vertical; }
.filebox { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.filebox p { overflow-wrap: anywhere; }
.srctitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30ch; }
.banner { padding: 10px 14px; background: var(--now); border-bottom: 1px solid var(--line); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
dialog.files .sheet { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog.files .actions { justify-content: space-between; }

.script { display: flex; flex-direction: column; min-height: 0; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.tools input[type="search"] { flex: 1 1 160px; min-width: 0; max-width: 420px; }
.lines { overflow: auto; flex: 1; scroll-behavior: smooth; }
.act { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line); padding: 5px 14px; font: 700 13px/1.2 var(--label); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.seg { display: grid; grid-template-columns: 58px minmax(0, 1fr) minmax(0, 1.15fr); border-bottom: 1px solid var(--line); background: var(--surface); }
.seg.sel { box-shadow: inset 3px 0 0 var(--accent); }
.seg.now .src { background: var(--now); }
.seg.none { background: var(--shade); }
.time { padding: 9px 4px 9px 12px; font: 400 13px/1.5 var(--data); color: var(--muted); }
.src { padding: 8px 12px; border: 0; background: none; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 5px; border-right: 1px solid var(--line); min-width: 0; }
.src:hover { background: var(--shade); }
.cue .who { font: 700 13px/1.3 var(--label); letter-spacing: .05em; color: var(--muted); }
.cue .who i { font: 400 13px var(--text); letter-spacing: 0; }
.cue p { overflow-wrap: anywhere; }
.tr { padding: 7px 10px 7px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tr .head { display: flex; align-items: center; gap: 6px; }
.tr .char { font: 700 14px/1.3 var(--label); letter-spacing: .05em; text-transform: uppercase; border-color: transparent; background: none; padding: 2px 4px; flex: 1 1 60px; min-width: 0; }
.tr .char:hover, .tr .char:focus { border-color: var(--line); background: var(--bg); }
.tr textarea { width: 100%; border-color: transparent; background: none; resize: none; overflow: hidden; padding: 3px 4px; line-height: 1.45; min-height: 30px; }
.tr textarea:hover, .tr textarea:focus { border-color: var(--line); background: var(--bg); }
.count { font: 400 13px/1.3 var(--data); color: var(--muted); padding: 0 4px; }
.count.long { color: var(--bad); font-weight: 600; }
.src .count { padding: 0; }
.gloss { font-size: 14px; color: var(--muted); }
.gloss::before { content: "ⓘ "; }
.more { position: relative; }
.more > summary { list-style: none; cursor: pointer; padding: 0 6px; color: var(--muted); font-weight: 700; border-radius: 3px; }
.more > summary::-webkit-details-marker { display: none; }
.more[open] > summary, .more > summary:hover { background: var(--shade); }
.more .menu { position: absolute; right: 0; top: 100%; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 6px 18px rgb(0 0 0 / .18); display: flex; flex-direction: column; min-width: 230px; padding: 4px; }
.more .menu button { background: none; border: 0; text-align: left; padding: 6px 8px; border-radius: 3px; }
.more .menu button:hover { background: var(--shade); }
.rownote { font-size: 14px; color: var(--warn); padding: 0 4px; overflow-wrap: anywhere; }
mark { background: var(--now); color: inherit; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 4px; z-index: 50; max-width: calc(100vw - 32px); }

@media (max-width: 900px) {
  .work { height: auto; min-height: 100vh; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .side { border-right: 0; position: sticky; top: 0; z-index: 4; border-bottom: 1px solid var(--line); }
  .lines { overflow: visible; }
  .seg { grid-template-columns: minmax(0, 1fr); }
  .time { padding: 6px 12px 0; }
  .src { border-right: 0; }
  .episode { grid-template-columns: minmax(0, 1fr) auto; }
  .cast { grid-template-columns: minmax(0, 1fr); }
}
.more.export > summary { color: var(--ink); font: 600 16px/1.2 var(--label); padding: 6px 12px; border-radius: 4px; }
.more.export[open] > summary, .more.export > summary:hover { background: var(--surface); border-color: var(--muted); }
.more.export .menu { min-width: 150px; }

/* Sign-in */
a.btn { display: inline-block; text-decoration: none; color: inherit; }
.home header .actions { display: flex; gap: 8px; align-items: center; }
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 16px; background: var(--surface); border: 1px solid var(--line); padding: 24px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.login input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); }
.login .btn { padding: 10px 12px; }
.login-error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; }
