/* ==================================================================== *
 * components.css — the content vocabulary.
 *
 * The site has one job: make a hard subject legible to someone reading
 * it for the first time, the night before. So the blocks below are not
 * decoration — each one is a promise about what kind of sentence is
 * inside it, and the reader learns the promises once and then navigates
 * by them.
 * ==================================================================== */

/* ---- rails --------------------------------------------------------- */

.rail h6 { margin: var(--sp-5) 0 var(--sp-2); font-size: var(--t-xs); }
.rail h6:first-child { margin-top: 0; }

.rail-unit { margin-bottom: var(--sp-5); }
.rail-unit > .rail-unit-t {
  display: block;
  font-family: var(--f-code); font-size: var(--t-xs);
  text-transform: uppercase; letter-spacing: .11em;
  color: var(--ink-sub); font-weight: 600;
  padding: 0 0 var(--sp-2);
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--sp-2);
}
.rail a {
  display: block; text-decoration: none;
  padding: .3rem .55rem .3rem .6rem;
  border-radius: var(--radius);
  color: var(--ink-dim);
  border-left: 2px solid transparent;
  transition: background .12s var(--ease), color .12s var(--ease), border-color .12s var(--ease);
}
.rail a:hover { background: var(--recessed); color: var(--ink); }
.rail a[aria-current="page"] {
  background: none;
  border-left-color: var(--ink);
  color: var(--ink); font-weight: 650;
}
.rail a .n {
  font-family: var(--f-code); font-size: var(--t-xs);
  color: var(--ink-sub); margin-right: .45rem;
}

/* Right rail: the outline, plus a progress rule that fills as you read. */
.toc { border-left: 1px solid var(--rule); padding-left: var(--sp-3); position: relative; }
.toc::before {
  content: ""; position: absolute; left: -1px; top: 0;
  width: 1px; height: var(--read, 0%);
  background: var(--butter-ink); transition: height .1s linear;
}
.toc a {
  display: block; text-decoration: none; padding: .22rem 0;
  color: var(--ink-sub); font-size: var(--t-sm); line-height: 1.4;
  border-left: 0;
}
.toc a.h3 { padding-left: var(--sp-3); font-size: var(--t-xs); }
.toc a:hover { color: var(--ink); background: none; }
.toc a[aria-current="true"] { color: var(--ink); font-weight: 600; }

/* ---- pills & labels ------------------------------------------------ */

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--f-code); font-size: var(--t-xs);
  line-height: 1; padding: .26rem .5rem;
  border-radius: var(--radius); border: 1px solid var(--rule);
  color: var(--ink-dim); background: var(--card);
  white-space: nowrap; vertical-align: middle;
}
.pill.sky    { background: color-mix(in oklab, var(--sky)    var(--wash), var(--card)); color: var(--sky-ink);    border-color: color-mix(in oklab, var(--sky-ink) 26%, var(--rule)); }
.pill.mint   { background: color-mix(in oklab, var(--mint)   var(--wash), var(--card)); color: var(--mint-ink);   border-color: color-mix(in oklab, var(--mint-ink) 26%, var(--rule)); }
.pill.butter { background: color-mix(in oklab, var(--butter) var(--wash), var(--card)); color: var(--butter-ink); border-color: color-mix(in oklab, var(--butter-ink) 26%, var(--rule)); }
.pill.rose   { background: color-mix(in oklab, var(--rose)   var(--wash), var(--card)); color: var(--rose-ink);   border-color: color-mix(in oklab, var(--rose-ink) 26%, var(--rule)); }
.pill.lilac  { background: color-mix(in oklab, var(--lilac)  var(--wash), var(--card)); color: var(--lilac-ink);  border-color: color-mix(in oklab, var(--lilac-ink) 26%, var(--rule)); }

.lbl {
  font-family: var(--f-code); font-size: var(--t-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .11em; color: var(--ink-sub);
}

/* The highlighter swipe itself. `multiply` on paper, `screen` on
   graphite — set once in tokens, so this rule never learns about themes.
   The slight rotation and the uneven inset are what stop it reading as a
   rectangle with a background-color. */
.hi {
  position: relative; z-index: 0;
  padding: 0 .12em; margin: 0 -.04em;
  border-radius: 2px;
  color: inherit;
}
.hi::before {
  content: ""; position: absolute; z-index: -1;
  left: 0; right: 0; top: .04em; bottom: .02em;
  background: var(--hi-c, var(--butter));
  mix-blend-mode: var(--hi-blend);
  border-radius: 3px 5px 4px 6px;
  transform: rotate(-.35deg);
}
.hi.sky    { --hi-c: var(--sky); }
.hi.mint   { --hi-c: var(--mint); }
.hi.butter { --hi-c: var(--butter); }
.hi.rose   { --hi-c: var(--rose); }
.hi.lilac  { --hi-c: var(--lilac); }

/* ==================================================================== *
 * Content blocks
 * ==================================================================== */

/* .plain — "in plain English". The single most important block on the
   site: every idea that is not self-evident is required to carry one. */
/* A marginal note on a page, not a card in an app: no full border and
   no drop of card colour, just a rule down the left the way you would
   score a margin by hand. */
.plain, .analogy, .warn, .spec, .exam, .note {
  margin: var(--sp-5) 0;
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-5);
  border: 0;
  border-left: 2px solid var(--rule-strong);
  border-radius: 0;
  background: none;
}
.plain > :last-child, .analogy > :last-child, .warn > :last-child,
.spec > :last-child, .exam > :last-child, .note > :last-child { margin-bottom: 0; }

