/* Feynman theme -- design tokens + component styling.
   Colour is expressed as CSS custom properties so light/dark is a pure-CSS
   switch driven by the [data-theme] attribute on <html>. The generated
   pygments.css follows the same convention for code tokens.

   The look is a "printed notebook": warm paper, an accent ink, a serif for
   display type and prose, a mono for code and labels. */

:root {
  --paper: #f8f7f3;
  --surface: #fffefa;
  --ink: #242923;
  --body: #4c514b;
  --muted: #73766e;
  --line: #dedfd6;
  --soft: #eeeee6;
  --accent: #a64b35;
  --accent-strong: #913c2a;
  --accent-soft: #f4e7df;
  --success: #38614e;
  --success-soft: #edf2e9;
  --error: #b4232c;
  --error-soft: #f6e6e4;
  /* Callout variants: a readable ink and a paper-toned wash, in the same
     muted register as --success / --success-soft. */
  --info: #2f5c7a;
  --info-soft: #e7eef3;
  --warning: #8a6614;
  --warning-soft: #f5ecd6;
  /* Code surface follows the theme so Pygments' light/dark token colours
     (scoped under :root vs [data-theme=dark]) stay readable in both. */
  --code-bg: #f3f2ea;
  --code-toolbar: #ecebe1;

  --serif: "Source Serif 4", ui-serif, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;

  --measure: 1180px;
  --radius: 5px;
  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #1c221f;
  --surface: #232b26;
  --ink: #eeeee1;
  --body: #c5cbc0;
  --muted: #a5ad9f;
  --line: #3c463d;
  --soft: #2b352e;
  --accent: #e49a7d;
  --accent-strong: #f5b59a;
  --accent-soft: #3b302a;
  --success: #add3b6;
  --success-soft: #283b2e;
  --error: #f2777a;
  --error-soft: #3a2a2b;
  --info: #8fc0dc;
  --info-soft: #24333b;
  --warning: #e0bd6f;
  --warning-soft: #362f20;
  --code-bg: #151b17;
  --code-toolbar: #1f2822;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  color-scheme: light dark;
  scroll-behavior: smooth;
  scroll-padding-top: 100px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.75 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--accent-strong); }

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; background: none; border: 0; color: inherit; }
button:disabled { cursor: default; opacity: 0.35; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
svg { display: block; max-width: 100%; }

.icon {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor;
  stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round;
  flex: 0 0 auto;
}

/* Progressive enhancement: elements that only make sense with JS. */
.js-only { display: none; }
.js .js-only { display: inline-flex; }

.feynman-container {
  width: min(var(--measure), calc(100% - 88px));
  margin-inline: auto;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -100px; left: 24px; z-index: 50;
  background: var(--surface); padding: 10px 16px;
  border: 1px solid var(--accent); border-radius: var(--radius);
}
.skip-link:focus { top: 16px; }

/* --- reading progress ------------------------------------------------ */
.reading-progress {
  position: fixed; inset: 0 auto auto 0; z-index: 30;
  width: 100%; height: 3px;
  background: var(--accent);
  transform: scaleX(0); transform-origin: left;
  pointer-events: none;
}

/* --- header ---------------------------------------------------------- */
.feynman-header {
  position: sticky; top: 0; z-index: 20;
  /* Opaque fallback first: browsers that don't parse color-mix (or drop the
     translucent value) keep a solid header so content never shows through. */
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
/* When the backdrop blur isn't available, keep the header fully opaque so it
   can't reveal the content scrolling beneath it. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .feynman-header { background: var(--paper); }
}
.feynman-header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 72px;
}
.brand { display: flex; align-items: center; gap: 18px; }
.feynman-wordmark {
  font-family: var(--serif);
  font-size: 30px; letter-spacing: -1px; line-height: 1;
}
.feynman-wordmark b { color: var(--accent); font-weight: normal; }
.brand-tag {
  border-left: 1px solid var(--line); padding-left: 18px;
  font-size: 11px; color: var(--muted); line-height: 1.5;
}
.header-actions { display: flex; align-items: center; gap: 24px; }
.header-link { font-size: 12px; color: var(--body); padding-block: 8px; }
.header-link:hover { color: var(--accent); }

/* Home link (collection builds only): icon + label pill matching the header. */
.home-link {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding-inline: 15px;
  border: 1px solid var(--line); border-radius: 19px;
  font-size: 13px; color: var(--ink); text-decoration: none;
}
.home-link:hover { background: var(--soft); color: var(--accent); }
.home-link .icon { width: 15px; height: 15px; }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 50%;
  background: transparent; color: var(--ink);
}
.icon-button:hover { background: var(--soft); }
.sun-icon, [data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }

/* --- hero ------------------------------------------------------------ */
.feynman-hero { padding: 64px 0 44px; }
.hero-kicker {
  display: flex; align-items: center; gap: 12px;
  color: var(--accent); margin: 0 0 22px;
}
.hero-kicker::before { content: ""; width: 26px; height: 1px; background: var(--accent); }
.feynman-title {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(48px, 6.5vw, 76px);
  letter-spacing: -2.4px; line-height: 1.0;
  margin: 0 0 22px;
}
.feynman-title em { color: var(--accent); font-style: italic; }
.feynman-subtitle {
  font-size: 16px; line-height: 1.8; color: var(--body);
  max-width: 40rem; margin: 0;
}
.hero-source { margin: 24px 0 0; }
.hero-source a {
  display: inline-flex; align-items: center; gap: 8px;
  font: 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
.hero-source a:hover { color: var(--accent); border-color: var(--accent); }
.hero-source .icon { width: 14px; height: 14px; }

/* --- document credits and tags --------------------------------------- */
/* The one styling for the authors/date/version row and the tag chips, matching
   the one markup in `meta.html.j2`. A theme adds a `<variant>-meta` /
   `<variant>-tags` class beside these and overrides only what it needs -- these
   rules are what it inherits, so a new theme gets a usable credit line free. */
.doc-meta {
  display: flex; flex-wrap: wrap; gap: 8px 22px;
  margin: 24px 0 0; font-size: 12px; color: var(--muted);
}
.doc-meta strong { color: var(--ink); font-weight: 600; }
.doc-meta a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.doc-tags {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  margin: 16px 0 0;
}
.doc-tags-label {
  font: 600 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
/* The chips themselves: a plain list, stripped of its bullets and indent. */
.doc-tag-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  list-style: none; margin: 0; padding: 0;
}
.doc-tag {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px;
  font: 11px var(--mono); letter-spacing: 0.03em; color: var(--muted);
  background: var(--surface);
}

/* --- notebook layout: sticky TOC + prose ----------------------------- */
.notebook-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 76px;
  padding: 60px 0 80px;
}
.contents { align-self: start; position: sticky; top: 108px; }
.contents h2 { margin: 0 0 20px; font-weight: 400; }
.contents ol {
  margin: 0; padding: 0; list-style: none;
  border-left: 1px solid var(--line);
}
.contents a {
  display: flex; align-items: baseline; gap: 12px;
  font-size: 12px; color: var(--muted); line-height: 1.5;
  padding: 10px 0 10px 16px; margin-left: -1px;
  border-left: 2px solid transparent;
}
.contents a span { font: 10px var(--mono); opacity: 0.8; }
.contents a:hover { color: var(--accent); }
.contents a[aria-current="location"] { color: var(--accent); border-color: var(--accent); }
/* A sub-heading sits under its section: indented by depth, a shade quieter and
   tighter, so the list still reads as an outline rather than a flat run. The
   depth comes from the stamped section number ("2.1" -> depth 2), so the
   indentation matches the number shown beside it. */
.contents .contents-sub a {
  padding-top: 7px; padding-bottom: 7px; padding-left: 30px;
  font-size: 11px; opacity: 0.85;
}
.contents .contents-depth-3 a { padding-left: 42px; opacity: 0.75; }

/* --- prose ----------------------------------------------------------- */
.feynman-prose { min-width: 0; max-width: 815px; }
.feynman-prose h2 {
  font: 400 34px/1.2 var(--serif);
  letter-spacing: -0.6px;
  margin: 52px 0 18px;
}
.feynman-prose > h2:first-child { margin-top: 0; }
.feynman-prose h3 { font: 400 24px/1.3 var(--serif); margin: 36px 0 14px; }
.feynman-prose p { margin: 0 0 20px; color: var(--body); line-height: 1.85; }
.feynman-prose a { color: var(--accent); text-underline-offset: 3px; text-decoration: underline; }
/* Cross-reference link ("Figure 1", "Equation 2"): reads as a unit, so no
   mid-word wrap, and a subtle dotted underline distinguishes it from prose
   links. A broken reference (no matching label) is flagged in the error colour
   so it is caught in review rather than shipped silently. */
.feynman-prose a.feynman-xref {
  white-space: nowrap;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.feynman-xref-broken {
  color: var(--error); font-family: var(--mono); font-size: 0.9em;
  text-decoration: underline wavy;
}
.feynman-prose strong { color: var(--ink); font-weight: 600; }
.feynman-prose ul, .feynman-prose ol { color: var(--body); padding-left: 1.3rem; }
.feynman-prose li { margin: 0.4rem 0; }
/* Strikethrough (`~~text~~`): a retraction, so it recedes rather than shouts. */
.feynman-prose s, .feynman-prose del { color: var(--muted); }
/* Definition lists (`Term` / `:   definition`): the term carries the weight, the
   body is indented under it -- a glossary, which is what authors reach for. */
.feynman-prose dl { margin: 0 0 20px; color: var(--body); }
.feynman-prose dt { margin-top: 16px; color: var(--ink); font-weight: 600; }
.feynman-prose dd { margin: 4px 0 0 1.3rem; line-height: 1.85; }
/* Task lists (`- [x] done`): the checkbox replaces the marker, so drop the
   bullet and pull the row back into the measure. Checkboxes ship disabled -- the
   state is authored in the source, not toggled by the reader. */
.feynman-prose .task-list-item { list-style: none; margin-left: -1.3rem; }
.feynman-prose .task-list-item input[type="checkbox"] {
  margin-right: 0.5rem;
  accent-color: var(--accent);
}
/* Footnotes: the reference is a superscript link, the definitions a smaller
   block at the foot of the prose. The plugin emits its own `<hr
   class="footnotes-sep">` *before* the section; we hide it and use a border on
   the section instead, so the rule matches the measure and the print rules. */
.feynman-prose .footnote-ref { font-size: 0.8em; font-variant-numeric: normal; }
.feynman-prose .footnote-ref a { text-decoration: none; }
.feynman-prose .footnotes-sep { display: none; }
.feynman-prose .footnotes {
  margin: 48px 0 0; padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 0.9em; color: var(--muted);
}
.feynman-prose .footnotes-list { padding-left: 1.3rem; }
.feynman-prose .footnote-item { margin: 0.6rem 0; }
.feynman-prose .footnote-item p { margin: 0 0 8px; line-height: 1.7; }
.feynman-prose .footnote-backref { text-decoration: none; margin-left: 4px; }
.feynman-prose hr { height: 1px; border: 0; background: var(--line); margin: 48px 0; }
.feynman-prose blockquote {
  margin: 24px 0; padding: 4px 0 4px 20px;
  border-left: 2px solid var(--accent);
  color: var(--muted); font: italic 18px/1.6 var(--serif);
}
.feynman-prose code:not(pre code) {
  color: var(--accent-strong); background: var(--accent-soft);
  padding: 2px 5px; border-radius: 3px;
  font: 0.87em var(--mono); white-space: nowrap;
}
/* A table is wrapped in <figure class="feynman-table-figure"> with an optional
   "Table N" caption; the table itself sits in a scroll container so a wide table
   scrolls horizontally rather than overflowing the measure. */
.feynman-prose .feynman-table-figure { margin: 24px 0; }
.feynman-prose .feynman-table-caption {
  margin-bottom: 8px; font: 0.85rem var(--sans); color: var(--muted);
  /* A caption now carries prose, not just the "Table N" label, so it has to wrap
     and lead like a sentence rather than sit on one line. */
  line-height: 1.6;
}
/* Caption prose is Markdown, so it can contain a code span -- which the prose
   rule sets in accent-on-tint at 0.87em. At caption size that reads as a shout;
   quiet it down and let it wrap with the text. */
.feynman-prose .feynman-table-caption code {
  font-size: 0.95em; background: none; color: inherit;
  padding: 0; white-space: normal;
}
.feynman-prose .feynman-table-scroll {
  /* Wide tables scroll horizontally rather than overflowing the measure. A
     max-height makes a long table scroll *within* this box, which is what lets
     the sticky header below actually stick (sticky is scoped to the nearest
     scroll container -- with no height cap here it would never engage). */
  overflow: auto;
  max-height: 75vh;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.feynman-prose table {
  border-collapse: collapse; width: 100%; margin: 0;
  font-size: 0.95rem;
}
.feynman-prose th, .feynman-prose td {
  border-bottom: 1px solid var(--line); padding: 0.5rem 0.75rem; text-align: left;
}
.feynman-prose tbody tr:last-child td { border-bottom: 0; }
.feynman-prose thead th {
  background: var(--soft);
  position: sticky; top: 0; z-index: 1;
}
/* Numeric (right-aligned) cells read best with lined-up, tabular figures. */
.feynman-prose td[style*="text-align:right"],
.feynman-prose th[style*="text-align:right"] {
  font-variant-numeric: tabular-nums;
}

/* Striped + compact variants (opt-in via `.striped` / `.compact`). */
.feynman-prose .feynman-table-striped tbody tr:nth-child(even) { background: var(--soft); }
.feynman-prose .feynman-table-compact th,
.feynman-prose .feynman-table-compact td { padding: 0.3rem 0.6rem; }

/* Sortable headers: a pointer affordance and a caret that reflects aria-sort.
   Enhanced only when JS is on (the runtime adds .feynman-th-sortable). */
.feynman-prose .feynman-th-sortable {
  cursor: pointer; user-select: none; white-space: nowrap;
}
.feynman-prose .feynman-th-sortable::after {
  content: "\2195"; /* up-down arrow, idle */
  margin-left: 0.4em; opacity: 0.35; font-size: 0.85em;
}
.feynman-prose .feynman-th-sortable[aria-sort="ascending"]::after { content: "\2191"; opacity: 0.8; }
.feynman-prose .feynman-th-sortable[aria-sort="descending"]::after { content: "\2193"; opacity: 0.8; }
.feynman-prose .feynman-th-sortable:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* --- maths (native MathML) ------------------------------------------ */
math { font-family: "Cambria Math", "Latin Modern Math", math; }
math[display="inline"] { padding-inline: 2px; font-size: 1.06em; }
.math-error { color: var(--error); font-family: var(--mono); }

.equation-panel {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center; gap: 12px;
  padding: 24px 26px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  margin: 26px 0;
}
.equation-panel math[display="block"] {
  display: block; margin: 0;
  font-size: 1.35rem; color: var(--ink); text-align: left;
}
/* Equation number: the (n) an @eq- reference points at. Sits between the maths
   and the copy button, so the panel is [ equation | (n) | copy ]. */
.equation-number {
  font: 13px var(--mono); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.equation-copy {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--muted);
}
.equation-copy:hover { color: var(--accent); border-color: var(--accent); }
.equation-copy .icon { width: 15px; height: 15px; }

/* Bare (non-panel) block equations still get their own centred line. */
math[display="block"] { display: block; margin: 1.5rem 0; text-align: center; }

/* --- code cards & executed cells ------------------------------------ */
.feynman-code,
.feynman-cell {
  margin: 24px 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
/* Figure / listing number shown in a caption ("Figure 1"), and the target an
   @fig-/@viz- reference lands on. Set in the accent so it reads as a label. */
.feynman-fig-label {
  color: var(--accent-strong);
  font-weight: 600;
}
.code-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--code-toolbar); color: var(--muted);
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  font: 10px var(--mono); letter-spacing: 0.04em;
}
.code-label { display: flex; align-items: center; gap: 8px; text-transform: uppercase; color: var(--body); }
.code-label .icon { width: 14px; height: 14px; }
.copy-button {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); padding: 4px 2px 4px 10px;
  font: 10px var(--mono); letter-spacing: 0.04em;
}
.copy-button:hover { color: var(--accent); }
.copy-button .icon { width: 13px; height: 13px; }

/* Pygments sets its own .highlight background/colour (light under :root, dark
   under [data-theme=dark]); we only need layout + font here. */
.feynman-code .highlight,
.feynman-cell .highlight {
  margin: 0;
}
.feynman-code .highlight pre,
.feynman-cell .highlight pre {
  margin: 0; padding: 20px;
  overflow-x: auto;
  font: 12px/1.85 var(--mono);
  tab-size: 4;
  scrollbar-width: thin;
}

.feynman-cell-output {
  background: var(--success-soft);
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.output-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--success); font: 9px var(--mono);
  letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 8px;
}
.output-label .icon { width: 12px; height: 12px; }
.feynman-output-text,
.feynman-output-error {
  margin: 0;
  font: 12px/1.7 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.feynman-output-text { color: var(--success); }
.feynman-output-error { color: var(--error); }
.feynman-output-figure { background: var(--surface); padding: 12px; border-radius: var(--radius); }
.feynman-output-figure svg,
.feynman-output-figure img { max-width: 100%; height: auto; display: block; margin-inline: auto; }
.feynman-output-html { overflow-x: auto; background: var(--surface); padding: 12px; border-radius: var(--radius); }

/* --- callout boxes --------------------------------------------------- */
/* A soft, variant-tinted wash with a coloured left rule, modelled on the
   executed-cell output block. Colour comes from the variant tokens, so the
   box recolours with the theme; per-variant rules only swap those two vars. */
.feynman-box {
  margin: 24px 0;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  background: var(--info-soft);
}
.feynman-box-info { border-left-color: var(--info); background: var(--info-soft); }
.feynman-box-warning { border-left-color: var(--warning); background: var(--warning-soft); }
.feynman-box-error { border-left-color: var(--error); background: var(--error-soft); }

/* Header row (icon + title), styled like .output-label. */
.feynman-box-title {
  display: flex; align-items: center; gap: 8px;
  font: 10px var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 8px;
}
/* A titleless box floats its icon at the top-left as a small variant marker. */
.feynman-box > .feynman-box-icon {
  float: left; margin: 1px 10px 4px 0;
}
/* A touch larger than the shared .icon, and a heavier stroke so the interior
   marks (the i's dot, the ! ) stay crisp at this small size. */
.feynman-box-icon .icon { width: 17px; height: 17px; stroke-width: 2; }
.feynman-box > .feynman-box-icon .icon { width: 19px; height: 19px; }
.feynman-box-info .feynman-box-title,
.feynman-box-info > .feynman-box-icon { color: var(--info); }
.feynman-box-warning .feynman-box-title,
.feynman-box-warning > .feynman-box-icon { color: var(--warning); }
.feynman-box-error .feynman-box-title,
.feynman-box-error > .feynman-box-icon { color: var(--error); }

/* The body is ordinary prose; trim the outer margins so the padding reads
   evenly, and clear the floated icon of a titleless box. */
.feynman-box > :last-child { margin-bottom: 0; }
.feynman-box-title + * { margin-top: 0; }
.feynman-box::after { content: ""; display: block; clear: both; }

/* --- viz ------------------------------------------------------------- */
.feynman-viz-figure { margin: 26px 0; }
feynman-viz {
  display: block;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  padding: 20px 24px;
}
.feynman-viz-figure figcaption {
  color: var(--muted); font-size: 11px; line-height: 1.75;
  margin-top: 12px;
}

/* --- scroll-driven viz (:::viz {... scroll}) -------------------------- */
/* The drawing AND its caption header (the "Figure N" label + intro prose)
   share one sticky block, so they pin together and the header never orphans
   above the figure. Only the ::: step waypoints -- moved into .fv-scroll-steps
   -- scroll past, each tall enough to give the reader a beat per step. With no
   JS the sticky positioning is harmless and the waypoints read as normal prose. */
.feynman-viz-scroll .fv-sticky {
  position: sticky; top: 12vh; z-index: 1;
  background: var(--paper);
}
/* The pinned caption header sits under the drawing, inside the sticky block. */
.feynman-viz-scroll .fv-sticky figcaption { margin-top: 12px; }
.feynman-viz-scroll .fv-scroll-steps { margin-top: 8px; }
.feynman-viz-scroll .fv-scroll-step {
  min-height: 46vh;
  display: flex; flex-direction: column; justify-content: center;
  font-size: 15px; line-height: 1.7; color: var(--muted);
  border-left: 2px solid var(--line); padding-left: 16px;
  transition: color 200ms ease, border-color 200ms ease;
}
/* The active waypoint (nearest the reading line) is highlighted so the reader
   sees which step the drawing is showing. JS sets aria-current on it. */
.feynman-viz-scroll .fv-scroll-step[aria-current] {
  border-left-color: var(--accent); color: var(--ink);
}
/* Trim the last waypoint's tail so the figure unpins promptly after the final
   step rather than leaving a long empty scroll gap. */
.feynman-viz-scroll .fv-scroll-step:last-child { min-height: 30vh; }
@media (prefers-reduced-motion: reduce) {
  .fv-cell, .fv-dot, .feynman-viz-scroll .fv-scroll-step { transition: none; }
}

/* --- embedded figures (:::figure) ------------------------------------ */
/* An external SVG inlined into the body. Framed like a viz block so the two
   read as one family; the SVG scales to the column width. */
.feynman-figure { margin: 26px 0; }
.feynman-figure-svg {
  max-width: 100%; height: auto; display: block; margin-inline: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 20px 24px;
}
/* theme=auto only: the root carries --ink so `currentColor` marks follow the
   theme and flip in dark mode. Verbatim figures get no colour override. */
.feynman-figure-themed { color: var(--ink); }
.feynman-figure figcaption {
  color: var(--muted); font-size: 11px; line-height: 1.75;
  margin-top: 12px;
}
.feynman-figure-missing {
  color: var(--muted); border: 1px dashed var(--line);
  border-radius: var(--radius); background: var(--surface);
  padding: 20px 24px; text-align: center; font-size: 12px;
}

/* viz internals (rendered by feynman.js) */
.fv-grid, .fv-radial, .fv-wave, .fv-fourier, .fv-galton {
  width: 100%; height: auto; display: block; margin-inline: auto;
}
.fv-grid { max-width: 420px; }
.fv-radial { max-width: 340px; }
.fv-wave { max-width: 460px; }
.fv-fourier { max-width: 460px; }
.fv-galton { max-width: 460px; }
.fv-cell { transition: fill 200ms ease, opacity 200ms ease; }

/* radial sweep */
.fv-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.fv-dot { transition: fill 200ms ease, opacity 200ms ease; }
.fv-sweep {
  stroke: var(--accent); stroke-width: 2; stroke-linecap: round;
  opacity: 0.85; transition: none;
}

/* travelling wave */
.fv-axis { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.fv-wave-path { stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.fv-wave-dot { fill: var(--accent); }

/* fourier synthesiser */
.fv-fourier-target { fill: none; stroke: var(--muted); stroke-width: 1.4; stroke-dasharray: 4 5; opacity: 0.55; }
.fv-fourier-sum { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }

/* galton board. Every marble is the same accent colour -- the shape of the
   pile, not any per-ball hue, carries the meaning. The newest marble drops
   through the pegs (.fv-ball-live) in that same colour. */
.fv-peg { fill: var(--muted); opacity: 0.55; }
.fv-galton-floor { stroke: var(--line); stroke-width: 1; }
.fv-galton-target { stroke: var(--muted); stroke-width: 1.4; stroke-dasharray: 4 5; opacity: 0.6; }
.fv-ball { fill: var(--accent); stroke: var(--surface); stroke-width: 0.75; }
.fv-controls {
  display: flex; align-items: center; gap: 0.75rem;
  flex-wrap: wrap; row-gap: 12px;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--line);
  font: 10px var(--mono); color: var(--muted);
}
.fv-controls button {
  border: 1px solid var(--line); background: var(--paper);
  color: var(--body); border-radius: 4px;
  padding: 0.3rem 0.65rem; font: inherit;
}
.fv-controls button:hover { border-color: var(--accent); color: var(--accent); }
/* Keep a usable track: when the buttons + readout leave too little room, the
   slider wraps to its own line rather than collapsing to a bare thumb. */
.fv-controls input[type="range"] { flex: 1 1 140px; accent-color: var(--accent); min-width: 120px; }
.fv-step { text-align: right; color: var(--body); margin-left: auto; }

/* --- footer ---------------------------------------------------------- */
.feynman-footer {
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 11px;
  padding-block: 24px 30px;
}
.footer-inner { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.footer-inner a { font-family: var(--serif); font-size: 18px; color: var(--ink); }

/* --- toast ----------------------------------------------------------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; z-index: 40;
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 12px; padding: 10px 17px; border-radius: var(--radius);
  box-shadow: 0 3px 15px #0003;
  max-width: calc(100% - 32px);
}
.toast:empty { display: none; }

/* --- collection search + listing ------------------------------------- */
/* The search form is `.js-only`: without JS the static post list stands alone.
   `.js .js-only` sets inline-flex globally, so re-declare it as a full-width
   block for this multi-line form. */
.js .search-form {
  display: block;
  width: 100%;
  max-width: 640px;
  margin-top: 26px;
}
.search-input {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--sans);
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-input:disabled { opacity: 0.6; cursor: not-allowed; }
.search-status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 8px 2px 0;
  min-height: 1.2em;
}
.search-status:empty { display: none; }

.search-layout {
  /* Breathing room before the footer so the last card never abuts it. */
  padding-bottom: 72px;
}
.post-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--measure);
  display: grid;
  gap: 18px;
}
.post-card { margin: 0; }
.post-card[hidden] { display: none; }
.post-card-link {
  display: block;
  padding: 22px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.post-card-link:hover,
.post-card-link:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px #0000000f;
}
.post-date {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}
.post-title {
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.2;
  color: var(--ink);
  margin: 0;
}
.post-subtitle {
  color: var(--body);
  margin: 8px 0 0;
  line-height: 1.5;
}
/* A card's tags: the shared chips in the accent ink, so they read as the card's
   own subject line rather than repeating the muted subtitle beneath. */
