:root {
  --bg: #07102a;
  --bg-2: #0b1736;
  --surface: #0f1d40;
  --surface-2: #16284f;
  --line: rgba(255, 255, 255, .08);
  --text: #e9eef8;
  --text-soft: #b7c1d8;
  --muted: #8592b0;
  --past: #8f9bb6;
  --accent: #27c4e3;
  --accent-2: #1596c2;
  --accent-ink: #04122b;
  --hl: rgba(39, 196, 227, .16);
  --hl-edge: rgba(39, 196, 227, .55);
  --glass: rgba(9, 18, 42, .82);
  --shadow: 0 20px 60px rgba(0, 0, 0, .45);
  --fs: 19px;
  --radius: 16px;
  --bar-h: 148px;
  --top-h: 64px;
  --side-w: 320px;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f6f3ec;
  --bg-2: #efeae0;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --line: rgba(20, 30, 60, .1);
  --text: #1a2133;
  --text-soft: #3b4560;
  --muted: #6a7390;
  --past: #7b8298;
  --accent: #0b8db3;
  --accent-2: #0a6f93;
  --accent-ink: #ffffff;
  --hl: rgba(11, 141, 179, .12);
  --hl-edge: rgba(11, 141, 179, .5);
  --glass: rgba(255, 253, 248, .86);
  --shadow: 0 18px 50px rgba(30, 40, 70, .18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- boot / shared ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(127, 140, 170, .3); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 50px; border-radius: 12px; font-weight: 600; font-size: 15px; transition: transform .12s, background .2s, box-shadow .2s; }
.btn:active { transform: scale(.985); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); box-shadow: 0 10px 30px rgba(39, 196, 227, .25); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.gsi-wrap { min-height: 46px; display: flex; justify-content: center; }
.link { color: var(--accent); font-weight: 500; padding: 6px 0; }
.link:hover { text-decoration: underline; }
.form-error { color: #ff8a8a; background: rgba(255, 80, 80, .08); border: 1px solid rgba(255, 90, 90, .25); padding: 10px 12px; border-radius: 10px; margin: 0; font-size: 14px; }
[data-theme="light"] .form-error { color: #b42318; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; grid-template-columns: 1.05fr 1fr; background:
  radial-gradient(1200px 600px at 20% 30%, rgba(39, 196, 227, .12), transparent 60%),
  radial-gradient(900px 600px at 90% 90%, rgba(21, 150, 194, .10), transparent 60%), var(--bg); }
.auth-art { display: grid; place-items: center; padding: 48px; }
.auth-cover { width: min(460px, 100%); aspect-ratio: 1; border-radius: 22px; box-shadow: 0 40px 120px rgba(39, 196, 227, .18), var(--shadow); }
.auth-card { align-self: center; width: min(460px, 100%); padding: 48px 32px; display: flex; flex-direction: column; gap: 16px; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 600; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.auth-card h1 { margin: 0; font: 700 clamp(30px, 4vw, 40px)/1.08 Inter, sans-serif; letter-spacing: -.02em; }
.lede { margin: 0 0 6px; color: var(--text-soft); font-size: 16px; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text-soft); background: var(--surface); border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; cursor: pointer; }
.consent input { margin-top: 3px; accent-color: var(--accent); width: 17px; height: 17px; flex: none; }
.consent em { color: var(--muted); font-style: normal; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { height: 38px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--surface-2); color: var(--text); }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 0 14px; font: 15px Inter, sans-serif; transition: border .2s, box-shadow .2s; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--hl); }
.auth[data-mode="signin"] [data-only="signup"], .auth[data-mode="signup"] [data-only="signin"] { display: none; }
.fineprint { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.55; }

