/* ============================================================
   GEOFFREY HINTON LITERATURE — STYLESHEET  (theme: "Energy landscape")
   ------------------------------------------------------------
   Same class names as before: drop-in replacement for the old
   styles.css. index.html, engine.js and content.js are unchanged.

   Palette
     ink    — deep indigo night (topbar, header, tables, footer)
     violet — interaction: links, active states, focus, buttons
     gold   — Nobel moments only: portrait ring, badge, key results
     moss   — success / completed
     paper  — cool lavender-grey page and rails

   Legacy token names (--navy, --purple-dark, --green-dark …) are
   kept as aliases because engine.js sets a few colours inline
   through them and content.js uses them in the callout legend.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Literata:opsz,wght@7..72,400;7..72,500;7..72,600;7..72,700&display=swap');

:root {
  /* ── Core palette ── */
  --ink:          #17122e;
  --ink-80:       #211a40;
  --ink-70:       #2b2352;
  --ink-60:       #5d5877;
  --ink-40:       #908ba8;
  --text:         #2a2640;
  --white:        #ffffff;
  --paper:        #f6f5fa;
  --line:         #e3e0ee;
  --line-2:       #cfcadf;

  --violet:       #5b3fd1;
  --violet-dark:  #4529b3;
  --violet-tint:  #efebff;
  --violet-soft:  #cdc2fb;

  --gold:         #c9a227;
  --gold-bright:  #e8c34f;
  --gold-soft:    #f6e8b8;
  --gold-dark:    #5e4708;

  --moss:         #2e7d5b;
  --moss-light:   #a8d9bf;
  --moss-tint:    #e6f4ec;

  --red:          #c2362f;
  --red-bg:       #fdecec;

  /* ── Legacy aliases (used by engine.js / content.js) ── */
  --navy:              var(--ink);
  --navy-80:           var(--ink-80);
  --navy-70:           var(--ink-70);
  --navy-60:           var(--ink-60);
  --navbar-background: var(--ink-70);
  --off-white:         var(--paper);
  --gray-10:           var(--line);
  --gray-20:           var(--line-2);
  --purple-light:      var(--violet-soft);
  --purple-dark:       var(--violet);
  --yellow-light:      var(--gold-bright);
  --yellow-dark:       var(--gold-dark);
  --blue-light:        var(--violet-soft);
  --blue-dark:         var(--violet-dark);
  --green-light:       var(--moss-light);
  --green-dark:        var(--moss);

  /* ── Callout tokens ── */
  --new-concept-bg:          var(--violet-dark);
  --repeating-concept-bg:    var(--violet-tint);
  --repeating-concept-label: var(--violet-dark);
  --repeating-concept-text:  var(--text);
  --caution-bg:              var(--gold-dark);
  --best-practice-bg:        var(--moss);
  --common-error-bg:         var(--gold-soft);
  --try-it-bg:               var(--moss-light);
  --deep-dive-bg:            var(--violet-tint);
  --critical-bg:             var(--ink-70);

  /* ── Layout ── */
  --sidebar-w:  272px;
  --toc-w:      248px;
  --header-h:   58px;
  --topbar-h:   auto;
  --radius:     10px;
  --radius-sm:  6px;
  --radius-lg:  16px;
  --shadow-sm:  0 1px 3px rgba(23,18,46,.08);
  --shadow-md:  0 8px 24px rgba(23,18,46,.14);
  --transition: .2s ease;

  /* ── Type ── */
  --font-read: 'Literata', Georgia, 'Times New Roman', serif;
  --font-body: 'Instrument Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  overflow-x: hidden;
}
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
::selection { background: var(--violet-soft); color: var(--ink); }

/* ── TOP BRAND STRIP ── */
.topbar {
  position: relative;
  text-align: center;
  padding: 28px 20px 22px;
  background:
    radial-gradient(ellipse 60% 120% at 50% 0%, rgba(91,63,209,.28), transparent 70%),
    var(--ink);
  border-bottom: 1px solid rgba(201,162,39,.55);
}
.topbar-brand {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  color: var(--white); text-decoration: none;
  font-family: var(--font-read); font-weight: 600; font-size: 31px; letter-spacing: -.01em;
}
.topbar-brand img { height: 44px; width: auto; display: block; }
.topbar-brand .topbar-portrait {
  position: relative; display: block; overflow: hidden; flex-shrink: 0;
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--white);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 2px var(--gold), 0 10px 26px rgba(0,0,0,.45);
}
/* same crop as before so the face fills the circle */
.topbar-brand .topbar-portrait img {
  position: absolute; left: -26%; top: -20%;
  width: 170%; height: auto; max-width: none; display: block;
}
.topbar-brand-text { min-width: 0; }

.disclaimer-btn {
  display: inline-block; margin-top: 14px;
  padding: 5px 16px; border-radius: 20px;
  background: transparent; border: 1px solid rgba(255,255,255,.26);
  color: rgba(255,255,255,.8);
  font-family: var(--font-body); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.disclaimer-btn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.45); color: var(--white); }

