/* Software Fundamentals: the one look.

   Light text on a near-black ground, like an instrument panel. One palette for every reader,
   no choice of colours. Prose is set in a humanist sans for long reading; everything that is
   a label, a number, a name of the machine or a caption is set in a monospace, small and
   spaced, like the markings on a board. Rules are hairlines. The accent is amber; links are
   cyan; the four kinds of aside each have a colour of their own.

   A figure carries classes, never colours (SPEC.md): the figure classes are at the end. */

@font-face { font-family: "Source Sans 3"; src: url("fonts/source-sans-3-latin-wght-normal.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Code Pro"; src: url("fonts/source-code-pro-latin-wght-normal.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }

:root {
  --ground: #0b0d10;       /* the page */
  --panel: #12161b;        /* a block set on the page: code, a figure, a table's head */
  --panel-2: #181d24;
  --rule: #262c35;         /* hairlines */
  --rule-2: #39414d;
  --ink: #d9dee5;          /* text */
  --ink-bright: #f3f5f8;   /* headings */
  --ink-2: #8c96a4;        /* secondary text, captions */
  --ink-3: #5d6673;        /* the quietest: planned pages, rules' labels */
  --accent: #f2b13c;       /* amber: numbers, markers, the current page */
  --link: #79c8ec;         /* cyan */
  --why: #6cc6e8;
  --history: #f2b13c;
  --trap: #ff6f61;
  --measured: #7fe08f;     /* phosphor green: output measured on a machine */
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --mono: "Source Code Pro", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --measure: 40.375rem;    /* 646px at 16px: the text column */
  --wide: 53.75rem;        /* 860px: a wide figure or table */
  --gutter: 1rem;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--sans); font-size: 1.0625rem; line-height: 1.68; font-weight: 400;
  font-optical-sizing: auto; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "running" "beside" "main" "foot";
}
@media (min-width: 46em) { body { font-size: 1.125rem; } }

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--ink-bright); }
a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: currentColor; }
a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
strong { font-weight: 650; color: var(--ink-bright); }
em { font-style: italic; }
.planned { color: var(--ink-3); }
.spoken { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- the running head ------------------------------------------------------------------ */
.running {
  grid-area: running; position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.55rem var(--gutter); border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--ground) 92%, transparent); backdrop-filter: blur(6px);
  font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
}
.crumbs { display: flex; align-items: center; gap: 0.7em; min-width: 0; white-space: nowrap; overflow: hidden; }
.crumbs a { color: var(--ink-2); text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { color: var(--ink-bright); }
.crumbs .book { color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; gap: 0.6em; }
.crumbs .chip { width: 0.55rem; height: 0.55rem; background: var(--accent); box-shadow: 0 0 0 2px var(--ground), 0 0 0 3px var(--accent); flex: none; }
.crumbs .sep { color: var(--ink-3); }
.crumbs .no { color: var(--accent); }
.open-contents { position: relative; cursor: pointer; color: var(--ink); user-select: none; flex: none; }
.open-contents input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.open-contents::after { content: " [+]"; color: var(--accent); }
.open-contents:has(input:checked)::after { content: " [\2212]"; }

/* ---- the contents ------------------------------------------------------------------------ */
.booknav {
  grid-area: beside; display: none; padding: 1rem var(--gutter) 1.25rem; border-bottom: 1px solid var(--rule);
  font-family: var(--sans); font-size: 0.875rem; line-height: 1.35;
}
body:has(#_contents-open:checked) .booknav { display: block; }
.booknav ol { margin: 0; padding: 0; list-style: none; }
.navhead, .booknav .part { margin: 0 0 0.9em; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.booknav a, .booknav .planned { display: grid; grid-template-columns: 2.4em 1fr; padding: 0.26em 0; color: var(--ink); text-decoration: none; }
.booknav .planned { color: var(--ink-3); }
.booknav a:hover { color: var(--ink-bright); }
.booknav .no { font-family: var(--mono); font-size: 0.85em; color: var(--ink-3); padding-top: 0.08em; }
.booknav a[aria-current] { color: var(--accent); }
.booknav a[aria-current] .no { color: var(--accent); }
.booknav .under { margin: 0.15em 0 0.6em 0.45em; padding-left: 0.8em; border-left: 1px solid var(--rule); font-size: 0.95em; }
.booknav .under a, .booknav .under .planned { grid-template-columns: 3em 1fr; }
.booknav .headings { margin: 0.1em 0 0.4em 3em; font-size: 0.93em; }
.booknav .headings a { display: block; padding: 0.18em 0; color: var(--ink-2); }

@media (min-width: 62em) {
  body { grid-template-columns: 17.5rem minmax(0, 1fr); grid-template-areas: "running running" "beside main" "beside foot"; }
  .booknav, body:has(#_contents-open:checked) .booknav {
    display: block; position: sticky; top: 2.3rem; align-self: start; max-height: calc(100vh - 2.3rem); overflow-y: auto;
    padding: 1.6rem 1rem 4rem 1.4rem; border-bottom: 0; border-right: 1px solid var(--rule);
    scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent;
  }
  .open-contents { display: none; }
}

/* ---- the column -------------------------------------------------------------------------- */
main { grid-area: main; min-width: 0; padding: 0 var(--gutter) 3rem; --frame: var(--measure); }
@media (min-width: 62em) { main { padding: 0 2.5rem 4rem; } }
@media (min-width: 90em) { main { --frame: var(--wide); } }
/* Everything stands in one frame with one left edge. Prose keeps to the text column inside it;
   a wide figure, a table and the lists of contents may use the frame's whole width. */
.head, .flow, .outline, .contents, .turn { max-width: var(--frame); margin-left: auto; margin-right: auto; }
.flow > * { margin-top: 0; margin-bottom: 1.05em; max-width: var(--measure); }
.flow > .figure.wide, .flow > .table, .flow > .tabular { max-width: none; }
.head .lede { max-width: 46rem; }

/* ---- the heads ----------------------------------------------------------------------------- */
.head { padding: 3.2rem 0 1.6rem; margin-bottom: 2rem; border-bottom: 1px solid var(--rule); }
.kicker { margin: 0 0 1rem; font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }
.kicker a { color: inherit; text-decoration: none; }
.kicker a:hover { color: var(--ink-bright); }
.kicker .no { color: var(--accent); margin-right: 0.6em; }
h1 { margin: 0 0 0.7rem; font-size: 2.35rem; line-height: 1.12; font-weight: 650; letter-spacing: -0.012em; color: var(--ink-bright); text-wrap: balance; }
.lede { margin: 0; font-size: 1.2em; line-height: 1.5; color: var(--ink); font-weight: 350; text-wrap: pretty; }

.title-page { padding: 5rem 0 2.5rem; position: relative; }
.title-page h1 { font-size: clamp(2.6rem, 6vw, 4rem); font-weight: 700; letter-spacing: -0.02em; }
.title-page::before {
  /* a strip of pins along the top of the title, like the edge of a chip */
  content: ""; position: absolute; left: 0; right: 0; top: 2.6rem; height: 0.55rem;
  background: repeating-linear-gradient(90deg, var(--rule-2) 0 0.5rem, transparent 0.5rem 1.1rem);
}

.opener { padding-top: 3.6rem; }
.opener .numeral {
  margin: 0 0 0.4rem; font-family: var(--mono); font-size: 5.5rem; font-weight: 300; line-height: 1;
  color: transparent; -webkit-text-stroke: 1.5px var(--accent); letter-spacing: -0.02em;
}
@supports not (-webkit-text-stroke: 1px black) { .opener .numeral { color: var(--accent); } }

/* ---- prose --------------------------------------------------------------------------------- */
.section { margin-top: 3rem; }
h2 { position: relative; margin: 0 0 0.8em; padding-top: 0.9rem; font-size: 1.5rem; line-height: 1.22; font-weight: 650; color: var(--ink-bright); border-top: 1px solid var(--rule); text-wrap: balance; }
h2::before { content: ""; position: absolute; left: 0; top: -1px; width: 2.2rem; height: 2px; background: var(--accent); }
h3 { margin: 1.9em 0 0.5em; font-size: 1.12rem; font-weight: 650; color: var(--ink-bright); }
p { text-wrap: pretty; hyphens: manual; }
ul, ol { padding-left: 1.3em; }
li { margin: 0.3em 0; }
li::marker { color: var(--ink-3); font-family: var(--mono); font-size: 0.85em; }
blockquote { margin-left: 0; padding-left: 1.1em; border-left: 1px solid var(--rule-2); color: var(--ink-2); }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em 0; }

code { font-family: var(--mono); font-size: 0.86em; color: var(--ink-bright); background: var(--panel-2); border: 1px solid var(--rule); border-radius: 2px; padding: 0.06em 0.3em; }
code.whole { white-space: nowrap; }
pre {
  position: relative; margin: 1.5em 0 1.7em; padding: 0.95em 1.1em; overflow-x: auto;
  background: var(--panel); border: 1px solid var(--rule); border-left: 2px solid var(--rule-2); border-radius: 2px;
  font-family: var(--mono); font-size: 0.84rem; line-height: 1.6; color: var(--ink);
  scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
/* Output measured on a real machine: the phosphor panel. */
pre[data-kind="recording"] { border-left-color: var(--measured); background: color-mix(in srgb, var(--measured) 4%, var(--panel)); color: color-mix(in srgb, var(--measured) 55%, var(--ink)); }
pre[data-kind="recording"]::before {
  content: "\25CF  " attr(data-label); display: block; margin: 0 0 0.7em; font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--measured);
}

/* ---- asides: a quotation that opens with its label in bold --------------------------------- */
.note {
  --kind: var(--ink-2); position: relative; margin: 1.8em 0; padding: 0.9em 1.15em 0.95em;
  border: 1px solid color-mix(in srgb, var(--kind) 28%, var(--rule)); border-left: 3px solid var(--kind); border-radius: 2px;
  background: color-mix(in srgb, var(--kind) 6%, var(--ground)); font-size: 0.95em; line-height: 1.6;
}
.note[data-kind="why"] { --kind: var(--why); }
.note[data-kind="history"] { --kind: var(--history); }
.note[data-kind="trap"] { --kind: var(--trap); }
.note > :first-child { margin-top: 0; }
.note > :last-child { margin-bottom: 0; }
.note > p:first-child > strong:first-child {
  display: block; margin-bottom: 0.35em; font-family: var(--mono); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--kind);
}

/* ---- tables -------------------------------------------------------------------------------- */
.table { overflow-x: auto; margin: 1.6em 0 1.8em; scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent; }
table { width: 100%; border-collapse: collapse; font-size: 0.9em; line-height: 1.45; font-variant-numeric: tabular-nums; }
thead th {
  padding: 0.65em 0.9em; text-align: left; vertical-align: bottom; white-space: nowrap;
  font-family: var(--mono); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2);
  background: var(--panel); border-top: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2);
}
td { padding: 0.6em 0.9em; vertical-align: top; border-bottom: 1px solid var(--rule); }
tbody tr:hover td { background: color-mix(in srgb, var(--ink) 3%, transparent); }
td[style*="right"], th[style*="right"] { font-family: var(--mono); font-size: 0.92em; }
.tabular { margin: 1.8em 0 2em; }
.tabular .table { margin: 0.6em 0 0; }
.label { display: none; }
@media (max-width: 46em) {
  .stacks table, .stacks tbody, .stacks tr, .stacks td { display: block; }
  .stacks thead { display: none; }
  .stacks tr { padding: 0.7em 0 0.8em; border-bottom: 1px solid var(--rule); }
  .stacks td { padding: 0; border: 0; }
  .stacks td:empty { display: none; }
  .stacks td:first-child { font-weight: 600; color: var(--ink-bright); }
  .stacks td + td { display: flow-root; margin-top: 0.35em; padding-left: 7rem; }
  .stacks .label { display: block; float: left; width: 6.4rem; margin-left: -7rem; padding-top: 0.2em; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
}

/* ---- figures ------------------------------------------------------------------------------- */
.figure {
  margin: 2em 0 2.2em; padding: 1.3rem 1.3rem 0.9rem; border: 1px solid var(--rule); border-radius: 2px; position: relative;
  /* a graticule, faint, like a scope's screen */
  background-color: var(--ground);
  background-image:
    linear-gradient(color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
}
.figure::before, .figure::after { content: ""; position: absolute; width: 10px; height: 10px; border-color: var(--accent); border-style: solid; }
.figure::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.figure::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }
.figure .art { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent; }
.figure svg { display: block; width: 100%; max-width: var(--natural); min-width: calc(var(--natural) * 0.75); height: auto; margin: 0 auto; }
figcaption { margin-top: 0.9em; padding-top: 0.75em; border-top: 1px dashed var(--rule); font-size: 0.86em; line-height: 1.5; color: var(--ink-2); }
.tabular figcaption { margin-top: 0; padding-top: 0; border-top: 0; }
figcaption .no { margin-right: 0.7em; font-family: var(--mono); font-size: 0.8em; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }

/* The figure grammar: classes a figure's SVG uses instead of colours and fonts. */
.fig text { font-family: var(--sans); font-size: 14px; fill: var(--ink); }
.fig .name, .fig .mono { font-family: var(--mono); font-size: 13px; }
.fig .small { font-size: 12px; }
.fig .quiet { fill: var(--ink-2); }
.fig .strong { font-weight: 600; fill: var(--ink-bright); }
.fig .head { font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; fill: var(--ink-2); }
.fig .mark { fill: var(--accent); }
.fig .measured { fill: var(--measured); }
.fig .box { fill: var(--panel); stroke: var(--rule-2); stroke-width: 1; }
.fig .ground { fill: var(--panel-2); stroke: none; }
.fig .mark-box { fill: color-mix(in srgb, var(--accent) 14%, var(--panel)); stroke: var(--accent); stroke-width: 1.25; }
.fig .cool-box { fill: color-mix(in srgb, var(--why) 12%, var(--panel)); stroke: var(--why); stroke-width: 1.25; }
.fig .line { fill: none; stroke: var(--ink-2); stroke-width: 1.25; }
.fig .dashed { fill: none; stroke: var(--ink-3); stroke-width: 1.25; stroke-dasharray: 4 4; }
.fig .mark-line { fill: none; stroke: var(--accent); stroke-width: 1.75; }
.fig .cool-line { fill: none; stroke: var(--why); stroke-width: 1.75; }
.fig .measured-line { fill: none; stroke: var(--measured); stroke-width: 2; }
.fig .arrow { fill: var(--ink-2); }
.fig .mark-arrow { fill: var(--accent); }
.fig .grid { stroke: var(--rule); stroke-width: 1; }
.fig .tick { fill: none; stroke: var(--ink-bright); stroke-width: 1.5; }

/* ---- a chapter's outline ------------------------------------------------------------------- */
.outline { margin-top: 3rem; }
.outline h2 { font-size: 0.75rem; font-family: var(--mono); font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-2); }
.outline ol { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--rule); }
.outline li { display: grid; grid-template-columns: 3.4rem 1fr; column-gap: 0.4rem; margin: 0; padding: 0.85rem 0; border-bottom: 1px solid var(--rule); }
.outline li > a, .outline li > .planned { display: contents; text-decoration: none; color: var(--ink-bright); font-weight: 600; }
.outline li > .planned { color: var(--ink-2); }
.outline .no { font-family: var(--mono); font-size: 0.82em; color: var(--accent); padding-top: 0.15em; }
.outline .planned .no { color: var(--ink-3); }
.outline .about { grid-column: 2; font-size: 0.92em; line-height: 1.5; color: var(--ink-2); margin-top: 0.15rem; }

