/* ============================================================
   YOSHUA BENGIO LITERATURE — STYLESHEET
   3-column lesson layout (sidebar / content / TOC), same class
   names as the Hinton template so content and engine stay
   interchangeable. Re-skin by editing the tokens in :root.

   Palette "Laurentian winter":
     ink (spruce night) · lake (interaction) · maple (brand)
     amber (highlight) · pine (success) · cool paper
   ============================================================ */

:root {
  /* ── Core palette ── */
  --ink:        #0f2a33;   /* spruce night: header, topbar, tables */
  --ink-80:     #16353f;   /* code background */
  --ink-70:     #22454f;   /* navbar */
  --ink-60:     #52676e;   /* muted text */
  --ink-40:     #8a9ba0;
  --white:      #ffffff;
  --paper:      #f2f5f4;   /* page + rails */
  --line:       #dce4e3;
  --line-2:     #c7d3d1;
  --text:       #22363c;   /* body copy */

  --lake:       #1d6a86;   /* links, active states, focus */
  --lake-dark:  #13506a;
  --lake-tint:  #e6f1f5;
  --lake-soft:  #a9d2e0;

  --maple:      #b7372b;   /* brand moments only */
  --maple-dark: #8f2a20;
  --maple-soft: #f1c6c0;

  --amber:      #f2c14e;
  --amber-dark: #5b4108;
  --amber-soft: #fbeac2;

  --pine:       #1f6b4a;
  --pine-light: #9fd1b5;

  --red:        #b3261e;
  --red-bg:     #fcebe9;

  /* ── Callout tokens (one per .callout-<variant>) ── */
  --new-concept-bg:   var(--lake);
  --caution-bg:       var(--amber-dark);
  --best-practice-bg: var(--pine);
  --common-error-bg:  var(--amber-soft);
  --deep-dive-bg:     #eef0f7;
  --deep-dive-line:   #4b4f86;
  --try-it-bg:        #e4f3eb;

  /* ── Layout ── */
  --sidebar-w:  272px;
  --toc-w:      248px;
  --header-h:   58px;
  --radius:     8px;
  --radius-sm:  5px;
  --radius-lg:  14px;
  --shadow-md:  0 6px 20px rgba(15,42,51,.12);
  --transition: .2s ease;

  /* ── Type ── */
  --font-read: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-ui:   'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex 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-ui);
  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(--lake); outline-offset: 2px; }

/* ── TOP BRAND STRIP ── */
.topbar {
  background: var(--ink);
  color: var(--white);
  text-align: center;
  padding: 26px 20px 20px;
  border-bottom: 3px solid var(--maple);
}
.topbar-brand {
  display: inline-flex; align-items: center; justify-content: center; gap: 18px;
  color: var(--white); text-decoration: none;
  font-family: var(--font-read); font-weight: 700; font-size: 30px; 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(--ink-70);
  border: 2px solid var(--white);
  box-shadow: 0 0 0 3px var(--maple), 0 8px 20px rgba(0,0,0,.35);
}
.topbar-brand .topbar-portrait img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 22%; max-width: none;
}
.topbar-brand-text { min-width: 0; }
.topbar-tagline {
  margin: 8px auto 0; max-width: 620px;
  font-size: 14px; color: rgba(255,255,255,.62);
}
.topbar-tagline:empty { display: none; }

.disclaimer-btn {
  margin-top: 12px; padding: 5px 16px; border-radius: 20px;
  background: transparent; border: 1px solid rgba(255,255,255,.28);
  color: rgba(255,255,255,.8); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: var(--transition);
}
.disclaimer-btn:hover { background: rgba(255,255,255,.1); 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(--maple), 0 4px 12px rgba(0,0,0,.35); }
  .topbar-tagline { font-size: 13px; }
}
@media (max-width: 380px) {
  .topbar-brand { font-size: 18px; }
  .topbar-brand .topbar-portrait { width: 48px; height: 48px; }
}