.centered { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.panel { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.panel h2 { margin: 0; font-size: 24px; }
.panel p { margin: 0; color: var(--text-soft); }
.icon-badge { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: var(--hl); color: var(--accent); }
.row-links { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; }

/* ---------- player layout ---------- */
.player-app { height: 100%; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 5; padding-top: env(safe-area-inset-top); height: calc(var(--top-h) + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.brand-cover { width: 38px; height: 38px; border-radius: 8px; flex: none; }
.top-actions, .topbar > .icon-btn { flex: none; }
.brand-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--text-soft); transition: background .15s, color .15s; position: relative; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-weight: 700; font-size: 14px; margin-left: 6px; overflow: hidden; background-size: cover; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 46px; width: 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; z-index: 30; }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle { display: flex; gap: 10px; align-items: center; padding: 10px; font-size: 14px; color: var(--text-soft); cursor: pointer; }
.menu-toggle input { accent-color: var(--accent); }
.menu-item { width: 100%; text-align: left; padding: 10px; border-radius: 10px; font-size: 14px; }
.menu-item:hover { background: var(--surface-2); }

.sidebar { grid-row: 2; border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 12px calc(var(--bar-h) + 16px); background: var(--bg-2); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 10px; font-weight: 700; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.overall { display: flex; align-items: center; gap: 10px; padding: 0 10px 14px; font-size: 12.5px; color: var(--muted); }
.overall-bar { flex: 1; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.overall-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.chapter-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.chapter { display: grid; grid-template-columns: 34px 1fr auto; gap: 4px 10px; align-items: center; width: 100%; text-align: left; padding: 10px; border-radius: 12px; transition: background .15s; }
.chapter:hover { background: var(--surface); }
.chapter.current { background: var(--surface-2); }
.ch-num { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; background: var(--surface); color: var(--muted); }
.chapter.current .ch-num { background: var(--accent); color: var(--accent-ink); }
.chapter.done .ch-num { color: var(--accent); }
.ch-label { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .03em; }
.ch-title { font-size: 14px; font-weight: 500; line-height: 1.3; }
.ch-dur { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-prog { grid-column: 2 / -1; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.ch-prog span { display: block; height: 100%; background: var(--accent); opacity: .75; }
.eq { display: none; gap: 2px; align-items: flex-end; height: 14px; }
.chapter.current.playing .eq { display: inline-flex; }
.chapter.current.playing .ch-n { display: none; }
.eq i { width: 3px; background: currentColor; border-radius: 2px; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s; } .eq i:nth-child(3) { animation-delay: -.6s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 14px; } }

.reader { grid-row: 2; overflow-y: auto; scroll-behavior: smooth; padding: 40px 24px calc(var(--bar-h) + 60px); outline: none; }
.text { max-width: 680px; margin: 0 auto; font-family: Literata, Georgia, "Times New Roman", serif; font-size: var(--fs); line-height: 1.72; color: var(--text); }
.text .ch-head { margin: 10px 0 36px; }
.text .ch-head .k { font: 600 12px/1 Inter, sans-serif; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); margin-bottom: 14px; }
.text .ch-head h1 { font: 600 clamp(28px, 4.2vw, 38px)/1.15 Literata, Georgia, serif; margin: 0; letter-spacing: -.01em; }
.text h2 { font: 700 1.02em/1.35 Inter, sans-serif; margin: 2.1em 0 .7em; letter-spacing: -.005em; }
.text h3 { font-size: 1em; font-style: italic; font-weight: 600; margin: 1.6em 0 .5em; }
.text p { margin: 0 0 1.05em; }
.text p.line { margin: 0; }
.text p.line.last { margin-bottom: 1.05em; }
.text blockquote { margin: 1.2em 0; padding-left: 18px; border-left: 3px solid var(--hl-edge); font-style: italic; color: var(--text-soft); }
.text ul { margin: 0 0 1.1em; padding-left: 1.3em; }
.text li { margin: 0 0 .45em; }
.text .row { font: 14px/1.5 Inter, sans-serif; padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--text-soft); background: var(--surface); }
.text .row.head { font-weight: 700; color: var(--text); border-radius: 10px 10px 0 0; margin-top: 1em; }
.text .row + p, .text .row + h2 { margin-top: 1.1em; }
.text hr { border: 0; text-align: center; margin: 1.8em 0; color: var(--muted); }
.text hr::after { content: "• • •"; letter-spacing: .5em; }
.seg { border-radius: 5px; transition: background-color .25s, color .25s, box-shadow .25s; box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: 1px 1px; }
.seg.spoken { cursor: pointer; }
.seg.spoken:hover { background: var(--hl); }
.seg.past { color: var(--past); }
.seg.active { background: var(--hl); color: var(--text); box-shadow: 0 0 0 2px var(--hl); }
.text-only { color: var(--muted); }
.text-only-note { display: inline-flex; align-items: center; gap: 8px; font: 600 11.5px/1 Inter, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 7px 12px; margin: 6px 0 16px; }
.chapter-end { margin: 3em 0 0; display: flex; justify-content: center; }
.chapter-end button { display: inline-flex; gap: 8px; align-items: center; padding: 12px 18px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font: 600 14px Inter, sans-serif; }

.follow-pill { position: fixed; left: 50%; transform: translateX(calc(-50% + var(--side-w) / 2)); bottom: calc(var(--bar-h) + 18px); z-index: 12; display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.follow-pill svg { width: 18px; height: 18px; }

/* ---------- player bar ---------- */
.playerbar { position: fixed; left: var(--side-w); right: 0; bottom: 0; z-index: 10; background: var(--glass); -webkit-backdrop-filter: saturate(160%) blur(18px); backdrop-filter: saturate(160%) blur(18px); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr auto 1fr; grid-template-areas: "now controls ." "scrub scrub scrub"; gap: 6px 18px; align-items: center; padding: 14px 24px calc(14px + env(safe-area-inset-bottom)); }
.now { grid-area: now; min-width: 0; }
.now-label { font-size: 11.5px; font-weight: 600; color: var(--accent); letter-spacing: .08em; text-transform: uppercase; }
.now-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { grid-area: controls; display: flex; align-items: center; gap: 8px; }
.scrub { grid-area: scrub; display: flex; align-items: center; gap: 12px; max-width: 900px; width: 100%; margin: 0 auto; }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; }
.time:last-child { text-align: right; }
.play { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); box-shadow: 0 10px 28px rgba(39, 196, 227, .35); transition: transform .12s; }
.play:active { transform: scale(.94); }
.play svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.play .i-pause, .play .i-load { display: none; }
.play.is-playing .i-play { display: none; }
.play.is-playing .i-pause { display: block; }
.play.is-loading svg { display: none; }
.play.is-loading .i-load { display: inline-block; border-color: rgba(4, 18, 43, .25); border-top-color: var(--accent-ink); }
.skip span { position: absolute; font-size: 9px; font-weight: 700; top: 50%; left: 50%; transform: translate(-50%, -40%); }
.skip svg { width: 26px; height: 26px; }
.pill-btn { height: 34px; min-width: 50px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--text-soft); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-variant-numeric: tabular-nums; }
.pill-btn svg { width: 17px; height: 17px; }
.pill-btn.on { color: var(--accent); border-color: var(--hl-edge); }

input[type="range"] { -webkit-appearance: none; appearance: none; flex: 1; height: 22px; background: transparent; cursor: pointer; --p: 0%; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 5px; background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p)); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 5px; background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: #fff; margin-top: -5px; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }

