/* ==========================================================================
   essay-kit base stylesheet — structure only, no palette.
   ==========================================================================

   A consuming site supplies the tokens below in its own main.css, loaded
   AFTER this file. Nothing here hardcodes a colour, a typeface or a corner
   radius; a site's whole visual identity lives in its token block.

   Required tokens:
     --paper --paper-2 --paper-3          surfaces, lightest to deepest
     --ink --ink-2 --ink-3                text, strongest to faintest
     --rule --rule-2                      borders
     --c-a … --c-e, --c-warn              accent roles; --c-a is "the subject"
     --fig-ink --fig-soft --fig-faint     figure line weights
     --tint --tint-strong                 fill percentages
     --font-body --font-ui --font-mono
     --measure                            reading column width
     --radius                             corner radius
     --shadow

   Two rules the whole thing depends on:

   1. Figures are inline SVG carrying semantic classes, never colours, so one
      figure renders correctly in both themes with no duplication.
   2. The stroke palette excludes `text`. A colour class means a stroke on a
      shape and a fill on a label; without the exclusion, coloured labels are
      outlined in their own colour and render doubled and smeared.
   ========================================================================== */

*, *::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: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: clamp(1.02rem, 0.98rem + 0.22vw, 1.16rem);
  line-height: 1.68;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display, var(--font-body));
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

a { color: inherit; text-decoration-color: color-mix(in oklab, var(--c-a) 55%, transparent); text-underline-offset: 0.16em; }
a:hover { text-decoration-color: var(--c-a); }
:focus-visible { outline: 2.5px solid var(--c-a); outline-offset: 2px; border-radius: 2px; }

code, kbd, samp, pre { font-family: var(--font-mono); }
/* Inline code sits in running prose, so it is distinguished by face rather than
   by a box — a bordered chip mid-sentence reads as a link or a button. */
code { font-size: 0.9em; letter-spacing: -0.01em; color: var(--ink); }
pre { background: var(--paper-2); border: 1px solid var(--rule-2); border-radius: var(--radius); padding: 1rem; overflow-x: auto; }
pre code { background: none; border: 0; padding: 0; font-size: 0.88em; }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--paper); color: var(--ink); padding: 0.7rem 1rem;
  border: 2px solid var(--c-a); border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* --- layout --------------------------------------------------------------- */

.wrap { width: min(72rem, 100% - 2.5rem); margin-inline: auto; }

/*
   The prose column: everything capped at the reading measure and centred,
   figures opting out by class to run wider.

   This was a named-line grid, which reads better in source but contributed
   ~100px of horizontal scroll overflow at narrow viewports that no individual
   child accounted for. Centred max-widths cannot overflow.
*/
.prose { padding-inline: clamp(1rem, 4vw, 2rem); max-width: 100%; }
.prose > * { max-width: var(--measure); margin-inline: auto; }
.prose > .figure--wide { max-width: min(52rem, 100%); }
.prose > .figure--full { max-width: min(68rem, 100%); }

.prose > * + * { margin-block-start: 1.15em; }
.prose > h2 { margin-block-start: 2.6em; font-size: 1.6em; }
.prose > h3 { margin-block-start: 2em; font-size: 1.22em; }
.prose > .figure { margin-block: 2.4em; margin-inline: auto; }
.prose > blockquote {
  margin-inline: auto; padding-inline-start: 1.2rem;
  border-inline-start: 3px solid color-mix(in oklab, var(--c-a) 60%, transparent);
  color: var(--ink-2); font-style: italic;
}
.prose ul, .prose ol { padding-inline-start: 1.4rem; }
.prose li + li { margin-block-start: 0.4em; }