/* ── Shared text close button used by every modal ── */
.modal-close-text {
  flex-shrink: 0; padding: 4px 12px; border-radius: 20px;
  border: 1px solid var(--line-2); background: var(--white); color: var(--ink-60);
  font-size: 12.5px; font-weight: 600; cursor: pointer; transition: var(--transition);
}
.modal-close-text:hover { border-color: var(--ink); color: var(--ink); }
.modal-close-text.on-dark { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); color: var(--white); }
.modal-close-text.on-dark:hover { background: rgba(255,255,255,.22); }

/* ── DISCLAIMER MODAL ── */
.disclaimer-overlay {
  display: none; position: fixed; inset: 0; z-index: 2000;
  background: rgba(15,42,51,.62);
  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;
  box-shadow: 0 16px 44px rgba(15,42,51,.35);
  border-top: 4px solid var(--maple);
}
.disclaimer-title {
  font-family: var(--font-read); font-size: 22px; font-weight: 700;
  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); }
.disclaimer-close { position: absolute; top: 14px; right: 14px; }

/* ── NAV BAR (sticky, so the sticky rails line up under it) ── */
.navbar {
  position: sticky; top: 0; z-index: 1000;
  height: var(--header-h);
  background: var(--ink-70);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.2);
}
.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(--maple); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-read); font-weight: 700; font-size: 14px;
}
.navbar-left-links, .navbar-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,.22);
  color: rgba(255,255,255,.85); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
  display: inline-flex; align-items: center;
}
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(--lake-soft); }
.navbar-btn.primary { background: var(--maple); border-color: var(--maple); color: var(--white); }
.navbar-btn.primary:hover { background: var(--maple-dark); border-color: var(--maple-dark); }

.navbar-search {
  flex: 0 1 280px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
  border-radius: 20px; padding: 6px 8px 6px 16px;
  color: rgba(255,255,255,.6); font-size: 13px; cursor: pointer;
  transition: var(--transition);
}
.navbar-search:hover { background: rgba(255,255,255,.14); color: rgba(255,255,255,.85); }
.navbar-search:focus-visible { outline-color: var(--lake-soft); }
.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: .8;
}

/* ── MAIN 3-COLUMN LAYOUT ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  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(--lake), var(--maple));
  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(--lake-tint); border-left-color: var(--lake); }
.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(--pine); border-color: var(--pine); color: var(--white); }
.lesson-item.active .lesson-num { background: var(--lake); border-color: var(--lake); 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(--lake-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(--maple-soft); color: var(--maple-dark); }
.badge-lab  { background: var(--try-it-bg); color: var(--pine); }
.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-size: 12px; font-weight: 600; color: var(--lake);
}
.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; 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); }

/* chevron drawn with borders — no icon font, no SVG */
.part-chevron {
  flex-shrink: 0; width: 22px; height: 22px; margin-top: 2px;
  border-radius: 50%; background: var(--line); position: relative;
  transition: transform .25s ease, background var(--transition);
}
.part-chevron::before {
  content: ""; position: absolute; left: 8px; top: 7px;
  width: 6px; height: 6px;
  border-right: 2px solid var(--ink-60); border-bottom: 2px solid var(--ink-60);
  transform: rotate(-45deg);
}
.part.open .part-chevron { transform: rotate(90deg); }
.part.has-active .part-chevron { background: var(--lake); }
.part.has-active .part-chevron::before { border-color: var(--white); }