@media (max-width: 720px) {
  .topbar-brand { gap: 12px; font-size: 21px; }
  .topbar-brand .topbar-portrait { width: 58px; height: 58px; box-shadow: 0 0 0 2px var(--gold), 0 4px 12px rgba(0,0,0,.4); }
}
@media (max-width: 380px) {
  .topbar-brand { font-size: 18px; }
  .topbar-brand .topbar-portrait { width: 48px; height: 48px; }
}

/* ── DISCLAIMER MODAL ── */
.disclaimer-overlay {
  display: none; position: fixed; inset: 0; z-index: 2000;
  background: rgba(23,18,46,.64);
  align-items: center; justify-content: center; padding: 20px;
}
.disclaimer-overlay.open { display: flex; }
.disclaimer-modal {
  position: relative; background: var(--white);
  border-radius: var(--radius-lg); max-width: 500px; width: 100%;
  padding: 30px 28px 26px;
  border-top: 4px solid var(--gold);
  box-shadow: 0 18px 48px rgba(23,18,46,.38);
}
.disclaimer-title {
  font-family: var(--font-read); font-size: 22px; font-weight: 600;
  color: var(--ink); margin-bottom: 12px;
}
.disclaimer-text { font-size: 14px; line-height: 1.75; color: var(--text); margin-bottom: 12px; }
.disclaimer-text:last-of-type { margin-bottom: 0; }
.disclaimer-text strong { color: var(--ink); font-weight: 700; }
.disclaimer-close {
  position: absolute; top: 14px; right: 14px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-60);
  font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.disclaimer-close:hover { background: var(--line); color: var(--ink); }

/* ── NAV BAR (now sticky, so both side rails line up under it) ── */
.navbar {
  position: sticky; top: 0; z-index: 1000;
  height: var(--header-h);
  background: var(--navbar-background);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(23,18,46,.3);
}
.navbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.navbar-brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--white); font-weight: 600; font-size: 15px; text-decoration: none;
}
.navbar-badge {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: var(--gold-bright);
  border: 1.5px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-read); font-weight: 600; font-size: 13.5px;
}
.navbar-links, .navbar-left-links { display: flex; align-items: center; gap: 6px; }
.navbar-left-links:empty { display: none; }
.navbar-btn {
  padding: 6px 13px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.84); font-family: var(--font-body); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
a.navbar-btn { text-decoration: none; }
.navbar-btn:hover { background: rgba(255,255,255,.1); color: var(--white); }
.navbar-btn:focus-visible { outline-color: var(--gold-bright); }
.navbar-btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 600; }
.navbar-btn.primary:hover { background: var(--gold-bright); border-color: var(--gold-bright); }

.navbar-search {
  flex: 0 1 290px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15);
  border-radius: 20px; padding: 6px 8px 6px 14px;
  color: rgba(255,255,255,.62); font-size: 13px; cursor: pointer;
  transition: var(--transition);
}
.navbar-search:hover { background: rgba(255,255,255,.13); color: rgba(255,255,255,.88); }
.navbar-search:focus-visible { outline-color: var(--gold-bright); }
.search-icon { font-size: 13px; opacity: .8; }
.search-icon:empty { display: none; }
.navbar-search kbd {
  margin-left: auto; font-family: var(--font-mono); font-size: 10.5px;
  background: rgba(255,255,255,.1); padding: 2px 8px; border-radius: 12px; opacity: .85;
}

/* ── MAIN 3-COLUMN LAYOUT ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  grid-template-rows: auto;
  min-height: calc(100vh - var(--header-h));
}

/* ── LEFT SIDEBAR ── */
.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overflow-x: hidden;
  background: var(--white);
  border-right: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }

.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--white); z-index: 10;
}
.sidebar-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.progress-bar-wrap { margin-top: 8px; height: 5px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress-bar-fill {
  height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--violet), var(--gold));
  transition: width .8s ease;
}
.progress-label {
  display: flex; justify-content: space-between; margin-top: 5px;
  font-size: 11.5px; color: var(--ink-60); font-variant-numeric: tabular-nums;
}

.lesson-group { padding: 8px 0; }
.lesson-group-label { font-size: 12px; font-weight: 600; color: var(--ink-60); padding: 6px 16px 2px; }

