/* =========================================================
   Deep Learning, from the ground up — Distill-style stylesheet
   ========================================================= */

:root {
  --bg: #fbfaf6;
  --bg-soft: #f4f1e8;
  --ink: #1a1a1a;
  --ink-soft: #44423d;
  --muted: #8a877f;
  --line: #e6e1d1;
  --line-strong: #c9c2ad;
  --accent: #c84e1d;     /* signal red — for activations, gradients */
  --accent-2: #1f6feb;   /* signal blue — for weights, data */
  --accent-3: #1a7a4c;   /* signal green — for outputs */
  --accent-4: #b8860b;   /* memory amber — for LSTM cell state */
  --accent-soft: #f6e4d8;
  --accent-2-soft: #dde7f7;
  --accent-3-soft: #d6e8de;
  --accent-4-soft: #f1e4c2;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --rail-w: 264px;
  --reader-max: 880px;
  --wide-max: 1100px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ============================================================
   Side rail
   ============================================================ */
.rail {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--rail-w);
  border-right: 1px solid var(--line);
  background: var(--bg);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  font-size: 13px;
}
.rail-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.rail-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.rail-list {
  list-style: none;
  margin: 0; padding: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}
.rail-list::-webkit-scrollbar { width: 4px; }
.rail-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 2px; }
.rail-list li {
  display: flex;
  gap: 10px;
  padding: 6px 8px;
  margin: 1px -8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
  align-items: baseline;
}
.rail-list li:hover { background: var(--bg-soft); color: var(--ink); }
.rail-list li.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}
.rail-list li.active .rail-num { color: var(--accent); }
.rail-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  min-width: 22px;
  letter-spacing: 0.02em;
}
.rail-section {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 14px !important;
  padding: 4px 0 2px !important;
  cursor: default !important;
  pointer-events: none;
  border-top: 1px dashed var(--line);
}
.rail-section:hover { background: transparent !important; }
.rail-foot {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}
.rail-progress {
  width: 100%;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.rail-progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .2s;
}
.rail-foot-meta {
  display: flex; gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* ============================================================
   Reader column
   ============================================================ */
.reader {
  margin-left: var(--rail-w);
  padding: 0 80px;
}
.screen {
  max-width: var(--reader-max);
  margin: 0 auto;
  padding: 96px 0;
  border-bottom: 1px solid var(--line);
}
.screen:last-child { border-bottom: none; }

/* ============================================================
   Cover
   ============================================================ */
.cover {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 32px;
  padding: 80px 0 60px !important;
}
.cover-header { padding-top: 40px; }
.kicker {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 24px;
}
.cover-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(48px, 7vw, 84px);
  line-height: 1.02;
  letter-spacing: -0.025em;
  margin: 0 0 28px;
  text-wrap: balance;
}
.cover-title em {
  font-style: italic;
  color: var(--accent);
  font-weight: 400;
}
.cover-sub {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 640px;
  font-weight: 400;
  text-wrap: pretty;
}
.cover-sub b { font-weight: 600; color: var(--ink); }
.cover-figure {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
}
.cover-meta {
  display: grid;
  grid-template-columns: repeat(4, auto) 1fr;
  align-items: center;
  gap: 36px;
  border-top: 1px solid var(--line);
  padding-top: 28px;
}
.cover-meta > div { display: flex; flex-direction: column; gap: 2px; }
.meta-num {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}
.meta-lbl {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}
.cover-cta { justify-self: end; }

/* ============================================================
   Section structure
   ============================================================ */
.section-head { margin-bottom: 48px; }
.section-eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.screen h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(34px, 4.5vw, 48px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 20px;
  text-wrap: balance;
}
.screen h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 56px 0 16px;
}
.screen h4 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 32px 0 10px;
}
.section-lede {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.5;
  color: var(--ink-soft);
  font-weight: 400;
  text-wrap: pretty;
  margin: 0;
}

/* ============================================================
   Prose
   ============================================================ */
.prose p {
  font-size: 17px;
  line-height: 1.75;
  margin: 0 0 18px;
  color: var(--ink);
  text-wrap: pretty;
}
.prose b, .prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.prose ul, .prose ol { padding-left: 22px; margin: 0 0 18px; }
.prose li { margin-bottom: 6px; }