.post-tags { margin-top: 12px; }
.post-tags .doc-tag { color: var(--accent); background: var(--paper); }
.search-empty {
  text-align: center;
  color: var(--muted);
  margin: 40px 0;
}

/* --- responsive ------------------------------------------------------ */
@media (max-width: 1080px) {
  .feynman-container { width: calc(100% - 64px); }
  .notebook-layout { gap: 38px; grid-template-columns: 176px minmax(0, 1fr); }
  .contents a { font-size: 11px; gap: 10px; padding-left: 12px; }
  .highlight pre { font-size: 11px; }
}
@media (max-width: 820px) {
  .notebook-layout { display: block; padding-top: 42px; }
  /* Compound selector (.contents.js-only) so this beats `.js .js-only`, which
     is equally specific but sets display:inline-flex; otherwise the sticky TOC
     stays visible and overlays the prose on mobile. */
  .contents,
  .contents.js-only { display: none; }
  .feynman-prose { max-width: 100%; }
  .highlight pre { font-size: 12px; }
}
@media (max-width: 580px) {
  html { scroll-padding-top: 84px; }
  .feynman-container { width: calc(100% - 40px); }
  .feynman-header-inner { height: 62px; }
  .brand-tag { display: none; }
  .feynman-hero { padding: 40px 0 32px; }
  .feynman-prose h2 { font-size: 28px; }
  .highlight pre { font-size: 11px; }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  :root, [data-theme="dark"] {
    --paper: #fff; --surface: #fff; --ink: #20251f; --body: #3b4039;
    --muted: #62665f; --line: #ddd; --accent: #91432e;
    --success: #365742; --success-soft: #f4f7f1; --code-toolbar: #f0efe8;
  }
  .feynman-header, .header-actions, .contents, .reading-progress,
  .fv-controls, .copy-button, .equation-copy, .toast { display: none !important; }
  .notebook-layout { display: block; }
  .feynman-code .highlight pre, .feynman-cell .highlight pre { white-space: pre-wrap; }
  figure, .equation-panel, h2 { break-inside: avoid; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
