/* ===========================================================================
   DocReader — "Lamplight"
   A warm paper reading room. Three themes, fused karaoke band with a
   travelling word-light, floating glass transport. Fully offline, system fonts.
   =========================================================================== */

/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="light"] {
  --bg:#F4F1EA; --surface:#FBF9F4; --surface2:#FFFFFF; --surface-glass:rgba(251,249,244,.82);
  --text:#23211C; --text-body:#37352F; --muted:#6E6A60; --faint:#9C988C;
  --border:#E3DED3; --border-strong:#D6CFC1;
  --accent:#9A3412; --accent-hover:#7C2A0E; --accent-text:#FFFFFF;
  --dim-text:#B4AEA2; --spotlight-dim:#C7C1B3;
  --hl-sent:#EFE7D6; --hl-sent-ring:rgba(154,52,18,.14);
  --hl-word:#F2D9B8; --hl-word-text:#7A3D12; --hl-word-glow:rgba(224,160,80,.40); --hl-word-ring:rgba(184,133,62,.55);
  --selection:#E7D3B6; --focus-ring:rgba(154,52,18,.40);
  --progress-track:rgba(35,33,28,.10); --progress-fill:#9A3412;
  --scrim:rgba(35,33,28,.28);
  --shadow:0 1px 2px rgba(70,52,32,.05), 0 10px 34px rgba(70,52,32,.12);
  --kbd-bg:#F4ECD9; --danger:#B91C1C; --danger-surface:#F7E4E1;
  --vignette:transparent;
}
:root[data-theme="sepia"] {
  --bg:#ECE3D2; --surface:#F3ECDD; --surface2:#FAF3E2; --surface-glass:rgba(243,236,221,.84);
  --text:#3A2F22; --text-body:#473B2B; --muted:#7A6E58; --faint:#A1937A;
  --border:#DCCFB6; --border-strong:#CDBE9F;
  --accent:#9A3412; --accent-hover:#7C2A0E; --accent-text:#FBF4E6;
  --dim-text:#B6A98F; --spotlight-dim:#C3B79C;
  --hl-sent:#E5D8BE; --hl-sent-ring:rgba(154,52,18,.16);
  --hl-word:#E7CF9C; --hl-word-text:#5E2E0C; --hl-word-glow:rgba(216,160,72,.42); --hl-word-ring:rgba(194,142,44,.55);
  --selection:#DEC7A0; --focus-ring:rgba(154,52,18,.42);
  --progress-track:rgba(59,47,34,.12); --progress-fill:#9A3412;
  --scrim:rgba(59,47,34,.30);
  --shadow:0 1px 2px rgba(60,46,30,.06), 0 10px 32px rgba(60,46,30,.16);
  --kbd-bg:#E5D8BE; --danger:#9A2A1A; --danger-surface:#EFD9CF;
  --vignette:transparent;
}
:root[data-theme="dark"] {
  --bg:#16151A; --surface:#1D1C22; --surface2:#26242B; --surface-glass:rgba(29,28,34,.86);
  --text:#E8E4DC; --text-body:#D6D1C6; --muted:#9A938A; --faint:#6B655D;
  --border:#2E2C33; --border-strong:#3A3741;
  --accent:#E0A063; --accent-hover:#EBB479; --accent-text:#1A150F;
  --dim-text:#5A554E; --spotlight-dim:#48443E;
  --hl-sent:#252029; --hl-sent-ring:rgba(224,160,99,.18);
  --hl-word:#E0A063; --hl-word-text:#1A150F; --hl-word-glow:rgba(240,184,110,.50); --hl-word-ring:rgba(201,138,78,.55);
  --selection:#473722; --focus-ring:rgba(224,160,99,.45);
  --progress-track:rgba(255,255,255,.06); --progress-fill:#E0A063;
  --scrim:rgba(0,0,0,.50);
  --shadow:0 1px 2px rgba(0,0,0,.30), 0 12px 40px rgba(0,0,0,.45);
  --kbd-bg:#26242B; --danger:#FF6B6B; --danger-surface:#2A1416;
  --vignette:radial-gradient(120% 80% at 50% 38%, transparent 55%, rgba(0,0,0,.22) 100%);
}