.lesson-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 14px 9px 16px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition); text-decoration: none;
  color: inherit; position: relative;
}
.lesson-item:hover { background: var(--paper); }
.lesson-item.active { background: var(--violet-tint); border-left-color: var(--violet); }
.lesson-num {
  flex-shrink: 0; min-width: 26px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: var(--paper); color: var(--ink-60); border: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px; transition: var(--transition); font-variant-numeric: tabular-nums;
}
.lesson-item.done .lesson-num { background: var(--moss); border-color: var(--moss); color: var(--white); }
.lesson-item.active .lesson-num { background: var(--violet); border-color: var(--violet); color: var(--white); }
.lesson-info { flex: 1; min-width: 0; }
.lesson-name { font-size: 13.5px; font-weight: 500; color: var(--ink); line-height: 1.35; }
.lesson-item.active .lesson-name { color: var(--violet-dark); font-weight: 600; }
.lesson-meta { font-size: 11.5px; color: var(--ink-60); margin-top: 2px; line-height: 1.4; }
.lesson-badge { font-size: 10.5px; padding: 1px 8px; border-radius: 20px; font-weight: 600; flex-shrink: 0; margin-top: 2px; }
.badge-new  { background: var(--gold-soft); color: var(--gold-dark); }
.badge-lab  { background: var(--moss-tint); color: var(--moss); }
.badge-soon { background: var(--paper); color: var(--ink-60); border: 1px solid var(--line); font-weight: 500; }

/* ── SIDEBAR PARTS ACCORDION ── */
.parts-controls { display: flex; justify-content: flex-end; margin-top: 6px; }
.parts-toggle-all {
  background: none; border: none; padding: 2px 0; cursor: pointer;
  font-family: var(--font-body); font-size: 12px; font-weight: 600; line-height: 1.4;
  color: var(--violet); border-radius: 3px;
}
.parts-toggle-all:hover { text-decoration: underline; text-underline-offset: 2px; }

.parts-accordion { padding: 0 0 24px; }
.part { border-bottom: 1px solid var(--line); }
.part-heading { margin: 0; font: inherit; }
.part-toggle {
  width: 100%;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 14px 12px 16px;
  background: var(--white); color: var(--ink);
  border: none; cursor: pointer; text-align: left;
  font-family: var(--font-body); line-height: 1.35;
  transition: background var(--transition);
}
.part-toggle:hover { background: var(--paper); }
.part-toggle:focus-visible { outline-offset: -2px; }
.part.open .part-toggle { background: var(--paper); }

.part-chevron {
  flex-shrink: 0; width: 22px; height: 22px; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--line); color: var(--ink-60);
  transition: transform .25s ease, background var(--transition), color var(--transition);
}
.part.open .part-chevron { transform: rotate(90deg); }
.part.has-active .part-chevron { background: var(--violet); color: var(--white); }

.part-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.part-label { font-family: var(--font-read); font-size: 12.5px; font-weight: 600; color: var(--gold-dark); }
.part.has-active .part-label { color: var(--violet); }
.part-title { font-size: 13.5px; font-weight: 600; color: var(--ink); }

.part-count {
  flex-shrink: 0; margin-top: 2px;
  font-size: 11px; font-weight: 600; line-height: 1.7;
  padding: 0 8px; border-radius: 20px;
  background: var(--white); color: var(--ink-60);
  border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.part.complete .part-count { background: var(--moss); border-color: var(--moss); color: var(--white); }

.part-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s ease; }
.part.open .part-panel { grid-template-rows: 1fr; }
.part-panel-inner { overflow: hidden; min-height: 0; }
.part-panel-body { padding: 2px 0 10px; }
.part-empty { font-size: 12.5px; line-height: 1.5; color: var(--ink-60); font-style: italic; padding: 4px 16px 6px 48px; }
.part .lesson-item { padding-left: 24px; }

.parts-accordion.no-anim .part-panel,
.parts-accordion.no-anim .part-chevron { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .part-panel, .part-chevron, .progress-bar-fill { transition: none; }
}

/* ── SEARCH MODAL ── */
body.search-open { overflow: hidden; }
.search-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 2300;
  background: rgba(23,18,46,.64);
  align-items: flex-start; justify-content: center;
  padding: 12vh 20px 20px;
}
.search-modal-overlay.open { display: flex; }
.search-modal {
  width: min(640px, 100%); max-height: 72vh;
  display: flex; flex-direction: column;
  background: var(--white); border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 20px 54px rgba(23,18,46,.42);
  font-family: var(--font-body);
}
.search-modal-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line); }
.search-modal-icon { font-size: 15px; line-height: 1; opacity: .6; }
.search-modal-icon:empty { display: none; }
.search-modal-input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-family: var(--font-body); font-size: 17px; line-height: 1.5; color: var(--ink); padding: 6px 0;
}
.search-modal-input::placeholder { color: var(--ink-40); }
.search-modal-input::-webkit-search-cancel-button { display: none; }
.search-modal-close {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-60);
  font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.search-modal-close:hover { background: var(--line); color: var(--ink); }