/* ---- the front page's contents ------------------------------------------------------------- */
.contents { margin-top: 3.5rem; }
.contents h2 { font-size: 0.75rem; font-family: var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-2); }
.toc { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.75rem; }
.toc li { margin: 0; padding: 1.1rem 1.15rem 1rem; border: 1px solid var(--rule); border-top: 2px solid var(--rule-2); background: var(--ground); display: flex; flex-direction: column; }
.toc li:has(a):hover { border-top-color: var(--accent); }
.toc li:hover { background: var(--panel); }
.toc .entry { margin: 0 0 0.45rem; font-weight: 650; line-height: 1.3; }
.toc .entry a, .toc .entry .planned { color: var(--ink-bright); text-decoration: none; display: block; }
.toc .entry .no { display: block; margin-bottom: 0.35rem; font-family: var(--mono); font-size: 0.78rem; font-weight: 500; color: var(--accent); letter-spacing: 0.08em; }
.toc .about { margin: 0 0 0.8rem; font-size: 0.88rem; line-height: 1.5; color: var(--ink-2); flex: 1; }
.toc .count { margin: 0; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }

/* ---- the turn of the page and the foot ----------------------------------------------------- */
.turn { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 4rem; background: var(--rule); border: 1px solid var(--rule); }
.turn a, .turn > span { display: block; padding: 0.9rem 1.1rem; background: var(--ground); color: var(--ink-bright); text-decoration: none; font-weight: 600; line-height: 1.35; }
.turn a:hover { background: var(--panel); }
.turn .after { text-align: right; grid-column: 2; }
.turn .dir { display: block; margin-bottom: 0.3rem; font-family: var(--mono); font-size: 0.68rem; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.turn .no { font-family: var(--mono); font-size: 0.85em; color: var(--accent); margin-right: 0.35em; }
.colophon { grid-area: foot; padding: 2rem var(--gutter) 3rem; border-top: 1px solid var(--rule); font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; color: var(--ink-3); }
.colophon p { max-width: var(--measure); margin: 0.3em auto; }
.colophon a { color: var(--ink-2); }
@media (min-width: 62em) { .colophon { padding-left: 2.5rem; padding-right: 2.5rem; } }
@media (min-width: 90em) { .colophon p { max-width: var(--wide); } }

@media (max-width: 46em) {
  h1 { font-size: 1.9rem; }
  .opener .numeral { font-size: 4rem; }
  .head { padding-top: 2.2rem; }
  .figure { padding: 0.9rem 0.7rem 0.7rem; }
}
@media print {
  .running, .booknav, .turn { display: none; }
}
