/* site/neural-networks/chapter.css — shared layout for the chapter pages.
   Loaded after ../style.css and reuses its tokens (--ink, --accent, --line, --wash, --muted). */

.chapter {
  max-inline-size: 78rem;
}

.chapter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
}

@media (min-width: 1100px) {
  .chapter-grid {
    grid-template-columns: 15rem minmax(0, 1fr);
  }
  .chapter-toc {
    position: sticky;
    inset-block-start: 1rem;
    align-self: start;
    max-block-size: calc(100dvh - 2rem);
    overflow-y: auto;
  }
}

.crumbs {
  font-size: 0.9rem;
  color: var(--muted);
  margin-block-end: 0.5rem;
}

.chapter-toc {
  font-size: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.chapter-toc > ol,
.chapter-toc ol ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-toc ol ol {
  margin-block: 0.25rem 0.75rem;
}

.chapter-toc li li {
  padding-block: 0.2rem;
}

.chapter-toc .toc-part {
  display: block;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chapter-toc a[aria-current="page"] {
  font-weight: 700;
  text-decoration: none;
  border-inline-start: 3px solid var(--accent);
  padding-inline-start: 0.4rem;
}

.chapter-toc .planned {
  color: var(--muted);
}

.prose {
  max-inline-size: 74ch;
  min-inline-size: 0;
}

.prose h2 {
  margin-block-start: 2.5rem;
}

.prose h3 {
  margin-block-start: 1.75rem;
}

.lead {
  font-size: 1.15rem;
}

/* Native MathML: no MathJax, no KaTeX. */
math {
  font-family: "STIX Two Math", "Cambria Math", "Latin Modern Math", "Noto Sans Math", math, serif;
}

/* `display: block math` has to be set explicitly. Measured in Chrome 154 on 2026-10-03: by
   default <math display="block"> computes plain `display: block`, which lays each child out as a
   separate CSS block, so the formula stacks vertically and every fraction bar spans the full
   width. A browser that does not know the two-keyword value drops this declaration and keeps its
   own default. tests/browser.mjs fails if any block formula stops laying out on one line. */
math[display="block"] {
  display: block math;
  margin-block: 1rem;
  padding-block: 0.4rem;
  font-size: 1.2em;
  overflow-x: auto;
  overflow-y: hidden;
}

.equation-note {
  color: var(--muted);
  font-size: 0.92rem;
  margin-block-start: -0.5rem;
}

/* Interactive panels */
.widget {
  border: 1px solid var(--line);
  background: var(--wash);
  border-radius: 8px;
  padding: 1rem;
  margin-block: 1.5rem;
  min-inline-size: 0;
}

.widget h3 {
  margin-block-start: 0;
}

.widget figure {
  margin: 0;
}

.widget canvas {
  display: block;
  inline-size: 100%;
  max-inline-size: 640px;
  block-size: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.widget canvas.draggable {
  touch-action: none;
  cursor: crosshair;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: end;
  margin-block: 0.75rem;
}

.controls label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.controls input[type="range"] {
  inline-size: min(14rem, 100%);
}

.readout {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  margin-block: 0.5rem;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

@media (min-width: 900px) {
  .two-col {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* History timeline */
.timeline {
  list-style: none;
  padding: 0;
  margin-block: 1rem;
  border-inline-start: 2px solid var(--line);
}

.timeline li {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.4rem 0 0.4rem 0.75rem;
}

.timeline .when {
  font-weight: 700;
  color: var(--accent);
}

.callout {
  border-inline-start: 4px solid var(--accent);
  background: var(--wash);
  padding: 0.75rem 1rem;
  margin-block: 1.25rem;
  border-radius: 0 6px 6px 0;
}

.callout > :first-child {
  margin-block-start: 0;
}

.callout > :last-child {
  margin-block-end: 0;
}

.honest {
  font-size: 0.9rem;
  color: var(--muted);
}

/* Hub: the stack */
.nn-stack {
  list-style: none;
  padding: 0;
  margin-block: 1.5rem;
  display: grid;
  gap: 0.6rem;
}

.nn-stack li {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1.15rem;
  background: var(--card, #151d2f);
  color: var(--ink, #f8fafc);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.nn-stack li:hover,
.nn-stack li:active,
.nn-stack li:focus-within {
  border-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.nn-stack li h3 {
  margin: 0.35rem 0 0.5rem;
}

.nn-stack li h3 a {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.nn-stack li h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.nn-stack .part-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #94a3b8);
}

.nn-stack .years {
  color: var(--muted, #94a3b8);
  font-size: 0.9rem;
  margin-inline-start: 0.4rem;
}

.nn-stack li.is-active {
  border-color: #38bdf8;
  box-shadow: inset 4px 0 0 #38bdf8, 0 4px 16px rgba(0, 0, 0, 0.4);
}

.nn-stack li.is-prereq {
  background: #1e293b;
  border-color: #475569;
}

.nn-stack .builds-on {
  font-size: 0.85rem;
  color: var(--muted, #94a3b8);
}

.prev-next {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  border-block-start: 1px solid var(--line);
  margin-block-start: 3rem;
  padding-block-start: 1rem;
}

.matrix {
  border-collapse: collapse;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.matrix td {
  border: 1px solid var(--line);
  padding: 0.2rem 0.4rem;
  text-align: end;
  min-inline-size: 2.4rem;
}

/* Optimiser colours: these match COLORS in gradient-descent.js. */
.swatch {
  display: inline-block;
  inline-size: 0.9em;
  block-size: 0.9em;
  border-radius: 2px;
  margin-inline-end: 0.4em;
  vertical-align: -0.1em;
  outline: 1px solid var(--line);
}

.sw-sgd { background: #d1495b; }
.sw-momentum { background: #f2a541; }
.sw-adagrad { background: #2f9e44; }
.sw-rmsprop { background: #7b2cbf; }
.sw-adam { background: #e83e8c; }
.sw-adamw { background: #111827; }
.sw-alt { background: #8a5a00; }

.sources li {
  margin-block: 0.35rem;
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

/* Code listings and ASCII diagrams keep their columns: no wrapping, scroll sideways on narrow screens. */
.listing {
  margin: 1.25rem 0 0.5rem;
  min-inline-size: 0;
}

.listing figcaption {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  margin-block-end: 0.25rem;
}

.listing pre,
.listing-bad,
.diagram,
.playground pre[data-source] {
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  max-block-size: none;
  margin-block: 0.5rem 1rem;
}

.listing-bad {
  border-inline-start: 4px solid #fb7185;
}

.diagram {
  font-size: 0.82rem;
  line-height: 1.35;
}