/* ---------- Static tokens ---------- */
:root {
  --font-serif:"Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,Cambria,"Noto Serif",serif;
  --font-sans:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --font-mono:ui-monospace,"Cascadia Code","SF Mono",Consolas,"Liberation Mono",monospace;
  --read-font:var(--font-serif);
  --read-size:20px; --leading:1.7; --measure:64ch;
  --ease:cubic-bezier(.4,0,.2,1); --ease-out:cubic-bezier(.22,1,.36,1);
}
:root[data-font="sans"] { --read-font:var(--font-sans); }
:root[data-font="mono"] { --read-font:var(--font-mono); }

* { box-sizing:border-box; }
[hidden] { display:none !important; }   /* must beat component display rules */
html, body { height:100%; }
body {
  margin:0; background:var(--bg); color:var(--text-body);
  font-family:var(--font-sans); font-size:14px;
  display:flex; flex-direction:column; overflow:hidden;
  transition:background-color .28s ease, color .28s ease;
  -webkit-font-smoothing:antialiased;
}
::selection { background:var(--selection); }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }

button { font-family:inherit; cursor:pointer; color:inherit; }
:focus-visible { outline:2px solid var(--accent); outline-offset:2px; border-radius:6px; }

/* ===================== TOP BAR ===================== */
#bar {
  height:52px; flex:0 0 auto; display:flex; align-items:center; justify-content:space-between;
  gap:14px; padding:0 16px; z-index:30;
  background:var(--surface-glass); backdrop-filter:blur(12px) saturate(120%); -webkit-backdrop-filter:blur(12px) saturate(120%);
  border-bottom:1px solid var(--border);
}
.brand { display:flex; align-items:center; gap:10px; min-width:0; }
.brand-tile {
  width:22px; height:22px; flex:0 0 auto; border-radius:7px; background:var(--accent); color:var(--accent-text);
  display:grid; place-items:center;
}
.brand-text { display:flex; flex-direction:column; min-width:0; line-height:1.15; }
.kicker { font-size:11.5px; font-weight:600; letter-spacing:.14em; text-transform:uppercase; color:var(--accent); }
.title-line { display:flex; align-items:baseline; gap:6px; min-width:0; }
#title { font-family:var(--font-serif); font-style:italic; font-size:13px; font-weight:600; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:42vw; }
.breadcrumb { font-size:12px; color:var(--faint); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.breadcrumb:not(:empty)::before { content:"· "; }

.bar-actions { display:flex; align-items:center; gap:4px; flex:0 0 auto; }
.icon-btn {
  width:32px; height:32px; border:none; background:transparent; color:var(--faint);
  border-radius:8px; display:grid; place-items:center; transition:color .15s, background-color .15s, transform .1s;
}
.icon-btn:hover { color:var(--text); background:color-mix(in srgb, var(--text) 7%, transparent); }
.icon-btn:active { transform:scale(.96); }
.icon-btn.aa { font-family:var(--font-serif); font-size:15px; font-weight:600; }
.icon-btn.accent { background:var(--accent); color:var(--accent-text); }
.icon-btn.accent:hover { background:var(--accent-hover); color:var(--accent-text); }
.icon-btn.close { color:var(--muted); font-size:15px; }

/* ===================== PROGRESS RAIL ===================== */
#progress { position:relative; height:3px; flex:0 0 auto; background:var(--progress-track); cursor:pointer; z-index:29; }
#progress:hover { height:5px; }
#progressBar { position:relative; height:100%; width:0; background:var(--progress-fill); transition:width .35s var(--ease); }
#progressBar::after {
  content:""; position:absolute; right:-3px; top:50%; width:7px; height:7px; border-radius:50%;
  background:var(--accent); transform:translateY(-50%); opacity:0;
}
body.playing #progressBar::after { opacity:1; animation:pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 0%,100%{ transform:translateY(-50%) scale(1);} 50%{ transform:translateY(-50%) scale(1.35);} }
.seek-tip {
  position:absolute; bottom:10px; transform:translateX(-50%); white-space:nowrap;
  background:var(--surface2); color:var(--text); border:1px solid var(--border); border-radius:7px;
  padding:3px 8px; font-size:12px; box-shadow:var(--shadow); pointer-events:none; z-index:31;
  max-width:40ch; overflow:hidden; text-overflow:ellipsis;
}

