/* ============================================================
   Explainer design system — dark, high-contrast, one continuous
   surface with the videos (VIDEO_BG == --surface).
   ============================================================ */

/* ---------- fonts ---------- */
@font-face {
  font-family: "Inter";
  src: url("../vendor/InterVariable.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../vendor/InterVariable-Italic.woff2") format("woff2");
  font-weight: 100 900; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../vendor/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../vendor/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../vendor/JetBrainsMono-Italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}

/* ---------- tokens ---------- */
:root {
  --bg: #0B0F14;
  --surface: #0E141D;      /* MUST equal manim VIDEO_BG */
  --elev: #101724;
  --border: #1D2938;
  --text: #E8EDF2;
  --muted: #9CAFC3;
  --faint: #64788C;
  --mint: #4FE3C1;
  --amber: #FFC24B;
  --violet: #B79BFF;
  --blue: #5BA8FF;
  --red: #FF6B81;
  --mint-dim: rgba(79, 227, 193, 0.12);
  --amber-dim: rgba(255, 194, 75, 0.12);
  --violet-dim: rgba(183, 155, 255, 0.12);
  --blue-dim: rgba(91, 168, 255, 0.12);
  --red-dim: rgba(255, 107, 129, 0.12);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --content-w: 760px;
  --sidebar-w: 292px;
  --toc-w: 224px;
  --radius: 12px;
  --radius-sm: 8px;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 5rem; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 17px; line-height: 1.75;
  font-optical-sizing: auto; text-rendering: optimizeLegibility;
}
::selection { background: rgba(79, 227, 193, 0.28); }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; border-radius: 2px; }
img, svg, video { max-width: 100%; height: auto; }
a { color: var(--mint); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- app layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.main { min-width: 0; display: flex; justify-content: center; gap: 2.5rem; padding: 0 1.5rem; }
.article-col { width: 100%; max-width: var(--content-w); padding-bottom: 6rem; }

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.4rem 1.1rem 2rem; scrollbar-width: thin;
}
.sidebar .site-title {
  font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em;
  color: var(--text); display: block; line-height: 1.3; margin-bottom: .2rem;
}
.sidebar .site-title:hover { text-decoration: none; color: var(--mint); }
.sidebar .site-sub { font-size: .78rem; color: var(--faint); margin: 0 0 1.2rem; line-height: 1.45; }
.nav-part { margin-top: 1.25rem; }
.nav-part > .part-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .12em; color: var(--faint); margin: 0 0 .4rem .5rem;
}
.nav-part a {
  display: flex; gap: .55rem; align-items: baseline;
  padding: .34rem .55rem; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .86rem; line-height: 1.35;
}
.nav-part a .n { font-family: var(--mono); font-size: .68rem; color: var(--faint); min-width: 1.2em; text-align: right; }
.nav-part a:hover { background: var(--elev); color: var(--text); text-decoration: none; }
.nav-part a.active { background: var(--mint-dim); color: var(--mint); font-weight: 600; }
.nav-part a.active .n { color: var(--mint); }
.sister-link {
  display: block; margin-top: 1.6rem; padding: .7rem .8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .8rem; color: var(--muted); line-height: 1.4;
}
.sister-link b { display: block; color: var(--text); font-size: .84rem; }
.sister-link:hover { border-color: var(--mint); text-decoration: none; }
.sister-link .arrow { color: var(--mint); }

/* ---------- mobile topbar ---------- */
.topbar {
  display: none; position: sticky; top: 0; z-index: 40;
  background: rgba(11, 15, 20, 0.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: .65rem 1rem; align-items: center; gap: .8rem;
}
.topbar .burger {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); width: 40px; height: 40px; font-size: 1.1rem;
  cursor: pointer; flex: none; display: grid; place-items: center;
}
.topbar .crumb { font-size: .86rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 45; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; width: min(84vw, 330px);
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.4);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; }
  .main { padding: 0 1.1rem; }
}

/* ---------- right TOC rail ---------- */
.toc { display: none; }
@media (min-width: 1460px) {
  .toc {
    display: block; width: var(--toc-w); flex: none;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 2.6rem 0 2rem; font-size: .8rem;
  }
  .toc .toc-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin-bottom: .6rem; }
  .toc a { display: block; color: var(--muted); padding: .22rem 0 .22rem .75rem; border-left: 2px solid var(--border); line-height: 1.4; }
  .toc a:hover { color: var(--text); text-decoration: none; }
  .toc a.current { color: var(--mint); border-left-color: var(--mint); }
}