.anchor {
  text-decoration: none; color: var(--ink-3); opacity: 0;
  margin-inline-start: 0.35em; font-family: var(--font-ui); font-weight: 400;
  transition: opacity 0.15s;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

/* --- header --------------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.site-header__inner { display: flex; align-items: center; gap: 1.25rem; min-height: 3.9rem; padding-block: 0.5rem; }

.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; font-weight: 600; }
.brand__mark { flex: none; width: 30px; height: 30px; }
.brand__name { font-size: 1.16rem; letter-spacing: -0.02em; }
.brand__tag { font-family: var(--font-ui); font-size: 0.74rem; color: var(--ink-2); letter-spacing: 0.06em; text-transform: uppercase; }

.nav { margin-inline-start: auto; display: flex; align-items: center; gap: 0.35rem; font-family: var(--font-ui); font-size: 0.88rem; }
.nav a {
  padding: 0.42rem 0.7rem; border-radius: var(--radius); text-decoration: none; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
}
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--paper-2); }
/* Nav icons must never collapse when the bar gets tight. */
.nav svg { flex: none; width: 16px; height: 16px; }
.nav__links { display: flex; align-items: center; gap: 0.35rem; }

.theme-toggle, .nav-toggle {
  flex: none; display: inline-grid; place-items: center;
  width: 2.15rem; height: 2.15rem; padding: 0;
  background: none; border: 1px solid var(--rule); border-radius: var(--radius);
  color: var(--ink-2); cursor: pointer;
}
.theme-toggle:hover, .nav-toggle:hover { background: var(--paper-2); color: var(--ink); }
.theme-toggle svg, .nav-toggle svg { width: 17px; height: 17px; flex: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
.nav-toggle { display: none; }

@media (max-width: 47rem) {
  .nav__links {
    display: none; position: absolute; inset-inline: 0; top: 100%;
    background: var(--paper); border-bottom: 1px solid var(--rule);
    flex-direction: column; align-items: stretch; padding: 0.6rem 1.25rem 1rem; gap: 0.15rem;
  }
  .nav__links.is-open { display: flex; }
  .nav-toggle { display: inline-grid; }
}

/* --- hero, cards ---------------------------------------------------------- */

.hero { padding-block: clamp(2.5rem, 6vw, 4.5rem) 1rem; }
.hero__title { font-size: clamp(2.1rem, 1.4rem + 3.2vw, 3.4rem); margin: 0 0 0.6rem; letter-spacing: -0.028em; }
.hero__lede { font-size: clamp(1.12rem, 1.02rem + 0.5vw, 1.34rem); color: var(--ink-2); max-width: 38rem; margin: 0; }
.hero__figure { margin-top: 2.2rem; }

.section-head { display: flex; align-items: baseline; gap: 1rem; margin-block: 3.5rem 1.4rem; }
.section-head h2 { margin: 0; font-size: 1.42rem; }
.section-head p { margin: 0; color: var(--ink-3); font-family: var(--font-ui); font-size: 0.86rem; }
.section-head::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }

.card-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fill, minmax(min(20rem, 100%), 1fr)); }

.card {
  display: flex; flex-direction: column;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius);
  overflow: hidden; text-decoration: none;
  transition: border-color 0.16s, transform 0.16s, box-shadow 0.16s;
}
.card:hover { border-color: color-mix(in oklab, var(--c-a) 45%, var(--rule)); transform: translateY(-2px); box-shadow: var(--shadow); }
/* A fixed-aspect stage with the figure centred at its own aspect. Capping the
   SVG's height while leaving its width at 100% squashes the element box. */
.card__thumb {
  background: var(--paper-2); border-bottom: 1px solid var(--rule-2);
  padding: 0.9rem; display: grid; place-items: center; aspect-ratio: 16 / 9;
}
.card__thumb svg { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.card__body { padding: 1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.card__field { font-family: var(--font-ui); font-size: 0.72rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--c-a); }
.card__title { margin: 0; font-size: 1.1rem; line-height: 1.28; }
.card__dek { margin: 0; color: var(--ink-2); font-size: 0.94rem; line-height: 1.5; }
.card__meta { margin-top: auto; padding-top: 0.5rem; font-family: var(--font-ui); font-size: 0.76rem; color: var(--ink-3); }

/* --- essay chrome --------------------------------------------------------- */

.essay-header { padding-block: clamp(2rem, 5vw, 3.4rem) 0.5rem; }
/* Display labels, not paragraphs — as <p> they became the first paragraph in
   <main>, so tooling sampling "body text colour" picked an accent instead. */
.essay-header .eyebrow {
  font-family: var(--font-ui); font-size: 0.76rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--c-a); margin: 0 0 0.7rem;
}
.essay-header h1 { font-size: clamp(1.95rem, 1.4rem + 2.4vw, 2.9rem); margin: 0 0 0.7rem; }
.essay-header .dek { font-size: clamp(1.06rem, 1rem + 0.4vw, 1.24rem); color: var(--ink-2); margin: 0; }
.essay-meta {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.1rem; margin-top: 1.3rem;
  padding-top: 1rem; border-top: 1px solid var(--rule);
  font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-3);
}

.breadcrumbs { font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-3); padding-top: 1.4rem; }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; }
.breadcrumbs li + li::before { content: "/"; margin-inline-end: 0.4rem; color: var(--rule); }

.tag-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
  font-family: var(--font-ui); font-size: 0.76rem; text-decoration: none;
  padding: 0.2rem 0.6rem; border: 1px solid var(--rule); border-radius: 999px; color: var(--ink-2);
}
.tag:hover { border-color: var(--c-a); color: var(--ink); }