.search-modal-results { overflow-y: auto; padding: 8px; scrollbar-width: thin; }
.search-modal-result {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px; margin-bottom: 2px;
  border: none; border-left: 3px solid transparent; border-radius: var(--radius-sm);
  background: transparent; font-family: var(--font-body); color: var(--ink); line-height: 1.4;
}
.search-modal-result.active { background: var(--violet-tint); border-left-color: var(--violet); }
.search-modal-result-title { font-size: 14.5px; font-weight: 600; }
.search-modal-result.active .search-modal-result-title { color: var(--violet-dark); }
.search-modal-result-meta { font-size: 12.5px; color: var(--ink-60); margin-top: 2px; }
.search-modal-result-part { font-size: 11.5px; color: var(--gold-dark); margin-top: 3px; }
.search-modal-result mark { background: var(--gold-soft); color: var(--ink); border-radius: 2px; padding: 0 1px; box-shadow: inset 0 -2px 0 var(--gold); }
.search-modal-current {
  display: inline-block; vertical-align: 1px; margin-left: 6px;
  font-size: 10.5px; font-weight: 600; padding: 0 8px; border-radius: 20px;
  background: var(--violet); color: var(--white); line-height: 1.7;
}
.search-modal-empty { padding: 28px 18px; text-align: center; font-size: 14px; color: var(--ink-60); line-height: 1.6; }
.search-modal-footer {
  display: flex; gap: 18px; flex-wrap: wrap; padding: 9px 20px;
  border-top: 1px solid var(--line); background: var(--paper);
  font-size: 11.5px; color: var(--ink-60); line-height: 1.6;
}
.search-modal-footer kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  background: var(--white); border: 1px solid var(--line-2); border-radius: 4px;
  padding: 0 5px; margin-right: 3px;
}
@media (max-width: 720px) {
  .search-modal-overlay { padding: 16px 12px; }
  .search-modal { max-height: calc(100vh - 32px); }
  .search-modal-footer { display: none; }
}

/* ── HEADER ACTIONS: links & image badges ── */
.action-badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: var(--radius-sm); transition: var(--transition); }
.action-badge img { height: 26px; display: block; }
.action-badge:hover { opacity: .85; }
.action-badge.github { background: #24292e; }

/* ── PDF MODAL ── */
.pdf-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 2100;
  background: rgba(23,18,46,.74);
  align-items: center; justify-content: center; padding: 24px;
}
.pdf-modal-overlay.open { display: flex; }
.pdf-modal {
  position: relative; width: min(920px, 100%); height: min(90vh, 1100px);
  background: var(--white); border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 14px 44px rgba(23,18,46,.42);
  display: flex; flex-direction: column;
}
.pdf-modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px 12px 20px;
  background: var(--ink); color: var(--white);
  border-bottom: 2px solid var(--gold);
  font-family: var(--font-read); font-size: 15px; font-weight: 600;
}
.pdf-modal-close {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: var(--white); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.pdf-modal-close:hover { background: rgba(255,255,255,.25); }
.pdf-modal-frame { flex: 1; border: none; width: 100%; }

/* ── IMAGES & LIGHTBOX ── */
.content-body img {
  cursor: zoom-in; transition: opacity var(--transition);
  max-width: 100%; display: block; margin: 12px 0 28px;
  border-radius: var(--radius); border: 1px solid var(--line);
}
.content-body img:hover { opacity: .93; }

.lightbox-overlay {
  display: none; position: fixed; inset: 0; z-index: 2200;
  background: rgba(23,18,46,.85);
  align-items: center; justify-content: center; padding: 48px;
}
.lightbox-overlay.open { display: flex; }
.lightbox-img { max-width: 100%; max-height: 100%; border-radius: var(--radius); box-shadow: 0 14px 50px rgba(0,0,0,.5); cursor: zoom-out; background: var(--white); }
.lightbox-close {
  position: fixed; top: 22px; right: 26px;
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: var(--white); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,.25); }