/* ===================== READING STAGE ===================== */
#reader {
  position:relative; flex:1 1 auto; overflow-y:auto; overflow-x:hidden;
  -webkit-mask-image:linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
          mask-image:linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
}
#reader::before { content:""; position:fixed; inset:52px 0 0 0; pointer-events:none; background:var(--vignette); z-index:0; }

#leftRail { position:fixed; left:0; top:55px; bottom:0; width:6px; z-index:5; opacity:0; transition:opacity .3s; }
body.has-doc #leftRail { opacity:1; }
#leftRailFill { position:absolute; left:0; top:0; width:100%; height:0; background:var(--accent); opacity:.5; transition:height .35s var(--ease); }
#leftRail:hover #leftRailFill { opacity:.85; }

#doc {
  position:relative; z-index:1; display:none; max-width:var(--measure); margin:0 auto;
  padding:6vh clamp(20px,5vw,52px) 52vh;
  font-family:var(--read-font); font-size:var(--read-size); line-height:var(--leading);
  color:var(--text-body); hyphens:auto; text-wrap:pretty;
}
#doc.show { display:block; }

#doc h1,#doc h2,#doc h3,#doc h4 { font-family:var(--font-serif); color:var(--text); }
#doc h1 { font-size:1.95em; font-weight:700; line-height:1.25; letter-spacing:-.012em; margin:.2em 0 .15em; }
#doc h2 { font-size:1.56em; font-weight:700; line-height:1.3; margin:2em 0 .35em; position:relative; }
#doc h2::after { content:""; display:block; width:24px; height:2px; background:var(--accent); margin-top:.3em; border-radius:2px; }
#doc h3 { font-size:1.25em; font-weight:600; font-style:italic; line-height:1.35; margin:1.6em 0 .25em; }
#doc h4 { font-size:1.08em; font-weight:600; margin:1.3em 0 .2em; }
#doc p { margin:0 0 1em; }
#doc > p:first-of-type::first-letter {
  float:left; font-size:3.4em; font-weight:700; line-height:.72; color:var(--accent);
  padding:.02em .12em 0 0;
}
#doc ul,#doc ol { margin:0 0 1em; padding-left:1.4em; }
#doc li { margin:.25em 0; }
#doc blockquote { margin:1.4em 0; padding-left:1em; border-left:2px solid var(--accent); color:var(--muted); font-style:italic; }
#doc a { color:var(--accent); text-underline-offset:2px; }
#doc img { max-width:100%; border-radius:8px; }
#doc hr { border:none; border-top:1px solid var(--border-strong); margin:2em 0; }
#doc pre {
  background:var(--surface); border:1px solid var(--border); border-radius:10px;
  padding:14px 16px; overflow:auto; font-size:.78em; line-height:1.5; font-family:var(--font-mono);
}
#doc code { font-family:var(--font-mono); font-size:.85em; }
#doc :not(pre) > code { background:var(--surface); border:1px solid var(--border); border-radius:5px; padding:.05em .35em; }
#doc table { border-collapse:collapse; width:100%; font-size:.9em; margin:1.2em 0; }
#doc th,#doc td { border:1px solid var(--border-strong); padding:7px 11px; text-align:left; }
#doc th { background:var(--surface); }

/* ---------- Word highlighting (class-toggle, reflow-proof) ---------- */
.w {
  border-radius:4px; padding:0 2px; margin:0 -2px; cursor:pointer;
  transition:background-color 90ms linear, color 200ms ease;
}
.w:hover { background:var(--hl-sent); }
.w.sent { background:var(--hl-sent); box-shadow:0 0 0 1px var(--hl-sent); }       /* fuse into one band */
.w.hl   { background:var(--hl-word); color:var(--hl-word-text); position:relative; z-index:1;
          box-shadow:0 0 0 1px var(--hl-word-ring), 0 0 14px 1px var(--hl-word-glow); will-change:background-color; }

/* focus modes */
:root[data-focus="spotlight"] #doc.show .w { color:var(--spotlight-dim); }
:root[data-focus="spotlight"] #doc.show .w.sent { color:var(--text); }
:root[data-focus="spotlight"] #doc.show .w.hl { color:var(--hl-word-text); }
:root[data-focus="off"] .w.sent { background:transparent; box-shadow:none; }

