:root {
  --paper: #FFFFFF;
  --band: #EEF3FC;
  --soft: #F6F8FB;
  --surface: #FFFFFF;
  --ink: #1F2633;
  --muted: #5B6475;
  --line: #DDE2EA;
  --blue: #1A5FD6;
  --blue-dark: #134BAE;
  --blue-pale: #E6EEFC;
  --on-blue: #FFFFFF;
  --navy: #0D1B3A;
  --gem: #1F9D5C;
  --gem-hi: #47C285;
  --facet-off: #E4E8EF;
  --stage: #0B1222;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --shadow-hi: 0 4px 18px rgba(16, 24, 40, .14);
  --display: "Lato", "Segoe UI", Arial, sans-serif;
  --body: "Lato", "Segoe UI", Arial, sans-serif;
  --r-lg: 10px;
  --r-sm: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1729; --band: #15213B; --soft: #131D33; --surface: #172036; --ink: #E8ECF4; --muted: #A3ADC2; --line: #2A3550;
    --blue: #6E9DFF; --blue-dark: #8DB2FF; --blue-pale: #1E2D4F; --on-blue: #0B1222; --navy: #E8ECF4;
    --gem: #3FBF7F; --gem-hi: #6FD9A2; --facet-off: #26324D; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0F1729; --band: #15213B; --soft: #131D33; --surface: #172036; --ink: #E8ECF4; --muted: #A3ADC2; --line: #2A3550;
  --blue: #6E9DFF; --blue-dark: #8DB2FF; --blue-pale: #1E2D4F; --on-blue: #0B1222; --navy: #E8ECF4;
  --gem: #3FBF7F; --gem-hi: #6FD9A2; --facet-off: #26324D; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--body);
  min-height: 100vh; display: flex; flex-direction: column; overflow-x: clip;
}
a { color: var(--blue); text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
h1, h2 { font-family: var(--display); font-weight: 900; letter-spacing: -0.01em; line-height: 1.15; margin: 0; color: var(--navy); }
h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; }
.small { font-size: .88rem; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 20px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .05);
}
.top-left { display: flex; align-items: center; gap: 22px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); font-family: var(--display); font-weight: 900; font-size: 1.15rem; }
.brand img { border-radius: 8px; }
.brand-light { font-weight: 400; color: var(--muted); }
.top-nav { display: flex; gap: 4px; }
.top-nav a { color: var(--ink); text-decoration: none; font-weight: 700; font-size: .95rem; padding: 8px 10px; border-radius: var(--r-sm); }
.top-nav a:hover { background: var(--blue-pale); color: var(--blue); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.pill { font-size: .82rem; font-weight: 700; padding: 6px 12px; border-radius: 999px; background: var(--blue-pale); color: var(--blue); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill[data-mode="locked"] { background: #FDEBD3; color: #7A4300; }
.pill[data-mode="continued"] { background: #E3F5EC; color: #146B40; }
.pill[data-mode="full"] { background: var(--gem); color: #FFFFFF; }
/* phones: the menu gets its own row under the logo */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; }
  .top-left { display: contents; }
  .top-nav { order: 3; width: 100%; flex-wrap: wrap; }
  .top-nav a { font-size: .9rem; padding: 6px 8px; white-space: nowrap; }
}
@media (max-width: 560px) { .brand-light { display: none; } .topbar { padding-inline: 14px; } }
@media (max-width: 480px) { .brand > span { display: none; } .pill { font-size: .78rem; } }
.top-actions .btn { white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 1rem/1 var(--body); padding: 13px 20px; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--blue); color: var(--on-blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-quiet { background: var(--surface); color: var(--blue); border-color: var(--line); }
.btn-quiet:hover { background: var(--blue-pale); border-color: var(--blue); }
.btn-sm { padding: 8px 14px; font-size: .88rem; }
.btn-wide { width: 100%; }

/* ---------- layout ---------- */
main:focus, main:focus-visible { outline: none; }
main { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 20px 56px; outline: none; }
.block { margin-top: 44px; }
.block > h2 { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.crumbs { margin: 20px 0 8px; font-size: .9rem; color: var(--muted); }
.crumbs a { color: var(--blue); text-decoration: none; font-weight: 700; }
.crumbs a:hover { text-decoration: underline; }
.page-head { margin: 8px 0 8px; }
.page-head h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
.page-head p { color: var(--muted); margin: 8px 0 0; max-width: 60ch; font-size: 1.05rem; }
.page-head-tight { margin-bottom: 18px; }
.empty-line { color: var(--muted); }

/* ---------- hero (full-width band) ---------- */
.hero {
  margin: 0 calc(50% - 50vw); padding: 56px calc(50vw - 50%) 52px;
  background: var(--band); border-bottom: 1px solid var(--line); text-align: center;
}
.hero h1 { font-size: clamp(2rem, 5.4vw, 3.2rem); max-width: 22ch; margin: 0 auto; }
.hero-sub { font-size: 1.15rem; color: var(--muted); margin: 14px auto 28px; max-width: 54ch; }
.search { display: flex; gap: 8px; max-width: 620px; margin: 0 auto; }
.search input {
  flex: 1; min-width: 0; font: 1.05rem var(--body); color: var(--ink);
  padding: 14px 18px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow);
}
.search input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-pale); }

/* ---------- subjects (colour-coded tiles) ---------- */
.subjects { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.subjects li { --c: var(--blue); }
.subjects li:nth-child(8n+1) { --c: #1A5FD6; }
.subjects li:nth-child(8n+2) { --c: #1F9D5C; }
.subjects li:nth-child(8n+3) { --c: #7B3FD0; }
.subjects li:nth-child(8n+4) { --c: #D9480F; }
.subjects li:nth-child(8n+5) { --c: #0E8A9C; }
.subjects li:nth-child(8n+6) { --c: #C2255C; }
.subjects li:nth-child(8n+7) { --c: #B7791F; }
.subjects li:nth-child(8n+8) { --c: #3B5BDB; }
.subjects a {
  display: grid; gap: 4px; height: 100%; padding: 16px 18px 16px 20px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--r-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.subjects a:hover { box-shadow: var(--shadow-hi); transform: translateY(-1px); }
.subjects a:hover .subj-name { color: var(--c); }
.subj-name { font-family: var(--display); font-weight: 900; font-size: 1.12rem; color: var(--navy); }
.subj-about { color: var(--muted); font-size: .93rem; }
.subj-count { font-size: .84rem; font-weight: 700; color: var(--c); margin-top: 6px; }

/* ---------- lessons ---------- */
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px 18px; }
.lesson {
  text-decoration: none; color: var(--ink); display: grid; gap: 4px; align-content: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
  padding-bottom: 12px; transition: box-shadow .15s ease;
}
.lesson:hover { box-shadow: var(--shadow-hi); }
.lesson > .lesson-title, .lesson > .lesson-meta { padding: 0 14px; }
.lesson > .thumb { margin-bottom: 8px; border-radius: 0; }
.thumb { position: relative; aspect-ratio: 16/9; border-radius: var(--r-sm); overflow: hidden; background: var(--blue-pale); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-blank { font-family: var(--display); font-weight: 900; font-size: 2.6rem; color: var(--blue); }
.thumb-play { position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; border-radius: 50%; background: var(--blue); box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.thumb-play::after { content: ""; position: absolute; left: 13px; top: 10px; border-left: 11px solid #FFFFFF; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.lesson-title { font-weight: 700; line-height: 1.3; color: var(--navy); }
.lesson:hover .lesson-title { color: var(--blue); }
.lesson-meta { font-size: .85rem; color: var(--muted); }
.lessons-stack { grid-template-columns: 1fr; gap: 10px; }
.lessons-stack .lesson { grid-template-columns: 140px 1fr; column-gap: 12px; padding: 8px; border-radius: var(--r-sm); }
.lessons-stack .lesson > .thumb { grid-row: span 2; margin: 0; border-radius: 4px; }
.lessons-stack .lesson > .lesson-title, .lessons-stack .lesson > .lesson-meta { padding: 0; }
.lessons-stack .thumb-blank { font-size: 1.6rem; }
.lessons-stack .thumb-play { width: 26px; height: 26px; right: 6px; bottom: 6px; }
.lessons-stack .thumb-play::after { left: 10px; top: 7px; border-left-width: 9px; border-top-width: 6px; border-bottom-width: 6px; }

/* ---------- books ---------- */
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.book { display: flex; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; transition: box-shadow .15s ease; }
.book-spine { width: 10px; background: var(--blue); flex: none; }
.book-body { padding: 14px 16px; display: grid; gap: 2px; }
.book-title { font-weight: 900; color: var(--navy); }
.book-meta { font-size: .88rem; color: var(--muted); }
.book-state { font-size: .86rem; color: var(--blue); margin-top: 6px; font-weight: 700; }
.book:hover { box-shadow: var(--shadow-hi); }
.book:hover .book-title { color: var(--blue); }

/* ---------- watch page ---------- */
.watch { display: grid; gap: 28px; margin-top: 10px; }
@media (min-width: 900px) { .watch { grid-template-columns: minmax(0, 1fr) 340px; } }
.watch-title { font-size: clamp(1.4rem, 3vw, 1.85rem); margin-top: 18px; }
.watch-meta { color: var(--muted); margin: 6px 0 0; }
.watch-meta a { font-weight: 700; text-decoration: none; }
.watch-side { background: var(--soft); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; align-self: start; }
.watch-side h2 { font-size: 1.05rem; margin-bottom: 12px; }

/* ---------- player ---------- */
.player { background: var(--stage); border-radius: var(--r-lg); overflow: hidden; outline: none; user-select: none; -webkit-user-select: none; }
.player:fullscreen { border-radius: 0; display: flex; flex-direction: column; justify-content: center; }
.player-stage { position: relative; aspect-ratio: 16/9; background: #000; }
.player:fullscreen .player-stage { aspect-ratio: auto; flex: 1; }
.player-frame, .player-frame iframe, #yt-target { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-shield { position: absolute; inset: 0; background: transparent; border: 0; cursor: pointer; z-index: 2; }
.player-cover, .player-end, .player-missing {
  position: absolute; inset: 0; z-index: 3; display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 20px; text-align: center; color: #F2F5FA;
  background: rgba(11, 18, 34, .84);
}
.player-cover.is-start { background: linear-gradient(160deg, #1A3D8F, #0B1222); }
.player-cover[hidden], .player-end[hidden] { display: none; }
.big-play { width: 76px; height: 76px; border-radius: 50%; border: 0; background: #FFFFFF; cursor: pointer; display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.big-play svg { width: 34px; height: 34px; fill: #1A5FD6; margin-left: 4px; }
.cover-title { font-family: var(--display); font-weight: 700; font-size: clamp(1rem, 2.4vw, 1.35rem); margin: 0; max-width: 34ch; }
.end-label { font-family: var(--display); font-weight: 900; font-size: 1.4rem; margin: 0; }
.end-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.player-end .btn-primary { background: #1A5FD6; color: #FFFFFF; }
.player-end .btn-quiet { background: transparent; color: #F2F5FA; border-color: rgba(255,255,255,.3); }
.player-missing p { margin: 0; }
.player-missing code { background: rgba(255,255,255,.12); padding: 1px 6px; border-radius: 4px; }
.player-missing .small { color: #B8C2D6; }
.player-bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--stage); color: #E8ECF4; }
.pbtn { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; font-size: 1.3rem; }
.pbtn:hover { background: rgba(255,255,255,.1); }
.pbtn svg { width: 24px; height: 24px; fill: currentColor; }
.ptime { font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pseek { flex: 1; min-width: 60px; accent-color: #6E9DFF; }
.pspeed { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.25); border-radius: 6px; padding: 4px; font: .82rem var(--body); }
.pspeed option { color: #1F2633; }
.yt-credit { margin: 0; padding: 0 12px 8px; font-size: .72rem; color: #8F9AB0; background: var(--stage); text-align: right; }
@media (max-width: 520px) { .pspeed, [data-act="back"] { display: none; } .ptime { font-size: .76rem; } }

/* ---------- reader ---------- */
.reader { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.reader-tools { position: sticky; top: 56px; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 8px 0; background: var(--paper); border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.reader-page { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.reader-zoom { display: flex; gap: 4px; }
.reader-zoom .pbtn { color: var(--blue); border: 1px solid var(--line); background: var(--surface); }
.reader-zoom .pbtn:hover { background: var(--blue-pale); }
.reader-pages { display: grid; justify-items: center; gap: 18px; overflow-x: auto; padding: 4px 0; background: var(--soft); border-radius: var(--r-sm); }
.page-slot { position: relative; background: #fff; box-shadow: 0 1px 0 var(--line), 0 6px 24px -12px rgba(16, 24, 40, .35); width: max-content; max-width: none; min-width: min(100%, 300px); }
.page-slot canvas { display: block; pointer-events: none; }
.page-wm { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-28deg); font: 900 clamp(14px, 3vw, 26px) var(--display); color: rgba(26, 95, 214, .08); white-space: nowrap; pointer-events: none; }
.page-no { position: absolute; right: 10px; bottom: 6px; font-size: .75rem; color: #8A93A6; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty p { margin: 0; }

/* ---------- gate dialog ---------- */
#gate {
  border: 0; padding: 0; border-radius: 12px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
}
#gate::backdrop { background: rgba(13, 27, 58, .62); backdrop-filter: blur(4px); }
.gate-inner { position: relative; padding: 28px 24px 24px; text-align: center; }
.gate-inner h2 { font-size: 1.45rem; font-weight: 900; margin: 14px 0 8px; }
.gate-inner p { margin: 0 0 10px; color: var(--muted); }
.gate-inner p strong { color: var(--ink); }
.gate-progress { font-variant-numeric: tabular-nums; }
.gate-note { font-size: .88rem; margin-top: 16px !important; }
.gate-close { position: absolute; right: 10px; top: 8px; width: 40px; height: 40px; border: 0; background: transparent; font-size: 1.6rem; color: var(--muted); cursor: pointer; border-radius: 8px; }
.gate-close:hover { background: var(--soft); }
.gem { width: 132px; height: 132px; display: block; margin: 0 auto; }
.facet { fill: var(--facet-off); stroke: var(--surface); stroke-width: 1.4; stroke-linejoin: round; transition: fill .35s ease; }
.facet.on { fill: var(--gem); }
.facet.on.alt { fill: var(--gem-hi); }
.gem-core { fill: var(--surface); }
.gem-num { font: 900 20px var(--display); fill: var(--navy); }
.share-or { font-size: .86rem; margin: 14px 0 8px !important; }
.share-links { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.share-link { font: 700 .9rem var(--body); padding: 9px 13px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--blue); text-decoration: none; cursor: pointer; }
.share-link:hover { border-color: var(--blue); background: var(--blue-pale); }
body.is-gated main { filter: blur(3px); pointer-events: none; }
.ask { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.ask-q { font-size: 1.05rem; margin-bottom: 4px !important; }
.ask-row { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 12px 0 14px; }
.ask-step { width: 44px; height: 44px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--blue); font: 900 1.4rem var(--body); cursor: pointer; }
.ask-step:hover { border-color: var(--blue); background: var(--blue-pale); }
.ask-num { width: 84px; height: 44px; text-align: center; font: 900 1.3rem var(--display); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); font-variant-numeric: tabular-nums; }
.ask-num:focus { border-color: var(--blue); }

/* ---------- ads ---------- */
.ad-slot { margin: 36px 0; padding-top: 6px; border-top: 1px solid var(--line); }
.ad-label { display: block; font-size: .72rem; color: var(--muted); margin-bottom: 6px; }

/* ---------- prose / footer / toast ---------- */
.prose { max-width: 68ch; }
.prose h2 { margin-top: 28px; }
.foot { background: var(--soft); border-top: 1px solid var(--line); padding: 26px 16px calc(26px + env(safe-area-inset-bottom)); text-align: center; font-size: .88rem; color: var(--muted); }
.foot p { margin: 4px 0; }
.foot a { font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: var(--navy); color: var(--paper); padding: 12px 18px; border-radius: 8px; font-size: .95rem; width: max-content; max-width: calc(100vw - 32px); box-shadow: var(--shadow-hi); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { body { display: none !important; } }

/* ---------- embedded ebook links ---------- */
.embed-frame { position: relative; height: min(82vh, 1100px); min-height: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.embed-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.embed-shield { position: absolute; top: 0; right: 0; width: 72px; height: 64px; background: transparent; z-index: 2; }
.embed-frame .page-wm { z-index: 1; }

/* ---------- courses ---------- */
.course-list { max-width: 820px; list-style: none; margin: 0; padding: 0; counter-reset: lesson; display: grid; gap: 4px; }
.course-list a { display: grid; grid-template-columns: 2.2em 120px 1fr; gap: 12px; align-items: center; padding: 8px; border-radius: var(--r-sm); text-decoration: none; color: var(--ink); border: 1px solid transparent; }
.course-list a:hover { background: var(--blue-pale); }
.course-list a[aria-current="true"] { background: var(--blue-pale); border-color: var(--blue); }
.course-list .num { font: 900 1rem var(--display); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.course-list a[aria-current="true"] .num { color: var(--blue); }
.course-list .thumb { aspect-ratio: 16/9; }
.course-list .t { font-weight: 700; line-height: 1.3; color: var(--navy); }
.course-list .t.is-loading { color: var(--muted); font-weight: 400; }
.watch-side .course-list a { grid-template-columns: 1.8em 96px 1fr; gap: 10px; }
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.course-card {
  display: grid; gap: 4px; padding: 18px 20px; border-radius: var(--r-sm); text-decoration: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-top: 4px solid var(--blue);
  transition: box-shadow .15s ease;
}
.course-card .cc-title { font: 900 1.12rem/1.25 var(--display); color: var(--navy); }
.course-card .cc-meta { font-size: .88rem; color: var(--muted); }
.course-card:hover { box-shadow: var(--shadow-hi); }
.course-card:hover .cc-title { color: var(--blue); }
.course-group { border-top-color: var(--gem); background: var(--band); }
.jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; }
.jump-btn { font: 700 .88rem var(--body); padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--blue); cursor: pointer; }
.jump-btn span { color: var(--muted); font-weight: 400; margin-left: 2px; }
.jump-btn:hover { border-color: var(--blue); background: var(--blue-pale); }
[id^="sec-"] { scroll-margin-top: 72px; }
.gate-later { margin-top: 12px; }