/* ── VIDEO ── */
.video-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-read); font-size: 20px; font-weight: 600;
  color: var(--ink); margin: 32px 0 10px;
}
.video-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden;
  margin: 0 0 8px; background: var(--ink-80);
  box-shadow: 0 0 0 1px var(--line);
}
.video-wrap iframe, .video-wrap video {
  position: absolute; inset: 0; width: 100%; height: 100%; border: none; display: block;
}
.video-play-overlay {
  position: absolute; top: 50%; left: 50%; z-index: 2;
  width: 86px; height: 86px; margin: -43px 0 0 -43px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 2px solid var(--gold);
  background: rgba(23,18,46,.6); color: var(--white); cursor: pointer;
  box-shadow: 0 8px 28px rgba(23,18,46,.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: opacity .2s ease, transform .2s ease, background var(--transition);
}
.video-play-overlay svg { width: 44px; height: 44px; display: block; margin-left: 4px; }
.video-play-overlay:hover { background: var(--violet); transform: scale(1.05); }
.video-play-overlay:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 4px; }
.video-play-overlay.is-hidden { opacity: 0; transform: scale(.85); pointer-events: none; }
@media (max-width: 720px) {
  .video-play-overlay { width: 64px; height: 64px; margin: -32px 0 0 -32px; }
  .video-play-overlay svg { width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) { .video-play-overlay { transition: none; } }
.video-caption { font-size: 13.5px; color: var(--ink-60); margin: 0 0 28px; text-align: center; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; margin: 28px 0; border: 1px solid var(--line); border-radius: var(--radius); }
.content-table { width: 100%; border-collapse: collapse; font-family: var(--font-body); font-size: 15px; }
.content-table caption {
  caption-side: top; text-align: left; padding: 12px 18px;
  font-family: var(--font-read); font-size: 15px; font-weight: 600;
  color: var(--ink); background: var(--paper); border-bottom: 1px solid var(--line);
}
.content-table thead th {
  background: var(--ink); color: var(--white); text-align: left;
  padding: 11px 18px; font-weight: 600; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid var(--gold);
}
.content-table tbody td { padding: 11px 18px; border-top: 1px solid var(--line); color: var(--text); vertical-align: top; line-height: 1.55; font-size: 15px; }
.content-table tbody tr:nth-child(even) { background: var(--paper); }
.content-table tbody tr:hover { background: var(--violet-tint); }
.content-table td strong { color: var(--ink); }

/* ── MAIN CONTENT AREA ── */
.main { min-width: 0; background: var(--white); }

/* Lesson header: an energy landscape.
   ::before = contour lines of an energy basin (thin rings),
   ::after  = the low-energy minimum glowing gold. */
.lesson-header {
  background: var(--ink);
  padding: 36px 48px 30px;
  position: relative; overflow: hidden; isolation: isolate;
}
.lesson-header::before,
.lesson-header::after {
  content: ""; position: absolute; pointer-events: none; z-index: -1;
}
.lesson-header::before {
  inset: -40% -10% -40% 35%;
  background:
    repeating-radial-gradient(ellipse 58% 44% at 62% 50%,
      transparent 0 17px,
      rgba(205,194,251,.20) 17px 18px),
    repeating-radial-gradient(ellipse 34% 30% at 96% 12%,
      transparent 0 15px,
      rgba(205,194,251,.12) 15px 16px);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 45%, #000 100%);
          mask-image: linear-gradient(90deg, transparent 0%, #000 45%, #000 100%);
}
.lesson-header::after {
  top: 50%; right: 12%; width: 320px; height: 240px; margin-top: -120px;
  background: radial-gradient(ellipse at center,
    rgba(232,195,79,.55) 0%,
    rgba(201,162,39,.25) 22%,
    rgba(91,63,209,.22) 48%,
    transparent 70%);
  filter: blur(2px);
}
.lesson-breadcrumb {
  font-size: 12.5px; color: rgba(255,255,255,.55); margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.lesson-breadcrumb a { color: rgba(255,255,255,.55); text-decoration: none; }
.lesson-breadcrumb a:hover { color: var(--gold-bright); }
.lesson-breadcrumb span.sep { opacity: .45; }
.lesson-main-title {
  font-family: var(--font-read); font-size: 34px; font-weight: 600; color: var(--white);
  letter-spacing: -.012em; line-height: 1.18; margin-bottom: 12px; max-width: 780px;
}
.lesson-subtitle {
  font-family: var(--font-read); font-size: 17px; color: rgba(255,255,255,.74);
  max-width: 660px; font-weight: 400; line-height: 1.65;
}
.lesson-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.lesson-tag {
  font-size: 12px; padding: 2px 11px; border-radius: 20px; font-weight: 500;
  border: 1px solid rgba(255,255,255,.2); color: rgba(255,255,255,.82);
  background: rgba(255,255,255,.06);
}
.lesson-actions { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; align-items: center; }
.action-btn {
  padding: 8px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 7px; border: 1px solid transparent;
}
a.action-btn { text-decoration: none; }
.action-btn.outline { background: rgba(255,255,255,.07); color: var(--white); border-color: rgba(255,255,255,.26); }
.action-btn.outline:hover { background: rgba(255,255,255,.16); }
.action-btn.accent { background: var(--gold); color: var(--ink); }
.action-btn.accent:hover { background: var(--gold-bright); }
.action-btn:focus-visible { outline-color: var(--gold-bright); }

.content-body { padding: 44px 48px 80px; width: 100%; }

/* ── CONTENT TYPOGRAPHY (serif reading column) ── */
.content-body h2 {
  font-family: var(--font-read); font-size: 27px; font-weight: 600; color: var(--ink);
  margin: 50px 0 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  letter-spacing: -.01em; line-height: 1.25;
  position: relative;
}
.content-body h2::after {
  content: ""; position: absolute; left: 0; bottom: -1px;
  width: 56px; height: 2px; background: var(--gold);
}
.content-body > :first-child { margin-top: 0; }
.content-body h3 { font-family: var(--font-read); font-size: 20.5px; font-weight: 600; color: var(--ink); margin: 30px 0 10px; line-height: 1.35; }
.content-body p,
.content-body li { font-family: var(--font-read); font-size: 18.5px; line-height: 1.8; color: var(--text); font-weight: 400; }
.content-body p { margin-bottom: 18px; }
.content-body a { color: var(--violet); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--violet-soft); }
.content-body a:hover { text-decoration-color: var(--violet); }
.content-body strong { font-weight: 700; color: var(--ink); }
.content-body ul, .content-body ol { margin: 0 0 20px 24px; }
.content-body li { margin-bottom: 8px; padding-left: 4px; }
.content-body li::marker { color: var(--gold); }
.content-body .callout-text strong { color: inherit; }

/* ── CALLOUTS ── */
.callout {
  border-radius: var(--radius); padding: 16px 20px;
  margin: 26px 0; border-left: 4px solid;
  display: flex; gap: 14px; align-items: flex-start;
}
.callout-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.callout-icon:empty { display: none; }
.callout-body { flex: 1; min-width: 0; }
.callout-label { font-family: var(--font-body); font-size: 13.5px; font-weight: 700; margin-bottom: 4px; }
.content-body .callout-text { font-family: var(--font-body); font-size: 15.5px; line-height: 1.7; margin: 0; }

.callout-new     { background: var(--new-concept-bg); border-color: var(--violet-soft); }
.callout-new .callout-label, .callout-new .callout-text { color: var(--white); }
.callout-caution { background: var(--caution-bg); border-color: var(--gold-bright); }
.callout-caution .callout-label, .callout-caution .callout-text { color: var(--white); }
.callout-best    { background: var(--best-practice-bg); border-color: var(--moss-light); }
.callout-best .callout-label, .callout-best .callout-text { color: var(--white); }
.callout-error   { background: var(--common-error-bg); border-color: var(--gold-dark); }
.callout-error .callout-label, .callout-error .callout-text { color: var(--ink); }
/* extra variants, ready if you use them in content.js */
.callout-deep    { background: var(--deep-dive-bg); border-color: var(--violet); }
.callout-deep .callout-label { color: var(--violet-dark); }
.callout-deep .callout-text { color: var(--ink); }
.callout-try     { background: var(--moss-tint); border-color: var(--moss); }
.callout-try .callout-label { color: var(--moss); }
.callout-try .callout-text { color: var(--ink); }

/* ── CODE BLOCK ── */
.code-block {
  background: var(--ink-80); border-radius: var(--radius);
  padding: 40px 22px 20px; margin: 26px 0; overflow-x: auto; position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.code-block::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 32px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(255,255,255,.02);
}
.code-lang {
  position: absolute; top: 8px; left: 18px;
  font-size: 11.5px; font-weight: 500; color: rgba(255,255,255,.5); font-family: var(--font-mono);
}
.code-block pre { font-family: var(--font-mono); font-size: 13.5px; line-height: 1.75; color: #dcd8f0; white-space: pre; tab-size: 4; }
.code-block .kw  { color: #b9a6ff; }
.code-block .fn  { color: #8fc7f2; }
.code-block .str { color: #b8e0a4; }
.code-block .cm  { color: rgba(220,216,240,.45); font-style: italic; }
.code-block .num { color: var(--gold-bright); }
.copy-btn {
  position: absolute; top: 5px; right: 10px;
  padding: 2px 12px; border-radius: 20px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.72); font-size: 11.5px; font-weight: 500; font-family: var(--font-body);
  cursor: pointer; transition: var(--transition);
}
.copy-btn:hover { background: rgba(255,255,255,.18); color: var(--white); }

/* ── MATH (KaTeX) ── */
.math-block {
  background: var(--paper);
  border: 1px solid var(--line); border-left: 3px solid var(--violet);
  border-radius: var(--radius);
  padding: 18px 22px; margin: 26px 0;
  overflow-x: auto; text-align: center;
}
.math-block .katex-display { margin: 0; }
.math-block .katex { font-size: 1.18em; }

/* ── KEY TERM CHIPS / INLINE CODE ── */
.term-chip {
  display: inline-block; padding: 0 9px; border-radius: 20px;
  font-size: 13px; font-family: var(--font-mono);
  background: var(--violet-tint); color: var(--violet-dark);
  border: 1px solid var(--violet-soft); white-space: nowrap;
}
.inline-code {
  font-family: var(--font-mono); font-size: .82em;
  background: var(--paper); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line);
}

/* ── QUIZ (single question) ── */
.quiz-card, .quizset-card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 24px; margin: 34px 0;
}
.quiz-header, .quizset-header {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-read); font-size: 19px; font-weight: 600; color: var(--ink);
  margin-bottom: 14px;
}
.quiz-header span:empty, .quizset-header span:empty { display: none; }
.quiz-question, .quizset-question-text { font-size: 15.5px; font-weight: 500; color: var(--ink); margin-bottom: 14px; }
.quiz-options, .quizset-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option, .quizset-option {
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--white);
  font-size: 15px; cursor: pointer; transition: var(--transition);
  text-align: left; font-family: var(--font-body); font-weight: 400; color: var(--ink); line-height: 1.5;
}
.quiz-option:hover, .quizset-option:hover { border-color: var(--violet-soft); background: var(--violet-tint); }
.quiz-option:disabled, .quizset-option:disabled { cursor: default; }
.quizset-option.selected { border-color: var(--violet); background: var(--violet-tint); }
.quiz-option.correct, .quizset-option.correct { border-color: var(--moss); background: var(--moss); color: var(--white); }
.quiz-option.wrong, .quizset-option.wrong { border-color: var(--red); background: var(--red-bg); color: var(--red); }
.quiz-feedback { margin-top: 12px; font-size: 14px; display: none; }
.quiz-feedback.show { display: block; }

/* ── QUIZ SET (graded on submit) ── */
.quizset-question-block { margin-bottom: 26px; }
.quizset-question-block:last-of-type { margin-bottom: 22px; }
.quizset-question-num { font-size: 12.5px; font-weight: 600; color: var(--ink-60); margin-bottom: 6px; }
.quizset-explanation { margin-top: 8px; font-size: 14px; color: var(--ink-60); display: none; line-height: 1.6; padding-left: 2px; }
.quizset-explanation.show { display: block; }
.quizset-submit-btn {
  padding: 10px 22px; border-radius: var(--radius-sm); border: none;
  background: var(--violet); color: var(--white);
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.quizset-submit-btn:hover { background: var(--violet-dark); }
.quizset-submit-btn:disabled { opacity: .5; cursor: default; }
.quizset-score-banner {
  display: none; padding: 12px 18px; border-radius: var(--radius-sm);
  margin-bottom: 20px; font-family: var(--font-body); font-size: 14.5px; font-weight: 600;
}
.quizset-score-banner.show { display: block; }
.quizset-score-banner.pass { background: var(--moss); color: var(--white); }
.quizset-score-banner.fail { background: var(--gold-soft); color: var(--ink); }

/* ── SECTION DIVIDER ── */
.section-divider { height: 1px; background: var(--line); margin: 44px 0; }

/* ── PREV / NEXT FOOTER ── */
.lesson-nav-footer {
  display: flex; justify-content: space-between; align-items: stretch; gap: 16px;
  padding: 24px 48px; border-top: 1px solid var(--line); background: var(--white);
}
.nav-btn {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--white);
  font-family: var(--font-body); font-size: 14px; cursor: pointer;
  transition: var(--transition); color: var(--ink); text-decoration: none;
}
.nav-btn:hover { border-color: var(--violet); background: var(--violet-tint); }
.nav-btn:hover .nav-arrow { color: var(--violet); }
.nav-arrow { font-size: 18px; color: var(--ink-40); transition: var(--transition); }
.nav-btn-label { font-size: 12px; color: var(--ink-60); display: block; margin-bottom: 2px; }
.nav-btn-title { font-family: var(--font-read); font-weight: 600; font-size: 15.5px; line-height: 1.35; }
.nav-btn.next { justify-content: flex-end; text-align: right; }
.nav-btn.disabled { opacity: .4; pointer-events: none; }

/* ── RIGHT RAIL — SECTION NAVIGATOR ── */
.toc {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overflow-x: hidden;
  background: var(--paper); border-left: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.toc::-webkit-scrollbar { width: 5px; }
.toc::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.toc-inner { padding: 22px 16px; }
.toc-title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.toc-list { list-style: none; display: flex; flex-direction: column; gap: 1px; border-left: 1px solid var(--line-2); }
.toc-item a {
  display: block; padding: 5px 10px 5px 12px; margin-left: -1px;
  font-size: 13px; color: var(--ink-60); text-decoration: none;
  border-left: 2px solid transparent; transition: var(--transition); line-height: 1.4;
}
.toc-item a:hover { color: var(--ink); }
.toc-item.active a { color: var(--violet-dark); font-weight: 600; border-left-color: var(--violet); }
.toc-item.sub a { padding-left: 24px; font-size: 12.5px; }

.toc-meta { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.toc-meta-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-60); margin-bottom: 8px; }
.toc-meta-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.legend { margin-top: 22px; }
.legend-title { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-60); margin-bottom: 7px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(23,18,46,.12); }