/* highlight styles */
:root[data-hl="underline"] .w.sent { background:transparent; box-shadow:none; }
:root[data-hl="underline"] .w.hl { background:transparent; color:inherit; box-shadow:none; text-decoration:underline; text-decoration-color:var(--accent); text-decoration-thickness:3px; text-underline-offset:3px; }
:root[data-hl="box"] .w.hl { background:transparent; color:inherit; box-shadow:inset 0 0 0 2px var(--accent); }

/* buffering shimmer on current sentence while synthesizing */
.w.buffering { background:linear-gradient(100deg, var(--hl-sent) 30%, color-mix(in srgb, var(--hl-sent) 60%, var(--surface2)) 50%, var(--hl-sent) 70%); background-size:200% 100%; animation:shimmer 1.4s linear infinite; }
@keyframes shimmer { from{ background-position:200% 0;} to{ background-position:-200% 0;} }

/* ---------- Empty state ---------- */
#dropzone { position:absolute; inset:0; display:none; align-items:center; justify-content:center; z-index:2; padding:24px; }
#dropzone.empty { display:flex; }
.hint { text-align:center; max-width:540px; }
.book { color:var(--faint); display:inline-block; animation:breathe 6s ease-in-out infinite; }
@keyframes breathe { 0%,100%{ opacity:.85;} 50%{ opacity:1;} }
.hint h1 { font-family:var(--font-serif); font-size:34px; font-weight:700; color:var(--text); margin:14px 0 6px; }
.deck { font-family:var(--font-serif); font-style:italic; font-size:18px; color:var(--muted); margin:0 auto 14px; max-width:42ch; line-height:1.5; }
.formats { font-size:11.5px; font-weight:600; letter-spacing:.12em; text-transform:uppercase; color:var(--faint); margin:0 0 22px; }
.empty-actions { display:flex; flex-direction:column; align-items:center; gap:12px; }
.primary-pill { background:var(--accent); color:var(--accent-text); border:none; border-radius:999px; padding:11px 26px; font-size:15px; font-weight:600; transition:background-color .15s, transform .1s; }
.primary-pill:hover { background:var(--accent-hover); }
.primary-pill:active { transform:scale(.98); }
.path-form { display:flex; gap:6px; width:min(420px,90vw); }
.path-form input { flex:1; background:var(--surface); border:1px solid var(--border); border-radius:9px; padding:9px 12px; font:inherit; color:var(--text); }
.path-form input::placeholder { color:var(--faint); }
.ghost-pill { background:var(--surface); border:1px solid var(--border); border-radius:9px; padding:0 16px; font-weight:500; color:var(--muted); }
.ghost-pill:hover { border-color:var(--accent); color:var(--text); }
.privacy { font-size:12.5px; color:var(--faint); margin:2px 0 0; max-width:40ch; }
.recent-label { margin:26px 0 10px; color:var(--faint); }
.recent-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:10px; text-align:left; }
.recent-card { background:var(--surface); border:1px solid var(--border); border-radius:11px; padding:12px 13px; transition:border-color .15s, transform .1s; min-width:0; }
.recent-card:hover { border-color:var(--accent); transform:translateY(-1px); }
.recent-card .rc-title { font-family:var(--font-serif); font-size:15px; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.recent-card .rc-meta { font-size:11.5px; color:var(--faint); margin-top:4px; }
.recent-card .rc-bar { height:3px; background:var(--progress-track); border-radius:2px; margin-top:8px; overflow:hidden; }
.recent-card .rc-bar > i { display:block; height:100%; background:var(--accent); }
.kbd-hints { font-size:12.5px; color:var(--muted); margin:26px 0 8px; }
.kbd-hints .t { font-style:italic; }
.engine { font-size:11px; color:var(--faint); margin:0; }
kbd {
  display:inline-block; font-family:var(--font-mono); font-size:11px; line-height:1.4; color:var(--muted);
  background:var(--kbd-bg); border:1px solid var(--border-strong); border-bottom-width:2px; border-radius:5px; padding:1px 6px; margin:0 1px;
}
body.dragover #dropzone::after { content:"Release to open"; position:absolute; inset:14px; border:2px dashed var(--accent); border-radius:16px; background:var(--hl-sent); display:grid; place-items:center; font-weight:600; color:var(--accent); animation:offset 2.4s ease-in-out infinite; }
@keyframes offset { 0%,100%{ inset:14px;} 50%{ inset:10px;} }

/* ---------- Loading ---------- */
#loading { position:absolute; inset:0; z-index:3; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; color:var(--muted); }
.spinner { width:30px; height:30px; border-radius:50%; border:3px solid var(--border); border-top-color:var(--accent); animation:spin .8s linear infinite; }
@keyframes spin { to{ transform:rotate(360deg);} }

#resumeScroll {
  position:fixed; bottom:96px; left:50%; transform:translateX(-50%); z-index:25;
  background:var(--surface2); color:var(--text); border:1px solid var(--border); border-radius:999px;
  padding:7px 16px; font-size:13px; box-shadow:var(--shadow);
}