.related { margin-block: 4rem 1rem; padding-top: 2rem; border-top: 1px solid var(--rule); }
.related h2 { font-size: 1.24rem; margin: 0 0 1.2rem; }
.trail { display: grid; gap: 0.9rem; }
.trail a {
  display: grid; grid-template-columns: 4.5rem 1fr; gap: 1rem; align-items: center;
  text-decoration: none; padding: 0.7rem; border: 1px solid var(--rule); border-radius: var(--radius);
}
.trail a:hover { border-color: color-mix(in oklab, var(--c-a) 45%, var(--rule)); background: var(--paper-2); }
.trail a > span:first-child { display: grid; place-items: center; aspect-ratio: 4 / 3; }
.trail svg { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.trail strong { font-weight: 600; display: block; }
.trail span { color: var(--ink-2); font-size: 0.9rem; }

/* --- figures -------------------------------------------------------------- */

.figure { margin: 0 auto; }
.figure__frame {
  background: var(--paper-2); border: 1px solid var(--rule-2); border-radius: var(--radius);
  padding: clamp(0.75rem, 2vw, 1.4rem); overflow-x: auto;
}
.figure--bleed .figure__frame { background: none; border: 0; padding: 0; }
.figure__caption { margin-top: 0.7rem; font-family: var(--font-ui); font-size: 0.86rem; line-height: 1.55; color: var(--ink-2); }
.figure__num { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--c-a); text-decoration: none; white-space: nowrap; }
.figure:target .figure__frame { border-color: var(--c-a); }

.fig-svg {
  display: block; width: 100%; height: auto;
  fill: none; stroke: none; stroke-width: 1.5; stroke-linecap: round;
  font-family: var(--font-ui);
}
.fig-svg .svg-bg { fill: var(--paper-2); stroke: none; }

/* Labels must never inherit a stroke — inline SVG under a coloured root
   renders doubled, furry text otherwise, invisible in review at small sizes. */
.fig-svg text { stroke: none; fill: var(--fig-ink); font-size: 14px; font-family: var(--font-ui); }
.fig-svg text.sm { font-size: 11.5px; }
.fig-svg text.big { font-size: 21px; font-weight: 600; }
.fig-svg text.em { font-weight: 600; }
.fig-svg text.quiet { fill: var(--ink-3); }
.fig-svg text.warn { fill: var(--c-warn); }
.fig-svg text.a { fill: var(--c-a); }
.fig-svg text.b { fill: var(--c-b); }
.fig-svg text.c { fill: var(--c-c); }
.fig-svg text.d { fill: var(--c-d); }
.fig-svg text.e { fill: var(--c-e); }
.fig-svg text.on-fill { fill: var(--ink); }
/* A halo, applied deliberately and only where a label sits on top of a line. */
.fig-svg text.halo, .fig-svg .edge-label {
  paint-order: stroke; stroke: var(--paper-2); stroke-width: 4px; stroke-linejoin: round;
}

/* Stroke palette. `:not(text)` is load-bearing: a colour class means a stroke
   on a shape and a fill on a label. Without the exclusion these rules (0,2,0)
   beat the `text { stroke: none }` reset (0,1,1) and every coloured label is
   outlined in its own colour. */
.fig-svg :not(text).ink   { stroke: var(--fig-ink); }
.fig-svg :not(text).soft  { stroke: var(--fig-soft); }
.fig-svg :not(text).faint { stroke: var(--fig-faint); }
.fig-svg :not(text).a { stroke: var(--c-a); }
.fig-svg :not(text).b { stroke: var(--c-b); }
.fig-svg :not(text).c { stroke: var(--c-c); }
.fig-svg :not(text).d { stroke: var(--c-d); }
.fig-svg :not(text).e { stroke: var(--c-e); }
.fig-svg :not(text).warn { stroke: var(--c-warn); }

/* Fills mix toward the paper, never toward `transparent`: a colour mixed with
   transparent renders as the same tint but computes to the full-strength
   colour, so contrast tooling reads dark labels on it as unreadable. */
.fig-svg .fill-a { fill: color-mix(in oklab, var(--c-a) var(--tint), var(--paper-2)); }
.fig-svg .fill-b { fill: color-mix(in oklab, var(--c-b) var(--tint), var(--paper-2)); }
.fig-svg .fill-c { fill: color-mix(in oklab, var(--c-c) var(--tint), var(--paper-2)); }
.fig-svg .fill-d { fill: color-mix(in oklab, var(--c-d) var(--tint), var(--paper-2)); }
.fig-svg .fill-e { fill: color-mix(in oklab, var(--c-e) var(--tint), var(--paper-2)); }
.fig-svg .fill-a2 { fill: color-mix(in oklab, var(--c-a) var(--tint-strong), var(--paper-2)); }
/* Genuinely see-through: these sit over other ink and must not hide it. */
.fig-svg .fill-area { fill: var(--c-a); fill-opacity: 0.12; }
.fig-svg .plane { fill: var(--c-a); fill-opacity: 0.18; stroke: var(--c-a); stroke-width: 1.4; }
.fig-svg .fill-paper { fill: var(--paper); }
.fig-svg .fill-paper2 { fill: var(--paper-3); }