/* ── MOBILE TOGGLE ── */
.mob-toggle {
  display: none; position: fixed; bottom: 20px; right: 20px; z-index: 1200;
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--violet); color: var(--white);
  border: 2px solid var(--gold); font-size: 20px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(91,63,209,.45);
  align-items: center; justify-content: center;
}

/* ── RESPONSIVE ── */
@media (max-width: 1180px) {
  .toc { display: none; }
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .navbar-links .navbar-btn:not(.primary) { display: none; }
}
@media (max-width: 720px) {
  :root { --sidebar-w: 0px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* drawer covers the full height, above the sticky navbar */
  .sidebar {
    position: fixed; left: -310px; top: 0; width: 290px; z-index: 1100;
    height: 100vh; height: 100dvh;
    transition: left .3s ease; box-shadow: none;
  }
  .sidebar.open { left: 0; box-shadow: var(--shadow-md); }
  .mob-toggle { display: flex; }
  .content-body { padding: 28px 20px 60px; }
  .content-body p, .content-body li { font-size: 17.5px; }
  .lesson-header { padding: 26px 20px 22px; }
  .lesson-header::before { inset: -40% -40% -40% 10%; opacity: .7; }
  .lesson-header::after { right: -20%; opacity: .7; }
  .lesson-main-title { font-size: 25px; }
  .lesson-subtitle { font-size: 15.5px; }
  .lesson-nav-footer { padding: 16px 20px; }
  .navbar { padding: 0 12px; }
  .navbar-search { flex: 0 0 auto; padding: 5px 12px; }
  .navbar-search kbd { display: none; }
  .navbar-left { gap: 8px; }
  .navbar-left-links .navbar-btn { padding: 5px 10px; font-size: 12px; }
  .navbar-left-links .navbar-btn:not(:first-child) { display: none; }
}
@media (max-width: 520px) {
  .lesson-nav-footer { flex-direction: column; gap: 10px; }
  .nav-btn { width: 100%; }
  .nav-btn.next { justify-content: flex-start; text-align: left; }
}

/* ── SITE FOOTER ── */
.site-footer {
  background:
    radial-gradient(ellipse 50% 100% at 50% 100%, rgba(91,63,209,.22), transparent 70%),
    var(--ink);
  padding: 30px 32px 18px;
  border-top: 1px solid rgba(201,162,39,.55);
}
.site-footer-inner { max-width: 1100px; margin: 0 auto; }
.site-footer-container { margin: 0 auto; text-align: center; max-width: 660px; }
.site-footer-brand { font-family: var(--font-read); font-size: 19px; font-weight: 600; color: var(--white); margin-bottom: 4px; }
.site-footer-tagline { font-size: 13px; color: rgba(255,255,255,.58); line-height: 1.65; text-align: center; margin: 0 auto; max-width: 620px; }
.site-footer-links { display: flex; gap: 24px; flex-wrap: wrap; }
.site-footer-links a, .site-footer-links button {
  font-family: var(--font-body); font-size: 13px; color: rgba(255,255,255,.66);
  text-decoration: none; background: none; border: none; cursor: pointer; padding: 0; transition: var(--transition);
}
.site-footer-links a:hover, .site-footer-links button:hover { color: var(--gold-bright); }

.site-footer-row {
  max-width: 1000px; margin: 18px auto 0;
  display: flex; align-items: center; justify-content: center; gap: 14px;
}
.site-footer-author {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 30px;
  background: rgba(255,255,255,.04); line-height: 1.4; white-space: nowrap;
}
.site-footer-author-label { font-size: 12px; color: rgba(255,255,255,.55); }
.site-footer-author-name { font-family: var(--font-read); font-size: 15px; font-weight: 600; color: var(--white); }
.site-footer-author-link {
  width: 30px; height: 30px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--gold); color: var(--ink); transition: var(--transition);
}
.site-footer-author-link svg { width: 15px; height: 15px; display: block; }
.site-footer-author-link:hover { background: var(--white); color: var(--violet); transform: translateY(-1px); }
.site-footer-author-link:focus-visible { outline-color: var(--gold-bright); outline-offset: 3px; }