.toast { position: fixed; left: 50%; transform: translateX(calc(-50% + var(--side-w) / 2)); bottom: calc(var(--bar-h) + 70px); z-index: 20; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; max-width: min(520px, 90vw); text-align: center; }

.menu-wa { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.menu-wa-value { color: var(--accent); font-size: 13px; font-weight: 600; }

.optin { position: fixed; z-index: 22; right: 24px; bottom: calc(var(--bar-h) + 18px); width: min(420px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 22px 22px 18px;
  animation: optin-in .35s cubic-bezier(.2, .8, .2, 1); }
@keyframes optin-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.optin-close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; }
.optin-close svg { width: 18px; height: 18px; }
.optin h3 { margin: 0 34px 6px 0; font-size: 19px; line-height: 1.25; }
.optin-kicker { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.optin-sub { margin: 0 0 14px; color: var(--text-soft); font-size: 14px; line-height: 1.5; }
.optin-row { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; color: var(--text-soft); cursor: pointer; margin-bottom: 10px; }
.optin-row input { accent-color: var(--accent); width: 17px; height: 17px; margin-top: 2px; flex: none; }
.optin-row strong { color: var(--text); word-break: break-all; }
.optin-wa { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.optin-wa-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.optin-wa-label svg { width: 18px; height: 18px; color: #25d366; }
.optin-wa-label em { color: var(--muted); font-style: normal; font-weight: 400; }
.optin-wa input { width: 100%; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); padding: 0 12px; font: 16px Inter, sans-serif; }
.optin-wa input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--hl); }
.optin-wa input.bad { border-color: #ff8a8a; }
.optin-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); min-height: 1.2em; }
.optin-hint.ok { color: #3ddc97; }
.optin-hint.bad { color: #ff8a8a; }
.optin-actions { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.optin-actions .btn { flex: 1; height: 46px; }
.optin-fine { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.optin-done { text-align: center; padding: 8px 0 4px; }
.optin-done h3 { margin: 12px 0 6px; }

.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 25; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  :root { --side-w: 0px; --bar-h: 176px; --fs: 18px; }
  .player-app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(88vw, 360px); z-index: 30; transform: translateX(-102%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: 24px; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .reader { grid-row: 2; padding: 28px 20px calc(var(--bar-h) + 70px); }
  .playerbar { left: 0; grid-template-columns: 1fr; grid-template-areas: "now" "scrub" "controls"; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); gap: 4px; }
  .now { text-align: center; }
  .controls { justify-content: space-between; width: 100%; max-width: 440px; margin: 0 auto; gap: 0; min-width: 0; }
  .controls .icon-btn { width: 40px; flex: none; }
  .controls .pill-btn { min-width: 46px; padding: 0 8px; flex: none; }
  .brand-title { font-size: 14px; }
  .topbar { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .top-actions .icon-btn { width: 38px; }
  .optin { left: 12px; right: 12px; width: auto; bottom: calc(var(--bar-h) + 10px); max-height: calc(100vh - var(--bar-h) - 90px); overflow-y: auto; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 32px 24px 0; }
  .auth-cover { width: min(260px, 70vw); }
  .auth-card { margin: 0 auto; padding: 24px 22px 40px; }
}
@media (max-width: 360px) {
  .controls .icon-btn { width: 34px; }
  .controls .pill-btn { min-width: 40px; padding: 0 6px; }
  .play { width: 52px; height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