.fig-svg .dot-a { fill: var(--c-a); stroke: none; }
.fig-svg .dot-b { fill: var(--c-b); stroke: none; }
.fig-svg .dot-c { fill: var(--c-c); stroke: none; }
.fig-svg .dot-warn { fill: var(--c-warn); stroke: none; }
.fig-svg .dot-faint { fill: var(--fig-faint); stroke: none; }

.fig-svg .frame { stroke: var(--fig-ink); stroke-width: 2; fill: none; }
.fig-svg .cell { stroke: var(--fig-faint); stroke-width: 1; }
.fig-svg .cell-clear { fill: none; }
.fig-svg .shell { stroke: color-mix(in oklab, var(--fig-ink) 45%, var(--paper-2)); stroke-width: 1.2; }
.fig-svg .node { fill: var(--paper); stroke: var(--fig-ink); stroke-width: 2; }
.fig-svg .edge { stroke: var(--c-b); }
.fig-svg .bar { stroke-width: 1; }
.fig-svg .ghost { stroke: color-mix(in oklab, var(--fig-ink) 22%, var(--paper-2)); stroke-width: 1.4; fill: none; }
.fig-svg .target { stroke: var(--fig-soft); fill: none; }
.fig-svg .tangent { stroke: var(--c-b); stroke-width: 2; }
.fig-svg .curve { stroke: var(--c-a); fill: none; }
.fig-svg .cut { stroke: var(--c-warn); fill: none; }
.fig-svg .hidden-edge { stroke: color-mix(in oklab, var(--fig-ink) 35%, var(--paper-2)); }
.fig-svg .ruling { stroke: color-mix(in oklab, var(--c-a) 55%, var(--paper-2)); stroke-width: 0.9; }

.fig-svg .face   { fill: color-mix(in oklab, var(--c-b) var(--tint), var(--paper)); stroke: var(--fig-ink); stroke-width: 1.2; }
.fig-svg .face-1 { fill: color-mix(in oklab, var(--c-b) 16%, var(--paper)); }
.fig-svg .face-2 { fill: color-mix(in oklab, var(--c-b) 26%, var(--paper)); }
.fig-svg .face-3 { fill: color-mix(in oklab, var(--c-c) 20%, var(--paper)); }
.fig-svg .face-4 { fill: color-mix(in oklab, var(--c-d) 20%, var(--paper)); }
.fig-svg .face-ribbon { fill: color-mix(in oklab, var(--c-a) 24%, var(--paper)); stroke: none; }
.fig-svg .face-ribbon.shade-1 { fill: color-mix(in oklab, var(--c-a) 12%, var(--paper)); }
.fig-svg .face-ribbon.shade-2 { fill: color-mix(in oklab, var(--c-a) 22%, var(--paper)); }
.fig-svg .face-ribbon.shade-3 { fill: color-mix(in oklab, var(--c-a) 34%, var(--paper)); }
.fig-svg .face-ribbon.shade-4 { fill: color-mix(in oklab, var(--c-a) 48%, var(--paper)); }
.fig-svg .ribbon-edge { stroke: none; }
.fig-svg .face-cone { fill: color-mix(in oklab, var(--c-b) 14%, var(--paper)); stroke: var(--fig-soft); stroke-width: 1.2; }
.fig-svg .cone-base { fill: color-mix(in oklab, var(--c-b) 22%, var(--paper)); }
.fig-svg .sphere { fill: color-mix(in oklab, var(--c-d) 20%, var(--paper-2)); stroke: var(--c-d); stroke-width: 1.6; }

/* --- maths ---------------------------------------------------------------- */

.katex { font-size: 1.04em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding-block: 0.4rem; }
.katex-display > .katex { white-space: normal; }

/* --- footer --------------------------------------------------------------- */

.site-footer {
  margin-top: 5rem; border-top: 1px solid var(--rule); background: var(--paper-2);
  font-family: var(--font-ui); font-size: 0.88rem; color: var(--ink-2);
}
.site-footer__inner { display: grid; gap: 2rem; padding-block: 2.5rem 3rem; grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr)); }
.site-footer h3 { font-family: var(--font-ui); font-size: 0.76rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 0.7rem; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer__base { border-top: 1px solid var(--rule); padding-block: 1.1rem 2rem; font-size: 0.82rem; color: var(--ink-3); }

/* --- utility -------------------------------------------------------------- */

.lede { font-size: 1.14em; color: var(--ink-2); }
.center { text-align: center; }
.quiet { color: var(--ink-3); }
.stack { display: grid; gap: 1rem; }