.part-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.part-label { font-family: var(--font-read); font-size: 12.5px; font-weight: 600; color: var(--ink-60); }
.part.has-active .part-label { color: var(--lake); }
.part-years { font-family: var(--font-mono); font-size: 11px; color: var(--maple); }
.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(--pine); border-color: var(--pine); 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.modal-open { overflow: hidden; }
.search-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 2300;
  background: rgba(15,42,51,.62);
  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 18px 50px rgba(15,42,51,.4);
}
.search-modal-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line); }
.search-modal-input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-family: var(--font-ui); 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-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; color: var(--ink); line-height: 1.4;
}
.search-modal-result.active { background: var(--lake-tint); border-left-color: var(--lake); }
.search-modal-result-title { font-size: 14.5px; font-weight: 600; }
.search-modal-result.active .search-modal-result-title { color: var(--lake-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(--maple); margin-top: 3px; }
.search-modal-result mark { background: var(--amber); color: var(--ink); border-radius: 2px; padding: 0 1px; }
.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(--lake); 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);
}
.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; }
}

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

/* Lesson header with the attention-alignment matrix.
   ::before = coloured diagonal band, ::after = grid gaps drawn in
   header colour on top, so the band shows through as lit cells. */
.lesson-header {
  background: var(--ink);
  padding: 36px 48px 30px;
  position: relative; overflow: hidden; isolation: isolate;
}
.lesson-header::before,
.lesson-header::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0;
  width: min(46%, 460px); z-index: -1;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 55%);
          mask-image: linear-gradient(90deg, transparent 0%, #000 55%);
}
.lesson-header::before {
  background:
    linear-gradient(135deg,
      transparent 30%,
      rgba(183,55,43,.25) 40%,
      rgba(183,55,43,.85) 48%,
      rgba(242,193,78,.75) 50%,
      rgba(183,55,43,.85) 52%,
      rgba(183,55,43,.25) 60%,
      transparent 70%),
    rgba(255,255,255,.05);
}
.lesson-header::after {
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 4px, transparent 4px 26px),
    repeating-linear-gradient(0deg,  var(--ink) 0 4px, transparent 4px 26px);
}
.lesson-header-inner { position: relative; max-width: 760px; }
.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 .sep { opacity: .45; }
.lesson-breadcrumb .current { color: rgba(255,255,255,.85); }
.lesson-main-title {
  font-family: var(--font-read); font-size: 34px; font-weight: 700; color: var(--white);
  letter-spacing: -.01em; line-height: 1.18; margin-bottom: 12px;
}
.lesson-subtitle { font-family: var(--font-read); font-size: 17px; color: rgba(255,255,255,.72); max-width: 640px; line-height: 1.6; }
.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,.8);
  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; cursor: pointer; transition: var(--transition);
  display: inline-flex; align-items: center; border: 1px solid transparent;
}
a.action-btn { text-decoration: none; }
.action-btn.outline { background: rgba(255,255,255,.08); color: var(--white); border-color: rgba(255,255,255,.28); }
.action-btn.outline:hover { background: rgba(255,255,255,.18); }
.action-btn.accent { background: var(--maple); color: var(--white); }
.action-btn.accent:hover { background: var(--maple-dark); }
.action-btn:focus-visible { outline-color: var(--lake-soft); }
.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; }

.content-body { padding: 44px 48px 80px; max-width: 860px; }

/* ── CONTENT TYPOGRAPHY (serif reading column) ── */
.content-body h2 {
  font-family: var(--font-read); font-size: 27px; font-weight: 700; color: var(--ink);
  margin: 48px 0 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  letter-spacing: -.01em; line-height: 1.25;
}
.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); }
.content-body p { margin-bottom: 18px; }
.content-body a { color: var(--lake); text-decoration: underline; text-underline-offset: 3px; }
.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(--maple); }
.content-body code { font-family: var(--font-mono); font-size: .82em; background: var(--paper); padding: 1px 6px; border-radius: 4px; }

/* ── FIGURES / IMAGES ── */
.content-figure { margin: 28px 0; }
.content-figure img {
  max-width: 100%; display: block; border-radius: var(--radius);
  border: 1px solid var(--line); cursor: zoom-in; transition: opacity var(--transition);
}
.content-figure img:hover { opacity: .93; }
.content-figure figcaption { font-size: 13.5px; color: var(--ink-60); margin-top: 10px; line-height: 1.55; }
.figure-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 220px; padding: 24px; text-align: center;
  border: 2px dashed var(--line-2); border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, var(--paper) 0 12px, var(--white) 12px 24px);
  color: var(--ink-60); font-size: 13.5px;
}
.figure-placeholder strong { color: var(--ink); font-size: 14.5px; }
.figure-placeholder code { font-family: var(--font-mono); font-size: 12.5px; }