.plain   { border-left-color: var(--butter-ink); }
.analogy { border-left-color: var(--mint-ink); }
.warn    { border-left-color: var(--rose-ink); }
.exam    { border-left-color: var(--sky-ink); }
.note    { border-left-color: var(--rule-strong); }

.plain::before, .analogy::before, .warn::before, .exam::before, .note::before {
  content: attr(data-t);
  display: block; margin-bottom: var(--sp-2);
  font-family: var(--f-code); font-size: var(--t-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
}
.plain::before   { content: attr(data-t, "In plain English"); color: var(--butter-ink); }
.analogy::before { color: var(--mint-ink); }
.warn::before    { color: var(--rose-ink); }
.exam::before    { color: var(--sky-ink); }
.note::before    { color: var(--ink-sub); }
.plain:not([data-t])::before   { content: "In plain English"; }
.analogy:not([data-t])::before { content: "The everyday version"; }
.warn:not([data-t])::before    { content: "Trap"; }
.exam:not([data-t])::before    { content: "How this gets asked"; }
.note:not([data-t])::before    { content: "Note"; }

/* .spec — the book's own words, or a literal prototype. This one KEEPS a
   ground, because the whole job of the block is to say "these are not my
   sentences, they are quotable". */
.spec {
  background: var(--recessed);
  border-left-color: var(--ink-dim);
  padding: var(--sp-4) var(--sp-5);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--f-code);
  font-size: var(--t-sm);
  line-height: 1.65;
}
.spec::before { content: attr(data-t); color: var(--ink-sub); }
.spec:not([data-t])::before { content: "From the book"; }
.spec .cite {
  float: right; font-size: var(--t-xs); color: var(--ink-sub);
  font-weight: 400; letter-spacing: .02em; text-transform: none;
}

/* A page/section citation used inline, so any claim can be chased. */
.cite-pill {
  font-family: var(--f-code); font-size: var(--t-xs);
  color: var(--ink-sub); white-space: nowrap;
  border-bottom: 1px dotted var(--rule-strong); cursor: help;
}

/* .defn — a term being introduced. */
.defn {
  margin: var(--sp-5) 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: var(--sp-4) 0;
}
.defn dt {
  font-family: var(--f-code); font-weight: 600; font-size: var(--t-sm);
  margin-bottom: var(--sp-2);
  display: inline-block;
}
.defn dd { margin: 0 0 var(--sp-4); }
.defn dd:last-child { margin-bottom: 0; }

/* .recall — end-of-section self-test. <details> so it works with no JS. */
.recall {
  margin: var(--sp-6) 0;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--card) 70%, transparent);
}
/* `display: flex` here was the bug that broke every question containing
   inline code: a flex container makes each INLINE child its own flex
   item, so "why must the parent close <code>connfd</code>" became three
   items and the text collapsed into narrow stacked columns.
   The marker is floated instead, which leaves the summary's contents as
   ordinary flowing text. */
.recall > summary {
  cursor: pointer; list-style: none;
  padding: var(--sp-4) var(--sp-5);
  font-weight: 600;
}
.recall > summary::-webkit-details-marker { display: none; }
.recall > summary::before {
  content: "?";
  float: left;
  margin: .1em var(--sp-3) 0 0;
  font-family: var(--f-code); font-weight: 700; font-size: var(--t-xs);
  width: 1.4rem; height: 1.4rem; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in oklab, var(--butter) var(--wash-strong), var(--card));
  color: var(--butter-ink);
}
.recall > summary::after { content: ""; display: block; clear: both; }
.recall[open] > summary { border-bottom: 1px dashed var(--rule); }
.recall > summary:hover { background: var(--card); }
.recall .a { padding: var(--sp-4) var(--sp-5); }
.recall .a > :last-child { margin-bottom: 0; }

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

.fig {
  margin: var(--sp-6) 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.fig-hd {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--rule);
  background: color-mix(in oklab, var(--recessed) 46%, var(--card));
  font-family: var(--f-code); font-size: var(--t-xs);
  color: var(--ink-sub);
}
.fig-hd .t { color: var(--ink-dim); font-weight: 600; }
.fig-hd .sp { flex: 1; }
.fig-bd { padding: var(--sp-5); overflow-x: auto; }
.fig-bd > svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.fig-cap {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--rule);
  font-size: var(--t-sm); color: var(--ink-dim);
  background: color-mix(in oklab, var(--recessed) 30%, var(--card));
}
.fig-cap > :last-child { margin-bottom: 0; }