/* ---------- chapter header ---------- */
.ch-header { padding: 3.2rem 0 1rem; }
.ch-header .kicker {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--mint); margin-bottom: .9rem;
}
.ch-header h1 {
  font-size: clamp(1.9rem, 4.5vw, 2.6rem); line-height: 1.12;
  letter-spacing: -0.022em; font-weight: 750; margin: 0 0 .55rem;
}
.ch-header .subtitle { font-size: 1.12rem; color: var(--muted); line-height: 1.55; margin: 0 0 1.3rem; max-width: 58ch; }
.need { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; margin-bottom: .6rem; }
.need .need-label { font-size: .74rem; color: var(--faint); margin-right: .15rem; }
.need a {
  font-size: .74rem; color: var(--muted); background: var(--elev);
  border: 1px solid var(--border); border-radius: 999px; padding: .18rem .7rem;
  line-height: 1.5;
}
.need a:hover { color: var(--mint); border-color: var(--mint); text-decoration: none; }
.ch-header hr { border: none; border-top: 1px solid var(--border); margin: 1.6rem 0 0; }

/* ---------- article typography ---------- */
article section { margin: 2.6rem 0; }
article h2 {
  font-size: 1.42rem; font-weight: 700; letter-spacing: -0.015em;
  line-height: 1.25; margin: 0 0 1rem; scroll-margin-top: 5rem;
}
article h2 .anchor { opacity: 0; font-weight: 400; color: var(--faint); margin-left: .4rem; font-size: .9em; }
article h2:hover .anchor { opacity: 1; }
article h3 { font-size: 1.08rem; font-weight: 650; margin: 1.6rem 0 .6rem; }
article p { margin: 0 0 1.1rem; }
article ul, article ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }
article li { margin-bottom: .45rem; }
article strong { font-weight: 650; color: #fff; }
article em { font-style: italic; }

/* plain-English reading of an equation */
.reading {
  border-left: 3px solid var(--mint); background: var(--mint-dim);
  padding: .7rem 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text); font-size: .95rem;
}

/* jargon definitions */
dfn { font-style: normal; font-weight: 600; color: var(--text); border-bottom: 1.5px dotted var(--mint); cursor: help; position: relative; }
dfn::after {
  content: attr(data-def); position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%); width: max-content; max-width: 280px;
  background: var(--elev); color: var(--muted); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .5rem .75rem; font-size: .78rem;
  font-weight: 400; line-height: 1.5; text-align: left;
  opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
dfn:hover::after, dfn:focus::after { opacity: 1; }

/* math */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .35rem 0; }
.katex { font-size: 1.06em; }

/* code */
code, pre { font-family: var(--mono); }
code { background: var(--elev); border: 1px solid var(--border); border-radius: 5px; padding: .1em .38em; font-size: .84em; }
pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; overflow-x: auto; line-height: 1.6; font-size: .84rem; }
pre code { background: none; border: none; padding: 0; }

/* tables */
article table { border-collapse: collapse; width: 100%; margin: 0 0 1.2rem; font-size: .92rem; display: block; overflow-x: auto; }
article th, article td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
article th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- callouts ---------- */
.callout {
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius);
  padding: 1rem 1.2rem .55rem; margin: 1.5rem 0; background: var(--surface);
}
.callout h4 {
  margin: 0 0 .5rem; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em; display: flex; align-items: center; gap: .45rem;
}
.callout h4::before { font-size: .95rem; }
.callout p, .callout ul { font-size: .95rem; margin-bottom: .55rem; }
.callout.note  { border-left-color: var(--mint);  } .callout.note h4  { color: var(--mint); }  .callout.note h4::before  { content: "✦"; }
.callout.why   { border-left-color: var(--violet);} .callout.why h4   { color: var(--violet);} .callout.why h4::before   { content: "◆"; }
.callout.myth  { border-left-color: var(--red);   } .callout.myth h4  { color: var(--red); }   .callout.myth h4::before  { content: "✕"; }
.callout.math  { border-left-color: var(--amber); } .callout.math h4  { color: var(--amber); } .callout.math h4::before  { content: "∑"; }
.callout.try   { border-left-color: var(--blue);  } .callout.try h4   { color: var(--blue); }  .callout.try h4::before   { content: "▶"; }