/* ── LIGHTBOX ── */
.lightbox-overlay {
  display: none; position: fixed; inset: 0; z-index: 2200;
  background: rgba(15,42,51,.82);
  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 12px 48px rgba(0,0,0,.5); cursor: zoom-out; background: var(--white); }
.lightbox-close { position: fixed; top: 18px; right: 20px; }

/* ── PDF MODAL ── */
.pdf-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 2100;
  background: rgba(15,42,51,.72);
  align-items: center; justify-content: center; padding: 24px;
}
.pdf-modal-overlay.open { display: flex; }
.pdf-modal {
  width: min(920px, 100%); height: min(90vh, 1100px);
  background: var(--white); border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 12px 40px rgba(15,42,51,.4);
  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);
  font-family: var(--font-read); font-size: 15px; font-weight: 600;
}
.pdf-modal-frame { flex: 1; border: none; width: 100%; }

/* ── VIDEO ── */
.video-block { margin: 32px 0; }
.video-title { font-family: var(--font-read); font-size: 20px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }
.video-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: var(--ink-80);
}
.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;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.9);
  background: rgba(15,42,51,.62); cursor: pointer;
  box-shadow: 0 8px 28px rgba(15,42,51,.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  transition: opacity .2s ease, transform .2s ease, background var(--transition);
}
/* play triangle drawn with CSS borders */
.video-play-overlay::before {
  content: ""; position: absolute; top: 50%; left: 50%;
  margin: -16px 0 0 -9px;
  border-style: solid; border-width: 16px 0 16px 26px;
  border-color: transparent transparent transparent var(--white);
}
.video-play-overlay:hover { background: var(--maple); transform: scale(1.05); }
.video-play-overlay:focus-visible { outline: 3px solid var(--lake-soft); outline-offset: 4px; }
.video-play-overlay.is-hidden { opacity: 0; transform: scale(.85); pointer-events: none; }
.video-fallback {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 24px; text-align: center; color: rgba(255,255,255,.8); font-size: 14px;
  background: var(--ink-80);
}
.video-fallback strong { color: var(--white); font-family: var(--font-read); font-size: 19px; }
.video-caption { font-size: 13.5px; color: var(--ink-60); margin-top: 10px; }
@media (max-width: 720px) {
  .video-play-overlay { width: 64px; height: 64px; margin: -32px 0 0 -32px; }
  .video-play-overlay::before { margin: -12px 0 0 -7px; border-width: 12px 0 12px 20px; }
}
@media (prefers-reduced-motion: reduce) { .video-play-overlay { transition: none; } }

/* ── 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-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;
}
.content-table tbody td { padding: 11px 18px; border-top: 1px solid var(--line); color: var(--text); vertical-align: top; line-height: 1.55; }
.content-table tbody tr:nth-child(even) { background: var(--paper); }
.content-table tbody tr:hover { background: var(--lake-tint); }
.content-table td strong { color: var(--ink); }

/* ── CALLOUTS ── */
.callout { border-radius: var(--radius); padding: 16px 20px; margin: 26px 0; border-left: 4px solid; }
.callout-label { font-size: 13.5px; font-weight: 700; margin-bottom: 4px; }
.content-body .callout-text { font-family: var(--font-ui); font-size: 15.5px; line-height: 1.7; margin: 0; }
.content-body .callout-text code { background: rgba(255,255,255,.16); }
.content-body .callout-error .callout-text code,
.content-body .callout-deep .callout-text code,
.content-body .callout-try .callout-text code { background: rgba(15,42,51,.08); }
.content-body .callout-text strong { color: inherit; }