.fig-ctl {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--rule);
  background: color-mix(in oklab, var(--recessed) 30%, var(--card));
}

/* ---- code ---------------------------------------------------------- */

pre {
  margin: var(--sp-5) 0;
  padding: var(--sp-4);
  background: var(--recessed);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: var(--t-sm);
  line-height: 1.62;
  tab-size: 4;
}
pre code { background: none; padding: 0; white-space: pre; }

/* Terminal transcript: what you typed vs what came back. */
.term {
  margin: var(--sp-5) 0;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--recessed);
  font-family: var(--f-code); font-size: var(--t-sm); line-height: 1.6;
  overflow-x: auto;
}
.term-hd {
  padding: .35rem var(--sp-4);
  border-bottom: 1px solid var(--rule);
  font-size: var(--t-xs); color: var(--ink-sub);
  background: color-mix(in oklab, var(--card) 60%, var(--recessed));
  position: sticky; left: 0;
}
.term-bd { padding: var(--sp-4); white-space: pre; }
.term .in  { color: var(--ink); font-weight: 600; }
.term .in::before { content: "$ "; color: var(--ink-sub); font-weight: 400; }
.term .out { color: var(--ink-dim); }
.term .hd  { color: var(--sky-ink); font-weight: 600; }
.term .mark{ background: color-mix(in oklab, var(--butter) var(--wash-strong), transparent); }

/* Syntax tint — deliberately three colours, not eight. Keywords and
   types are structure; strings and numbers are data; comments recede.
   Anything more turns a 40-line listing into confetti. */
.k  { color: var(--sky-ink);   font-weight: 600; }  /* keyword / type       */
.f  { color: var(--lilac-ink); font-weight: 600; }  /* function being called*/
.s  { color: var(--mint-ink); }                     /* string / literal     */
.n  { color: var(--mint-ink); }                     /* number               */
.c  { color: var(--ink-sub); font-style: italic; }  /* comment              */
.pp { color: var(--butter-ink); }                   /* preprocessor         */

/* ---- tables -------------------------------------------------------- */

.tw { overflow-x: auto; margin: var(--sp-5) 0; border-radius: var(--radius); }
table {
  width: 100%; border-collapse: collapse;
  font-size: var(--t-sm);
}
th, td {
  text-align: left; padding: .5rem .7rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
/* No `position: sticky` here. A page-level table is not inside a scroll
   container, so a sticky header offset by the bar's height renders
   shifted up out of its own row and clips. The widget tables that DO
   scroll re-enable it against their own box, in widgets.css. */
thead th {
  font-family: var(--f-code); font-size: var(--t-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-sub);
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
  background: var(--recessed);
  vertical-align: bottom;
}
tbody tr:hover { background: color-mix(in oklab, var(--recessed) 55%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td code, th code { white-space: nowrap; }
table.mono td:first-child { font-family: var(--f-code); white-space: nowrap; }

/* ---- misc ---------------------------------------------------------- */

.card {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--card); padding: var(--sp-5);
}

.grid2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }

.kicker {
  font-family: var(--f-code); font-size: var(--t-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .13em; color: var(--ink-sub);
  margin-bottom: var(--sp-3);
}

.lede { font-size: var(--t-md); color: var(--ink-dim); line-height: 1.62; }

.pagenav {
  display: flex; gap: var(--sp-4); margin-top: var(--sp-8);
  padding-top: var(--sp-5); border-top: 1px solid var(--rule);
}
.pagenav a {
  flex: 1 1 0; text-decoration: none;
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4); background: var(--card);
  transition: border-color .13s var(--ease), background .13s var(--ease);
}
.pagenav a:hover { border-color: var(--rule-strong); }
.pagenav a .d { display: block; font-family: var(--f-code); font-size: var(--t-xs); color: var(--ink-sub); margin-bottom: .2rem; }
.pagenav a .t { font-weight: 600; }
.pagenav a.next { text-align: right; }

.foot {
  border-top: 1px solid var(--rule);
  margin-top: var(--sp-8);
  padding: var(--sp-6) var(--gutter);
  font-size: var(--t-sm); color: var(--ink-sub);
  text-align: center;
}

/* A heading that opens a container it does not own — a figure caption, a
   card, a question block — must not also draw the page-level section
   rule, or the rule stubs across part of the box. */
:where(.card, .card-c, .fig, .cw, .pq, .recall, .q, .plain, .analogy,
       .warn, .exam, .note, .spec, .ask) :where(h2, h3, h4) {
  margin-top: 0; padding-top: 0; border-top: 0;
}