.site-footer-disclaimer {
  flex: 1; min-width: 0; margin: 0; padding: 8px 14px;
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(255,255,255,.04);
  font-size: 12.5px; line-height: 1.6; color: rgba(255,255,255,.68); text-align: left;
}
.site-footer-disclaimer strong { color: var(--gold-bright); }
.site-footer-disclaimer-btn {
  background: none; border: none; padding: 0; margin-left: 4px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--violet-soft);
  text-decoration: underline; text-underline-offset: 3px;
}
.site-footer-disclaimer-btn:hover { color: var(--white); }
.site-footer-disclaimer-btn:focus-visible { outline-color: var(--gold-bright); }

.site-footer-bottom,
.site-footer .site-footer-bottom {
  max-width: 1000px; margin: 16px auto 0; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px; color: rgba(255,255,255,.42);
  display: flex; justify-content: center; text-align: center; flex-wrap: wrap; gap: 8px;
}
@media (max-width: 900px) {
  .site-footer-row { flex-direction: column; gap: 12px; }
  .site-footer-disclaimer { width: 100%; }
}
@media (max-width: 720px) {
  .site-footer { padding: 24px 16px 88px; } /* room for the floating menu button */
  .site-footer-author { white-space: normal; flex-wrap: wrap; justify-content: center; border-radius: 16px; padding: 8px 12px; row-gap: 4px; }
  .site-footer-author-label { flex-basis: 100%; text-align: center; }
}

/* ── RAIL SCROLLBARS: always visible, themed ── */
.sidebar, .toc {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--violet-soft) transparent;
}
.sidebar:hover, .toc:hover { scrollbar-color: var(--violet) transparent; }