/* worked example */
.worked {
  background: var(--elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.3rem .6rem; margin: 1.5rem 0;
}
.worked h4 {
  margin: 0 0 .7rem; font-size: .78rem; font-weight: 700; color: var(--amber);
  text-transform: uppercase; letter-spacing: .09em;
}
.worked h4::before { content: "✎ "; }
.worked p { font-size: .96rem; }

/* ---------- figures / videos / widgets ---------- */
.fig { margin: 1.8rem 0; }
.fig img { display: block; margin: 0 auto; border-radius: var(--radius-sm); }
figcaption { font-size: .84rem; color: var(--muted); line-height: 1.6; margin-top: .7rem; padding: 0 .2rem; }
figcaption strong { color: var(--text); font-weight: 650; }

.video-card {
  margin: 1.8rem 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.video-card video { display: block; width: 100%; background: var(--surface); }
.video-card figcaption { padding: .8rem 1.1rem 1rem; margin: 0; border-top: 1px solid var(--border); }

.widget {
  margin: 1.8rem 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.widget .widget-title {
  padding: .6rem 1.1rem; font-size: .78rem; font-weight: 700; color: var(--blue);
  text-transform: uppercase; letter-spacing: .09em; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.widget .widget-title::before { content: "⟡ interactive"; color: var(--faint); font-weight: 400; letter-spacing: .05em; order: 2; font-size: .68rem; }
.widget .widget-body { padding: 1rem 1.1rem 1.2rem; }
.widget svg text { font-family: var(--sans); }
.widget button, .widget .wbtn {
  font: 600 .8rem var(--sans); color: var(--text); background: var(--elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .45rem .9rem; cursor: pointer; min-height: 38px;
}
.widget button:hover { border-color: var(--mint); color: var(--mint); }
.widget button.primary { background: var(--mint-dim); border-color: var(--mint); color: var(--mint); }
.widget input[type="range"] { accent-color: var(--mint); }
.widget .readout { font-family: var(--mono); font-size: .82rem; color: var(--amber); }

/* ---------- recap + bridge ---------- */
.recap {
  background: linear-gradient(180deg, var(--mint-dim), transparent 140%);
  border: 1px solid rgba(79, 227, 193, .35); border-radius: var(--radius);
  padding: 1.3rem 1.5rem .7rem; margin: 3rem 0 1.5rem;
}
.recap h2 { font-size: 1.05rem; color: var(--mint); margin-bottom: .8rem; }
.recap ul { margin: 0 0 .8rem; }
.recap li { margin-bottom: .55rem; font-size: .96rem; }

/* ---------- prev / next ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 3rem 0 0; }
.pager a {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.2rem; color: var(--muted); line-height: 1.4; background: var(--surface);
}
.pager a:hover { border-color: var(--mint); text-decoration: none; }
.pager a .dir { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); display: block; margin-bottom: .3rem; }
.pager a .t { color: var(--text); font-weight: 650; font-size: .95rem; }
.pager a.next { text-align: right; }
.pager a.prev:empty, .pager a.next:empty { visibility: hidden; }
@media (max-width: 560px) { .pager { grid-template-columns: 1fr; } .pager a.next { text-align: left; } }

/* ---------- landing (index) pages ---------- */
body.landing .article-col { max-width: 880px; }
.hero { padding: 4.5rem 0 2.5rem; }
.hero .kicker { font-family: var(--mono); font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mint); margin-bottom: 1rem; }
.hero h1 { font-size: clamp(2.3rem, 6vw, 3.4rem); line-height: 1.06; letter-spacing: -0.028em; font-weight: 800; margin: 0 0 1rem; }
.hero .tagline { font-size: 1.22rem; color: var(--muted); max-width: 56ch; line-height: 1.6; margin: 0 0 2rem; }
.hero .cta { display: inline-block; background: var(--mint); color: #06281F; font-weight: 700; padding: .8rem 1.6rem; border-radius: 999px; font-size: .95rem; }
.hero .cta:hover { text-decoration: none; filter: brightness(1.08); }

.intro-card {
  display: flex; gap: 1.3rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem 1.7rem; margin: 1rem 0 2.5rem;
}
.intro-card .avatar {
  flex: none; width: 54px; height: 54px; border-radius: 50%;
  background: var(--mint-dim); border: 1px solid var(--mint);
  display: grid; place-items: center; font-weight: 800; color: var(--mint); font-size: 1.15rem;
}
.intro-card p { margin-bottom: .8rem; font-size: 1rem; }
.intro-card p:last-child { margin-bottom: 0; }

.part-grid { display: grid; gap: 1.2rem; margin: 2rem 0 3rem; }
.part-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem 1.6rem; }
.part-card .part-kicker { font-family: var(--mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); margin-bottom: .3rem; }
.part-card h2 { font-size: 1.25rem; margin: 0 0 .35rem; }
.part-card .blurb { color: var(--muted); font-size: .92rem; margin: 0 0 1rem; }
.part-card ol { margin: 0; padding: 0; list-style: none; }
.part-card ol a {
  display: flex; gap: .7rem; align-items: baseline; padding: .42rem .6rem;
  margin: 0 -0.6rem; border-radius: var(--radius-sm); color: var(--muted); font-size: .92rem;
}
.part-card ol a:hover { background: var(--elev); color: var(--text); text-decoration: none; }
.part-card ol a .n { font-family: var(--mono); font-size: .72rem; color: var(--mint); min-width: 1.4em; text-align: right; }
.part-card ol a .sub { color: var(--faint); font-size: .8rem; display: block; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border); margin-top: 4rem; padding: 1.8rem 0 0;
  font-size: .82rem; color: var(--faint); line-height: 1.6;
}
.site-footer a { color: var(--muted); }