/* ===================== FLOATING TRANSPORT ===================== */
#player {
  position:fixed; left:50%; bottom:24px; transform:translateX(-50%); z-index:24;
  width:min(560px,100% - 48px); display:flex; flex-direction:column; gap:8px;
  background:var(--surface-glass); backdrop-filter:blur(14px) saturate(120%); -webkit-backdrop-filter:blur(14px) saturate(120%);
  border:1px solid var(--border); border-radius:22px; padding:10px 16px 12px; box-shadow:var(--shadow);
  transition:opacity .28s var(--ease-out), transform .28s var(--ease-out);
  animation:riseIn .4s var(--ease-out);
}
@keyframes riseIn { from{ opacity:0; transform:translate(-50%,12px);} to{ opacity:1; transform:translate(-50%,0);} }
#player.idle { opacity:0; transform:translate(-50%,12px); pointer-events:none; }
.player-top { display:flex; align-items:center; gap:10px; }
.readout { font-family:var(--font-mono); font-size:12.5px; color:var(--muted); font-variant-numeric:tabular-nums; flex:0 0 auto; }
.player-main { display:flex; align-items:center; justify-content:center; gap:6px; }
.t-btn { width:34px; height:34px; border:none; background:transparent; color:var(--muted); border-radius:9px; display:grid; place-items:center; transition:color .15s, background-color .15s, transform .1s; }
.t-btn:hover { color:var(--text); background:color-mix(in srgb,var(--text) 7%,transparent); }
.t-btn:active { transform:scale(.94); }
.t-divider { width:1px; height:22px; background:var(--border); margin:0 4px; }
.play-btn {
  width:46px; height:46px; border:none; border-radius:50%; background:var(--accent); color:var(--accent-text);
  display:grid; place-items:center; transition:background-color .15s, transform .1s, box-shadow .3s;
}
.play-btn:hover { background:var(--accent-hover); }
.play-btn:active { transform:scale(.96); }
.play-btn:disabled { opacity:.45; }
body.playing .play-btn { box-shadow:0 0 18px 0 var(--hl-word-glow); }
.pill-btn { background:transparent; border:1px solid var(--border); border-radius:999px; padding:5px 12px; font-family:var(--font-mono); font-size:12.5px; font-variant-numeric:tabular-nums; color:var(--muted); transition:border-color .15s, color .15s; }
.pill-btn:hover { border-color:var(--accent); color:var(--text); }
.voice-pill { display:inline-flex; align-items:center; gap:6px; font-family:var(--font-sans); padding:5px 12px 5px 10px; max-width:150px; }
#voiceLabel { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:104px; }
@media (max-width:430px) { #voiceLabel { display:none; } .voice-pill { padding:5px 9px; } }

/* scrubber (native range, restyled) */
#scrubber { flex:1 1 auto; -webkit-appearance:none; appearance:none; height:18px; background:transparent; cursor:pointer; }
#scrubber::-webkit-slider-runnable-track { height:3px; border-radius:3px; background:linear-gradient(to right, var(--accent) var(--fill,0%), var(--border) var(--fill,0%)); }
#scrubber::-moz-range-track { height:3px; border-radius:3px; background:var(--border); }
#scrubber::-moz-range-progress { height:3px; border-radius:3px; background:var(--accent); }
#scrubber::-webkit-slider-thumb { -webkit-appearance:none; appearance:none; width:13px; height:13px; border-radius:50%; background:var(--accent); margin-top:-5px; box-shadow:0 1px 3px rgba(0,0,0,.25); }
#scrubber::-moz-range-thumb { width:13px; height:13px; border:none; border-radius:50%; background:var(--accent); box-shadow:0 1px 3px rgba(0,0,0,.25); }

/* popovers */
.popover {
  position:absolute; bottom:calc(100% + 10px); background:var(--surface2); border:1px solid var(--border);
  border-radius:14px; box-shadow:var(--shadow); padding:12px 14px; width:240px; max-width:calc(100vw - 16px); z-index:26;
  animation:popIn .18s var(--ease-out);
}
@keyframes popIn { from{ opacity:0; transform:translateY(6px);} to{ opacity:1; transform:translateY(0);} }
#speedPop { right:48px; } #voicePop { right:8px; }
.popover .kicker { display:block; margin-bottom:10px; }
.speed-row { display:flex; align-items:center; gap:10px; }
.speed-row input { flex:1; accent-color:var(--accent); }
.chips { display:flex; gap:6px; margin-top:12px; }
.chips button { flex:1; background:var(--surface); border:1px solid var(--border); border-radius:8px; padding:6px 0; font-size:12px; color:var(--muted); transition:.15s; }
.chips button:hover { border-color:var(--accent); color:var(--text); }
.chips button.on { background:var(--accent); border-color:var(--accent); color:var(--accent-text); }
.voice-list { display:flex; flex-direction:column; gap:2px; max-height:300px; overflow:auto; }
.voice-group { margin:10px 4px 3px; color:var(--faint); position:sticky; top:0; background:var(--surface2); }
.voice-group:first-child { margin-top:2px; }
.voice-row { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px 10px; border-radius:8px; transition:background-color .15s; }
.voice-row:hover { background:var(--surface); }
.voice-row.on { background:var(--hl-sent); }
.voice-row .vname { font-family:var(--font-serif); font-size:14px; color:var(--text); text-align:left; }
.voice-row button.prev { width:24px; height:24px; border:none; background:transparent; color:var(--muted); border-radius:6px; display:grid; place-items:center; }
.voice-row button.prev:hover { color:var(--accent); }
.engine-foot { margin:10px 0 0; color:var(--faint); }

/* ===================== DRAWERS / MODAL / SCRIM ===================== */
#scrim { position:fixed; inset:0; background:var(--scrim); z-index:40; animation:fade .18s ease; }
@keyframes fade { from{opacity:0;} to{opacity:1;} }
.drawer { position:fixed; top:0; bottom:0; width:320px; max-width:88vw; z-index:41; background:var(--surface2); box-shadow:var(--shadow); display:flex; flex-direction:column; }
.drawer.left { left:0; border-right:1px solid var(--border); animation:slideL .28s var(--ease-out); }
.drawer.right { right:0; border-left:1px solid var(--border); animation:slideR .28s var(--ease-out); }
@keyframes slideL { from{ transform:translateX(-100%);} to{ transform:translateX(0);} }
@keyframes slideR { from{ transform:translateX(100%);} to{ transform:translateX(0);} }
.drawer-head { display:flex; align-items:center; gap:10px; padding:16px 16px 12px; border-bottom:1px solid var(--border); }
.drawer-head .kicker { flex:1; }
.drawer-body { padding:6px 16px 20px; overflow:auto; }

.set-row { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:13px 0; border-bottom:1px solid var(--border); }
.set-row:last-of-type { border-bottom:none; }
.set-row > label { font-size:13px; font-weight:500; color:var(--muted); flex:0 0 auto; }
.seg { display:flex; background:var(--surface); border:1px solid var(--border); border-radius:9px; padding:2px; gap:2px; }
.seg button { border:none; background:transparent; color:var(--muted); border-radius:7px; padding:5px 9px; font-size:12px; font-weight:500; transition:.15s; white-space:nowrap; }
.seg button:hover { color:var(--text); }
.seg button.on { background:var(--accent); color:var(--accent-text); }
.stepper { display:flex; align-items:center; gap:8px; background:var(--surface); border:1px solid var(--border); border-radius:9px; padding:2px; }
.stepper button { border:none; background:transparent; color:var(--text); width:30px; height:26px; border-radius:7px; font-weight:600; }
.stepper button:hover { background:color-mix(in srgb,var(--text) 8%,transparent); }
.stepper .readout { min-width:22px; text-align:center; color:var(--text); }
.link-btn { background:none; border:none; color:var(--accent); font-size:13px; padding:14px 0 0; }
.link-btn:hover { text-decoration:underline; }

.toc-list { padding:8px 8px 24px; overflow:auto; display:flex; flex-direction:column; }
.toc-item { display:block; text-align:left; background:none; border:none; padding:7px 10px 7px 12px; font-size:14px; color:var(--muted); border-left:2px solid transparent; border-radius:0 7px 7px 0; transition:color .15s, background-color .15s; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.toc-item:hover { color:var(--text); background:var(--surface); }
.toc-item.lvl2 { padding-left:24px; font-size:13.5px; }
.toc-item.lvl3 { padding-left:36px; font-size:13px; color:var(--faint); }
.toc-item.active { color:var(--accent); font-weight:600; border-left-color:var(--accent); }

.modal { position:fixed; inset:0; z-index:42; display:grid; place-items:center; padding:24px; background:var(--scrim); animation:fade .18s ease; }
.modal-card { width:min(520px,100%); background:var(--surface2); border:1px solid var(--border); border-radius:16px; box-shadow:var(--shadow); overflow:hidden; animation:popIn .2s var(--ease-out); }
.help-grid { display:grid; grid-template-columns:auto 1fr; gap:10px 16px; padding:18px 20px 22px; align-items:center; font-size:14px; }
.help-grid > div:nth-child(odd) { text-align:right; color:var(--muted); }
.help-grid .span2 { grid-column:1 / -1; text-align:center !important; padding-top:8px; border-top:1px solid var(--border); }
.muted { color:var(--muted); }

/* ===================== TOAST ===================== */
#toast {
  position:fixed; left:50%; bottom:96px; transform:translateX(-50%) translateY(10px); z-index:45;
  background:var(--surface2); color:var(--text); border:1px solid var(--border); border-radius:12px;
  padding:11px 16px; font-size:14px; box-shadow:var(--shadow); opacity:0; pointer-events:none;
  transition:opacity .25s, transform .25s; max-width:min(520px,90vw); display:flex; align-items:center; gap:12px;
}
#toast.show { opacity:1; transform:translateX(-50%) translateY(0); pointer-events:auto; }
#toast.error { background:var(--danger-surface); border-color:color-mix(in srgb,var(--danger) 40%,var(--border)); color:var(--danger); }
#toast button { background:none; border:none; color:var(--accent); font-weight:600; font-size:14px; white-space:nowrap; }
#toast.error button { color:var(--danger); text-decoration:underline; }

/* ===================== RESPONSIVE ===================== */
@media (max-width:900px) { #title { max-width:30vw; } .breadcrumb { display:none; } }
@media (max-width:720px) {
  #doc { padding:5vh clamp(18px,5vw,24px) 52vh; }
  #player { width:calc(100% - 24px); bottom:14px; border-radius:18px; }
  #leftRail { display:none; }
  .drawer { width:100%; max-width:100%; }
  #toast { bottom:86px; }
}
@media (max-width:768px) {
  /* bigger touch target for the scrubber on small / touch screens */
  #scrubber { height:24px; }
  #scrubber::-webkit-slider-runnable-track { height:8px; border-radius:8px; }
  #scrubber::-webkit-slider-thumb { width:18px; height:18px; margin-top:-5px; }
  #scrubber::-moz-range-track { height:8px; border-radius:8px; }
  #scrubber::-moz-range-progress { height:8px; border-radius:8px; }
  #scrubber::-moz-range-thumb { width:18px; height:18px; }
}
@media (max-width:420px) {
  .player-top .readout { display:none; }
  #speedBtn { display:none; }
}

/* ===================== REDUCED MOTION ===================== */
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { animation-duration:.001ms !important; animation-iteration-count:1 !important; transition-duration:.001ms !important; scroll-behavior:auto !important; }
  .w { transition:none; }
}