.aside {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  border-left: 2px solid var(--accent);
  padding: 8px 18px;
  margin: 24px 0;
  background: var(--accent-soft);
}

.callout {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px 22px;
  margin: 24px 0;
}
.callout-title {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 8px;
}
.callout p:last-child { margin-bottom: 0; }

/* ============================================================
   Equations
   ============================================================ */
.eq {
  font-family: var(--serif);
  font-size: 22px;
  text-align: center;
  padding: 18px 0;
  margin: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  letter-spacing: 0.01em;
}
.eq .var { font-style: italic; }
.eq .sub { font-size: 0.7em; vertical-align: sub; }
.eq .sup { font-size: 0.7em; vertical-align: super; }
.eq .op { color: var(--muted); margin: 0 6px; }
.eq .lbl {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 8px;
  font-style: normal;
}

/* ============================================================
   Figures (animations)
   ============================================================ */
.fig {
  margin: 32px -40px;
  padding: 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.fig.fig-soft { background: var(--bg-soft); }
.fig.fig-wide {
  margin-left: -110px;
  margin-right: -110px;
}
.fig.fig-dark {
  background: #161513;
  border-color: #2a2724;
  color: #e8e3d2;
}
.fig svg { display: block; max-width: 100%; height: auto; }

.caption {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  margin: -16px 0 32px;
  padding: 0 12px;
  text-wrap: pretty;
}

.fig-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.fig-controls .ctrl-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.fig-controls input[type=range] {
  flex: 1;
  min-width: 120px;
}
.fig-controls .ctrl-value {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  min-width: 60px;
  text-align: right;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary, .btn-ghost {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 3px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: all .15s;
  letter-spacing: 0.01em;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ============================================================
   Card row (the 4-architecture grid in orientation)
   ============================================================ */
.card-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 24px 0;
}
.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 20px;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--line-strong); }
.card-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 2px;
  margin-bottom: 8px;
}
.card-h {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 4px;
}
.card-b {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
}

/* ============================================================
   Code blocks
   ============================================================ */
.code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: #161513;
  color: #e8e3d2;
  border-radius: 4px;
  padding: 22px 26px;
  margin: 24px -40px;
  overflow-x: auto;
  white-space: pre;
  position: relative;
}
.code-tag {
  position: absolute;
  top: 10px; right: 14px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9a9485;
}
.code .kw { color: #ff8c61; }
.code .fn { color: #6fc2d4; }
.code .str { color: #c8d97c; }
.code .num { color: #d9b66f; }
.code .com { color: #6e6a5e; font-style: italic; }
.code .var { color: #e8e3d2; }

/* ============================================================
   Two-column figure layout
   ============================================================ */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  align-items: start;
  margin: 28px 0;
}
.split-wide { grid-template-columns: 1.4fr 1fr; }

/* ============================================================
   Stat / pill rows
   ============================================================ */
.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

/* ============================================================
   HUD (bottom right nav)
   ============================================================ */
.hud {
  position: fixed;
  bottom: 24px; right: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 60;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 10px 6px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
}
.hud-time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.hud-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
}
.hud-btn:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ============================================================
   Animation token: subtle reveal as sections enter
   ============================================================ */
.screen { opacity: 0.4; transition: opacity .5s; }
.screen.in-view { opacity: 1; }

/* highlight color tokens we'll reuse in figures */
.tok-data { color: var(--accent-2); }
.tok-act  { color: var(--accent); }
.tok-mem  { color: var(--accent-4); }
.tok-out  { color: var(--accent-3); }

/* fig title */
.fig-title {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.fig-title strong { color: var(--ink); font-weight: 600; }

/* responsive shrink */
@media (max-width: 1100px) {
  .reader { padding: 0 40px; }
  .fig.fig-wide { margin-left: -40px; margin-right: -40px; }
  .code { margin-left: -20px; margin-right: -20px; }
}
@media (max-width: 900px) {
  :root { --rail-w: 0px; }
  .rail { display: none; }
  .reader { padding: 0 24px; }
  .card-row { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .cover-meta { grid-template-columns: 1fr 1fr; gap: 20px; }
  .fig { margin-left: 0; margin-right: 0; }
  .code { margin-left: 0; margin-right: 0; }
}