.callout-new     { background: var(--new-concept-bg); border-color: var(--lake-soft); }
.callout-new .callout-label, .callout-new .callout-text { color: var(--white); }
.callout-caution { background: var(--caution-bg); border-color: var(--amber); }
.callout-caution .callout-label, .callout-caution .callout-text { color: var(--white); }
.callout-best    { background: var(--best-practice-bg); border-color: var(--pine-light); }
.callout-best .callout-label, .callout-best .callout-text { color: var(--white); }
.callout-error   { background: var(--common-error-bg); border-color: var(--amber-dark); }
.callout-error .callout-label, .callout-error .callout-text { color: var(--ink); }
.callout-deep    { background: var(--deep-dive-bg); border-color: var(--deep-dive-line); }
.callout-deep .callout-label { color: var(--deep-dive-line); }
.callout-deep .callout-text { color: var(--ink); }
.callout-try     { background: var(--try-it-bg); border-color: var(--pine); }
.callout-try .callout-label { color: var(--pine); }
.callout-try .callout-text { color: var(--ink); }

/* ── CODE BLOCK ── */
.code-block { background: var(--ink-80); border-radius: var(--radius); margin: 26px 0; position: relative; overflow: hidden; }
.code-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.code-lang { font-family: var(--font-mono); font-size: 11.5px; color: rgba(255,255,255,.5); }
.copy-btn {
  padding: 3px 12px; border-radius: 20px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.7); font-size: 11.5px; font-weight: 500; cursor: pointer; transition: var(--transition);
}
.copy-btn:hover { background: rgba(255,255,255,.18); color: var(--white); }
.code-block pre { padding: 16px 20px 20px; overflow-x: auto; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.75; color: #d6e4e6; white-space: pre; tab-size: 4; }
.code-block .kw  { color: #f2a097; }
.code-block .fn  { color: #8fd0e6; }
.code-block .str { color: #c9e3a2; }
.code-block .cm  { color: rgba(214,228,230,.45); font-style: italic; }
.code-block .num { color: #f2c14e; }

/* ── MATH (KaTeX) ── */
.math-block {
  background: var(--paper); border: 1px solid var(--line); border-left: 3px solid var(--lake);
  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; }
.content-body .math-caption { font-family: var(--font-ui); font-size: 14px; line-height: 1.6; color: var(--ink-60); margin: -14px 0 24px; }

/* ── TERM CHIPS ── */
.term-chip {
  display: inline-block; padding: 0 9px; border-radius: 20px;
  font-family: var(--font-mono); font-size: 13px;
  background: var(--lake-tint); color: var(--lake-dark); border: 1px solid var(--lake-soft); white-space: nowrap;
}

/* ── 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 { font-family: var(--font-read); font-size: 19px; font-weight: 700; color: var(--ink); margin-bottom: 12px; }
.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; color: var(--ink); line-height: 1.5;
}
.quiz-option:hover, .quizset-option:hover { border-color: var(--lake-soft); background: var(--lake-tint); }
.quiz-option:disabled, .quizset-option:disabled { cursor: default; }
.quizset-option.selected { border-color: var(--lake); background: var(--lake-tint); }
.quiz-option.correct, .quizset-option.correct { border-color: var(--pine); background: var(--pine); color: var(--white); }
.quiz-option.wrong, .quizset-option.wrong { border-color: var(--red); background: var(--red-bg); color: var(--red); text-decoration: line-through; text-decoration-thickness: 1px; }
.quiz-feedback { margin-top: 12px; font-size: 14px; display: none; }
.quiz-feedback.show { display: block; }
.quiz-feedback.is-correct { color: var(--pine); }
.quiz-feedback.is-wrong { color: var(--red); }

/* ── QUIZ SET (graded on submit) ── */
.quizset-question-block { margin-bottom: 26px; }
.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; }
.quizset-explanation.show { display: block; }
.quizset-submit-btn {
  padding: 10px 22px; border-radius: var(--radius-sm); border: none;
  background: var(--lake); color: var(--white); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.quizset-submit-btn:hover { background: var(--lake-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-size: 14.5px; font-weight: 600; }
.quizset-score-banner.show { display: block; }
.quizset-score-banner.pass { background: var(--pine); color: var(--white); }
.quizset-score-banner.fail { background: var(--amber-soft); color: var(--ink); }

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

/* ── PREV / NEXT FOOTER ── */
.lesson-nav-footer {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  padding: 24px 48px; border-top: 1px solid var(--line); background: var(--white);
}
.nav-btn {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 20px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--white);
  font-size: 14px; cursor: pointer; transition: var(--transition);
  color: var(--ink); text-decoration: none; min-width: 0;
}
.nav-btn:hover { border-color: var(--lake); background: var(--lake-tint); }
.nav-btn-label { font-size: 12px; color: var(--ink-60); }
.nav-btn-title { font-family: var(--font-read); font-weight: 600; font-size: 15.5px; line-height: 1.35; }
.nav-btn.next { text-align: right; }
.nav-btn.disabled { opacity: .4; pointer-events: none; }

/* ── RIGHT RAIL ── */
.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(--lake-dark); font-weight: 600; border-left-color: var(--lake); }
.toc-item.sub a { padding-left: 24px; font-size: 12.5px; }
.toc-empty { font-size: 12.5px; color: var(--ink-60); font-style: italic; padding-left: 12px; }

.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: 3px; flex-shrink: 0; border-left: 3px solid; }

/* ── MOBILE TOGGLE ── */
.mob-toggle {
  display: none; position: fixed; bottom: 20px; right: 20px; z-index: 900;
  height: 44px; padding: 0 20px; border-radius: 22px;
  background: var(--lake); color: var(--white);
  border: none; font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 6px 18px rgba(29,106,134,.45);
}

/* ── 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) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: -310px; top: 0; width: 290px; z-index: 1100;
    transition: left .3s ease; height: 100vh; height: 100dvh;
  }
  .sidebar.open { left: 0; box-shadow: var(--shadow-md); }
  .mob-toggle { display: block; z-index: 1200; }
  .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, .lesson-header::after { width: 70%; opacity: .55; }
  .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 14px; }
  .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 { grid-template-columns: 1fr; }
  .nav-btn.next { text-align: left; }
  .navbar-course-name-hide { display: none; }
}

/* ── SITE FOOTER ── */
.site-footer { background: var(--ink); padding: 30px 32px 18px; border-top: 3px solid var(--maple); }
.site-footer-container { margin: 0 auto; text-align: center; max-width: 640px; }
.site-footer-brand { font-family: var(--font-read); font-size: 19px; font-weight: 700; color: var(--white); margin-bottom: 4px; }
.site-footer-tagline { font-size: 13px; color: rgba(255,255,255,.58); line-height: 1.65; }
.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 {
  padding: 3px 12px; border-radius: 20px;
  background: var(--maple); color: var(--white);
  font-size: 12px; font-weight: 600; text-decoration: none; transition: var(--transition);
}
.site-footer-author-link:hover { background: var(--white); color: var(--maple-dark); }
.site-footer-author-link:focus-visible { outline-color: var(--lake-soft); outline-offset: 3px; }
.site-footer-disclaimer {
  flex: 1; min-width: 0; padding: 8px 14px;
  border-left: 3px solid var(--amber);
  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);
}
.site-footer-disclaimer strong { color: var(--amber); }
.site-footer-disclaimer-btn {
  background: none; border: none; padding: 0; margin-left: 4px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--lake-soft);
  text-decoration: underline; text-underline-offset: 3px;
}
.site-footer-disclaimer-btn:hover { color: var(--white); }
.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); text-align: center;
}
@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; }
  .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; }
}
