:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel2: #1a2333;
  --fg: #e6edf3;
  --mute: #8b98a9;
  --line: #2a3446;
  --accent: #5eead4;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; overflow: hidden; }
button, select { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover, select:hover { border-color: var(--accent); }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#viewport { position: relative; flex: 1; overflow: hidden; background: var(--bg); }
#stage { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; transform-origin: 0 0;
  background: radial-gradient(ellipse at 50% 35%, #121a2a 0%, #0b0f17 70%); overflow: hidden; }
#svg { position: absolute; left: 0; top: 0; overflow: visible; }
#html-layer { position: absolute; inset: 0; }

/* ---------- animated objects ---------- */
.obj { position: absolute; white-space: nowrap; line-height: 1.25;
  transition: opacity .55s ease, left .8s cubic-bezier(.4,0,.2,1), top .8s cubic-bezier(.4,0,.2,1),
    transform .8s cubic-bezier(.4,0,.2,1), color .45s, background-color .45s, border-color .45s,
    width .8s cubic-bezier(.4,0,.2,1), height .8s cubic-bezier(.4,0,.2,1), filter .45s; }
.obj.wrap { white-space: normal; }
svg .sobj { transition: opacity .55s ease, transform .8s cubic-bezier(.4,0,.2,1), fill .45s, stroke .45s,
  stroke-dashoffset 1.1s ease-in-out, stroke-width .45s; }
#stage.instant .obj, #stage.instant .sobj, #stage.instant .obj * { transition: none !important; }

.box { display: flex; align-items: center; justify-content: center; text-align: center; border: 3px solid; border-radius: 14px;
  white-space: normal; padding: 6px 10px; }
.box-in { width: 100%; }
.title-main { font-weight: 800; letter-spacing: -0.02em; }
.heading { font-weight: 700; letter-spacing: -0.01em; }
.mono { font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; }
.tag { padding: 4px 12px; border-radius: 999px; border: 2px solid; }

.code { background: #0f1520; border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px;
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; white-space: pre; line-height: 1.5;
  box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.code .ln { display: block; padding: 0 8px; margin: 0 -8px; border-radius: 4px; transition: background-color .4s, opacity .4s; }
.code.has-hl .ln { opacity: .5; }
.code.has-hl .ln.hl { opacity: 1; background: rgba(94, 234, 212, .12); }
.code .k { color: #c792ea; } .code .t { color: #82aaff; } .code .s { color: #c3e88d; }
.code .n { color: #f78c6c; } .code .c { color: #6b7a90; font-style: italic; } .code .o { color: #89ddff; }
.code .f { color: #ffcb6b; }

.tbl { border-collapse: collapse; }
.tbl td { border: 1px solid #334055; padding: 6px 14px; text-align: center; transition: background-color .45s, color .45s; }
.tbl tr:first-child td { color: var(--mute); font-weight: 600; }

ul.bul { margin: 0; padding: 0; list-style: none; }
ul.bul li { margin: 0 0 .55em 0; padding-left: 1.2em; position: relative; transition: opacity .55s, transform .55s; }
ul.bul li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }
ul.bul li.pending { opacity: 0; transform: translateX(-12px); }

.katex { font-size: 1.05em; }

/* ---------- caption ---------- */
#caption { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: min(980px, 92%);
  background: rgba(5, 8, 13, .82); color: #f1f5f9; padding: 8px 16px; border-radius: 10px; font-size: 16px; line-height: 1.4;
  text-align: center; pointer-events: none; transition: opacity .3s; }
#caption:empty, #caption.off { opacity: 0; }

/* ---------- controls ---------- */
#controls { background: var(--panel); border-top: 1px solid var(--line); }
#progress { position: relative; height: 10px; background: #0d131d; cursor: pointer; }
#progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #2dd4bf, #60a5fa); }
#progress-marks .mk { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.35); }
#progress-hover { position: absolute; bottom: 14px; transform: translateX(-50%); background: #000; color: #fff; font-size: 12px;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; display: none; }
#bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
#time { font-variant-numeric: tabular-nums; color: var(--mute); font-size: 14px; min-width: 110px; }
#where { font-size: 14px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
#btn-cc.on { border-color: var(--accent); color: var(--accent); }

/* ---------- menu / start ---------- */
#menu, #start { position: fixed; inset: 0; background: rgba(4, 6, 10, .78); display: flex; align-items: center; justify-content: center; z-index: 10; }
#menu-inner { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(760px, 94vw); max-height: 86vh; overflow: auto; padding: 18px 22px; }
#menu-head { display: flex; justify-content: space-between; align-items: center; }
#menu-head h2 { margin: 0; }
.ch-item { display: flex; gap: 12px; align-items: baseline; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.ch-item:hover { background: var(--panel2); }
.ch-item.cur { background: rgba(94, 234, 212, .08); outline: 1px solid rgba(94,234,212,.35); }
.ch-num { color: var(--accent); font-weight: 700; min-width: 28px; }
.ch-title { flex: 1; }
.ch-dur { color: var(--mute); font-variant-numeric: tabular-nums; font-size: 14px; }
.ch-scenes { font-size: 13px; color: var(--mute); margin: 2px 0 0 40px; }
.ch-scenes span { cursor: pointer; margin-right: 10px; }
.ch-scenes span:hover { color: var(--accent); }
.menu-help { color: var(--mute); font-size: 13px; }
#start-inner { text-align: center; max-width: 640px; padding: 24px; }
#start-inner h1 { font-size: 44px; margin: 0 0 8px; letter-spacing: -0.02em; }
#start-inner p { color: var(--mute); }
#start-btn, #resume-btn { font-size: 20px; padding: 12px 28px; margin: 8px; border-radius: 12px; }
#start-btn { background: #0f766e; border-color: #14b8a6; }
#audio-warn { color: #fbbf24 !important; font-size: 14px; }

@media (max-width: 700px) {
  #where, #time { display: none; }
  #caption { font-size: 14px; }
}

/* ---------- quiz ---------- */
#btn-quiz.on { border-color: var(--accent); color: var(--accent); }
#quiz { position: fixed; inset: 0; background: rgba(4, 6, 10, .82); display: flex; align-items: center; justify-content: center; z-index: 11; }
#quiz-inner { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(860px, 94vw); max-height: 90vh;
  display: flex; flex-direction: column; }
#quiz-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 22px 10px; border-bottom: 1px solid var(--line); }
#quiz-kicker { color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
#quiz-head h2 { margin: 4px 0 0; font-size: 22px; }
#quiz-list { overflow: auto; padding: 8px 22px 14px; }
.qz { padding: 14px 0; border-bottom: 1px solid #1f2838; }
.qz:last-child { border-bottom: 0; }
.qz-q { font-size: 17px; line-height: 1.5; margin-bottom: 10px; }
.qz-n { color: var(--accent); font-weight: 700; margin-right: 6px; }
.qz-choices { display: grid; gap: 6px; }
.qz-choice { text-align: left; padding: 8px 12px; font-size: 15px; line-height: 1.4; background: var(--panel2); }
.qz-choice.right { border-color: #4ade80; background: rgba(74, 222, 128, .12); }
.qz-choice.wrong { border-color: #f87171; background: rgba(248, 113, 113, .12); }
.qz-choice:disabled { cursor: default; color: var(--fg); }
.qz-choice:disabled:not(.right):not(.wrong) { opacity: .55; }
.qz-num { display: flex; gap: 8px; align-items: center; }
.qz-num input { font: inherit; font-size: 16px; color: var(--fg); background: #0d131d; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 180px; }
.qz-num input.right { border-color: #4ade80; } .qz-num input.wrong { border-color: #f87171; }
.qz-fb { margin-top: 10px; font-size: 15px; line-height: 1.5; padding: 8px 12px; border-radius: 8px; }
.qz-fb.right { background: rgba(74, 222, 128, .08); border-left: 3px solid #4ade80; }
.qz-fb.wrong { background: rgba(248, 113, 113, .08); border-left: 3px solid #f87171; }
.qz-fb b:first-child { margin-right: 4px; }
.qz code, .qz-fb code { font-family: "JetBrains Mono", "SF Mono", Menlo, monospace; font-size: .92em; background: #0d131d; padding: 1px 5px; border-radius: 4px; }
#quiz-foot { display: flex; gap: 8px; align-items: center; padding: 12px 22px; border-top: 1px solid var(--line); }
#quiz-score { color: var(--mute); font-size: 14px; }
#quiz-next.ready { background: #0f766e; border-color: #14b8a6; }
#quiz-opt { display: block; margin-top: 14px; color: var(--mute); font-size: 15px; cursor: pointer; }
#quiz-opt input { margin-right: 6px; vertical-align: middle; }
.ch-quiz { font-size: 12px; color: var(--mute); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; cursor: pointer; }
.ch-quiz:hover { border-color: var(--accent); color: var(--accent); }
.ch-quiz.pass { color: #4ade80; border-color: rgba(74, 222, 128, .5); }

/* ---------- audio load warning ---------- */
#audio-toast { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); max-width: min(760px, 92%);
  background: rgba(127, 29, 29, .92); color: #fee2e2; border: 1px solid #f87171; padding: 8px 16px; border-radius: 10px;
  font-size: 15px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 5; }
#audio-toast.on { opacity: 1; }
