:root {
  --iaf: #ff8c1a;
  --paf: #39d98a;
  --rec: #ffc48a;
  --bg: #0b0f14;
  --panel: rgba(12, 16, 22, 0.86);
  --text: #e8e8e8;
  --muted: #9aa5ab;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
canvas#scene { position: fixed; inset: 0; display: block; }
button { font: inherit; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px;
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: linear-gradient(to bottom, rgba(8, 10, 14, 0.92), rgba(8, 10, 14, 0.55));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
#clock {
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 16px; letter-spacing: 0.08em;
  color: #fff; white-space: pre; background: rgba(255, 255, 255, 0.06); padding: 6px 10px; border-radius: 4px;
  border-left: 3px solid var(--iaf);
}
#chapterTitle { font-size: 15px; font-weight: 600; color: #f4f4f4; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status {
  display: flex; gap: 12px; align-items: center; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11px;
  background: rgba(255, 140, 26, 0.08); border: 1px solid rgba(255, 140, 26, 0.35); padding: 5px 10px; border-radius: 4px;
  white-space: nowrap;
}
#status .who { color: var(--iaf); font-weight: 700; margin-right: 4px; }
#status .item { color: var(--muted); }
#status b { color: #fff; font-weight: 600; }
#status b.warn { color: #ffd27a; }
#status b.bad { color: #ff6b6b; }

/* ---------- sidebar ---------- */
#sidebar {
  position: fixed; top: 58px; left: 0; bottom: 150px; width: 268px; padding: 14px 14px 10px;
  background: var(--panel); border-right: 1px solid rgba(255, 255, 255, 0.06);
  overflow-y: auto; transition: transform 0.25s ease;
}
#sidebar.hidden { transform: translateX(-100%); }
#sidebar h1 { font-family: var(--serif); font-size: 20px; line-height: 1.15; margin: 0 0 6px; color: #fff; }
#sidebar h1 span { font-size: 13px; color: var(--rec); font-family: var(--font); font-weight: 500; }
#sidebar .sub { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.4; }
#sidebar h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 8px 0 6px; }
#chapterList { list-style: none; margin: 0; padding: 0; }
#chapterList li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: baseline;
  padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 12.5px; line-height: 1.3; color: #d8dde2;
}
#chapterList li:hover { background: rgba(255, 255, 255, 0.06); }
#chapterList li.active { background: rgba(255, 140, 26, 0.16); color: #fff; box-shadow: inset 3px 0 0 var(--iaf); }
#chapterList .num { color: var(--muted); font-family: "SF Mono", Menlo, monospace; font-size: 11px; }
#chapterList .clk { color: var(--muted); font-family: "SF Mono", Menlo, monospace; font-size: 10.5px; }
#sidebar .legend { font-size: 11px; color: var(--muted); margin-top: 14px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.sw.iaf { background: var(--iaf); }
.sw.paf { background: var(--paf); }
.sw.rec { border: 1px dashed var(--rec); }

/* ---------- caption ---------- */
#caption {
  position: fixed; left: 50%; bottom: 158px; transform: translateX(-50%);
  width: min(820px, calc(100vw - 32px)); padding: 10px 16px 12px;
  background: rgba(8, 10, 14, 0.86); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 8px;
  font-size: 15px; line-height: 1.45; color: #f3f3f3; transition: opacity 0.25s;
}
#caption.empty { opacity: 0; }
#caption .caphead { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rec); }
#caption.radio { border-color: rgba(127, 224, 255, 0.4); font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 14px; }
#capRadio { display: none; background: #7fe0ff; color: #05222c; padding: 1px 6px; border-radius: 3px; font-weight: 700; }
#capBadge { display: none; border: 1px dashed var(--rec); color: var(--rec); padding: 1px 7px; border-radius: 10px; font-size: 10px; letter-spacing: 0.06em; }
#capSpeaker:empty { display: none; }

/* ---------- controls ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0; height: 150px; padding: 10px 16px 12px;
  background: linear-gradient(to top, rgba(8, 10, 14, 0.96), rgba(8, 10, 14, 0.7));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
#controls .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#controls .scrubrow { position: relative; height: 34px; margin-bottom: 8px; display: block; }
#scrub { width: 100%; margin: 12px 0 0; -webkit-appearance: none; appearance: none; height: 6px; background: rgba(255, 255, 255, 0.15); border-radius: 3px; outline: none; }
#scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--iaf); border: 2px solid #fff; cursor: pointer; }
#scrub::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--iaf); border: 2px solid #fff; cursor: pointer; }
#ticks { position: absolute; left: 8px; right: 8px; top: 4px; height: 6px; pointer-events: none; }
#ticks span { position: absolute; top: 0; width: 1px; height: 6px; background: rgba(255, 255, 255, 0.5); }
#controls button {
  background: rgba(255, 255, 255, 0.08); color: #fff; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 5px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
}
#controls button:hover { background: rgba(255, 255, 255, 0.16); }
#btnPlay { min-width: 74px; background: var(--iaf); color: #1a1000; font-weight: 700; border-color: transparent; }
#btnPlay.playing { background: rgba(255, 255, 255, 0.14); color: #fff; }
#controls .group button { border-radius: 0; margin-left: -1px; }
#controls .group button:first-child { border-radius: 5px 0 0 5px; }
#controls .group button:last-child { border-radius: 0 5px 5px 0; }
#controls .group button.active { background: rgba(255, 140, 26, 0.3); border-color: var(--iaf); }
#timeLabel { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); min-width: 96px; }
.toggle { font-size: 12px; color: #d8dde2; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { accent-color: var(--iaf); }
#controls .ghost { background: transparent; color: var(--muted); }
#controls .ghost.active { color: var(--rec); border-color: rgba(255, 196, 138, 0.5); }
.hint { margin-left: auto; font-size: 11px; color: var(--muted); font-family: "SF Mono", Menlo, monospace; }

#errlog { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #status { display: none; }
  #clock { font-size: 13px; }
  #chapterTitle { font-size: 13px; }
  #caption { font-size: 13px; bottom: 150px; }
  #controls { height: 150px; }
  .hint { display: none; }
}
