/* oryx. One stylesheet for every page. Pages are hand-written HTML in
   site/; this file and site.js are the only parts they share.

   The whole page is a character grid. The font is monospace, so every glyph
   is exactly 1ch wide, and every line is one row of `--lh` tall. Widths are
   written in ch, heights in rows (multiples of --lh), and anything in a
   <pre> lands on the grid exactly, so ASCII decoration can be dropped in
   anywhere. Courier Prime's advance is 0.6em, so at 15px/21px one row is
   2⅓ch tall and a tile 7ch x 3 rows (28 x 12) is a square. Press `g` on any
   page to see the grid. */

@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/CourierPrime-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/CourierPrime-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/CourierPrime-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/CourierPrime-BoldItalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
/* Courier Prime has no box-drawing, block or arrow glyphs. GridSymbols
   (built by tools/gridsymbols.py) draws those ranges to Courier Prime's
   width and stem weight, filling the 1ch x 1 row cell exactly, and is
   attached to the same family so `┌─┐` in a <pre> just works. */
@font-face {
  font-family: "Courier Prime";
  src: url("/fonts/GridSymbols.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+2190-2195, U+2500-25FF;
}

/* Colour. Everything coloured on the page is mixed from one hue, `--hue`.
   A page picks its own with `<html style="--hue: 300">`. The second diagram
   colour, `--warm`, sits 150° round the wheel so it stays distinct from the
   accent whatever hue a page uses. */
:root {
  --hue: 262;
  --lh: 1.3125rem;
  --cols: 72;
  color-scheme: light;
  --bg: #fdfdfb;
  --fg: #1a1a1a;
  --muted: #767676;
  --rule: #e4e4de;
  --accent: oklch(50% 0.17 var(--hue));
  --accent-soft: oklch(94% 0.03 var(--hue));
  --code-bg: oklch(97% 0.012 var(--hue));
  --code-inline: #e9e9e4;
  --code-blend: darken;
  --warm: oklch(55% 0.16 calc(var(--hue) + 150));
  --select: oklch(88% 0.08 var(--hue));
  --code-key: var(--accent);
  --code-str: oklch(50% 0.14 145);
  --code-num: oklch(52% 0.18 350);
  --code-kw: oklch(52% 0.15 40);
  --code-type: oklch(48% 0.12 200);
}
/* Light is the default regardless of the OS setting; dark is opt-in via the
   toggle, which sets `data-theme` on <html> and remembers it. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131316;
  --fg: #dcdcd7;
  --muted: #8f8f8f;
  --rule: #2c2c31;
  --accent: oklch(78% 0.12 var(--hue));
  --accent-soft: oklch(26% 0.035 var(--hue));
  --code-bg: oklch(20% 0.015 var(--hue));
  --code-inline: #2b2b30;
  --code-blend: lighten;
  --warm: oklch(76% 0.12 calc(var(--hue) + 150));
  --select: oklch(40% 0.09 var(--hue));
  --code-str: oklch(76% 0.13 145);
  --code-num: oklch(78% 0.14 350);
  --code-kw: oklch(76% 0.12 40);
  --code-type: oklch(76% 0.1 200);
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: calc(2 * var(--lh)) 2ch calc(4 * var(--lh));
  background: var(--bg);
  color: var(--fg);
  font: 0.9375rem/var(--lh) "Courier Prime", "Courier New", Courier, monospace;
  font-variant-ligatures: none;
}
main {
  width: calc(var(--cols) * 1ch);
  max-width: 100%;
  margin: 0 auto;
}
/* Grid overlay, toggled with `g` (site.js): a line every 1ch and every row,
   from main's top-left corner, which is where the text starts. */
[data-grid] main {
  background-image:
    repeating-linear-gradient(to right, var(--rule) 0 1px, transparent 1px 1ch),
    repeating-linear-gradient(to bottom, var(--rule) 0 1px, transparent 1px var(--lh));
}
::selection { background: var(--select); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Every block's vertical spacing is a whole number of rows. */
p, ul, ol, pre, blockquote, table, figure, hr { margin: 0 0 var(--lh); }
h1, h2, h3 { margin: 0 0 var(--lh); font-size: 1rem; line-height: var(--lh); }
h2 { margin-top: var(--lh); }
/* Section heading: `── title ─────────…` out to the edge of the column. */
h2.rule { display: flex; gap: 1ch; white-space: nowrap; }
h2.rule::before { content: "──"; color: var(--muted); font-weight: normal; }
h2.rule::after {
  content: "────────────────────────────────────────────────────────────────────────────────────────────────";
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: normal;
}
/* `<hr>` is a row of ─. */
hr { height: var(--lh); border: 0; overflow: hidden; color: var(--muted); }
hr::before { content: "────────────────────────────────────────────────────────────────────────────────────────────────"; display: block; white-space: nowrap; }
/* ASCII decoration: a <pre class="ascii"> is text on the grid, nothing else.
   Wider art than the column scrolls sideways instead of wrapping. */
pre.ascii {
  padding: 0;
  background: none;
  color: var(--muted);
  overflow-x: auto;
}
pre.ascii.fg { color: var(--fg); }
pre.ascii.accent { color: var(--accent); }
/* Bold in ASCII art (the oryx's eyes): a soft dusty pink-purple in light
   mode, a dark crimson in dark mode. */
pre.ascii b { color: #c49ac4; }
:root[data-theme="dark"] pre.ascii b { color: #9b1c31; }
/* Centred on the column, even when wider than it (it then overhangs both
   sides equally). Keep (72 - width) even so it stays on the grid. */
pre.ascii.center { width: fit-content; max-width: none; overflow: visible; position: relative; left: 50%; transform: translateX(-50%); }
.subtitle, .muted { color: var(--muted); }
.subtitle { display: block; }
h1 + .subtitle { margin: calc(-1 * var(--lh)) 0 var(--lh); }
.crumb { margin-bottom: var(--lh); }
ul, ol { padding-left: 2ch; }
ul { list-style: none; }
ul > li::before { content: "- "; margin-left: -2ch; color: var(--muted); }
.entries { padding: 0; }
.entries > li::before { content: none; }
.entries li > br + .subtitle { display: inline; padding-left: 2ch; }
em { font-style: italic; }
strong { font-weight: 700; }

/* Links: accent, underlined; hover inverts like a terminal selection. */
a { color: var(--accent); text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover, a:focus-visible { background: var(--accent); color: var(--bg); text-decoration: none; }
/* External links (`target="_blank"`) get a trailing arrow, 1ch wide. */
a[target="_blank"]::after {
  content: "";
  display: inline-block;
  width: 1ch;
  height: 0.5em;
  vertical-align: 0.2em;
  background-color: currentColor;
  --arrow: no-repeat right center/0.5em 0.5em url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cg fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.6 9.4 8.6 3.4'/%3E%3Cpath d='M4.6 3.4h4v4'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-mask: var(--arrow);
  mask: var(--arrow);
}

/* Theme toggle, a text button pinned top-right by site.js: [dark] / [light]. */
.theme-toggle {
  position: fixed;
  top: var(--lh);
  right: 2ch;
  z-index: 10;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.theme-toggle:hover, .theme-toggle:focus-visible { color: var(--fg); }

/* Code. Inline `<code>` is a snippet: the font can't change, so it sits
   on a grey box. The box is a little bigger than the text, but the padding
   is cancelled by a negative margin (and vertical padding on an inline
   takes no room), so the text stays on the grid. The box overhangs the
   neighbouring cells by 0.3ch, so it is blended (darken on light, lighten
   on dark) and a glyph or underline beside it shows through instead of
   being clipped. Blocks are tinted with the page hue. Tokens are marked up
   by hand:
   .k key, .s string, .n number, .w keyword, .t type. */
pre, code, kbd, samp { font-family: inherit; font-size: inherit; } /* the UA sheet would swap in the system monospace */
code { background: var(--code-inline); padding: 2px 0.3ch; margin: 0 -0.3ch; mix-blend-mode: var(--code-blend); }
pre { padding: var(--lh) 2ch; background: var(--code-bg); overflow-x: auto; }
pre code { background: none; padding: 0; margin: 0; mix-blend-mode: normal; }
a:hover code, a:focus-visible code { background: none; } /* a hovered link inverts; the tint would hide its text */
.k { color: var(--code-key); }
.s { color: var(--code-str); }
.n { color: var(--code-num); }
.w { color: var(--code-kw); }
.t { color: var(--code-type); }
blockquote { padding-left: 2ch; border-left: 1px solid var(--rule); color: var(--muted); }
img { max-width: 100%; }

/* Figures: an image or diagram with a muted caption under it. */
figcaption { color: var(--muted); }
figure > img { display: block; margin: 0 auto var(--lh); height: auto; }
/* Diagrams are hand-written inline SVG drawn in theme colours. Inside an
   SVG, px are user units, so this font-size is relative to the viewBox. */
.diagram {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: var(--lh);
  overflow: visible;
  font-size: 8px;
  fill: var(--fg);
}
.diagram text { fill: var(--fg); }
.diagram .mono, .diagram .small { font-size: 7px; }
.diagram .ink { stroke: var(--fg); fill: none; }
.diagram .dotted { stroke: var(--muted); stroke-dasharray: 1 2; }
.diagram .faint { fill: var(--rule); stroke: var(--fg); stroke-width: 0.6; }
.diagram .accent, .diagram text.accent { fill: var(--accent); }
.diagram .warm, .diagram text.warm { fill: var(--warm); }
.diagram .muted, .diagram text.muted { fill: var(--muted); }
.diagram .accent-line { stroke: var(--accent); fill: none; }
.diagram .warm-line { stroke: var(--warm); fill: none; }
.diagram .muted-line { stroke: var(--muted); fill: none; }
.diagram .phase .band { fill: transparent; }
.diagram .phase:hover .band { fill: var(--accent-soft); }
.diagram .phase:hover .label { fill: var(--accent); }

/* Noise field (site.js, on <body class="noise">): one <pre> behind the
   page filled with faint centred dots, blank under the text. It is
   positioned and sized by the script; this only sets how it looks. The
   colour mixes a little of the text colour into the background, so it
   follows the theme. .n1-.n3 are the cells the pointer has stirred, from
   faint to strong. */
.noise-field {
  position: absolute;
  top: 0;
  margin: 0;
  padding: 0;
  z-index: 0;
  overflow: hidden;
  font: inherit;
  line-height: var(--lh);
  color: color-mix(in oklab, var(--fg) 5%, var(--bg));
  background: none;
  pointer-events: none;
  user-select: none;
}
.noise-field .n1 { color: color-mix(in oklab, var(--fg) 12%, var(--bg)); }
.noise-field .n2 { color: color-mix(in oklab, var(--fg) 20%, var(--bg)); }
.noise-field .n3 { color: color-mix(in oklab, var(--fg) 30%, var(--bg)); }
/* The same smoke over ASCII art: from its muted grey toward the text colour. */
pre.ascii .n1 { color: color-mix(in oklab, var(--fg) 35%, var(--muted)); }
pre.ascii .n2 { color: color-mix(in oklab, var(--fg) 65%, var(--muted)); }
pre.ascii .n3 { color: var(--fg); }
body.noise { position: relative; overflow-x: clip; } /* art wider than a phone is cut off, not scrolled */
body.noise main { position: relative; z-index: 1; }

/* Page transition (site.js). Following a link to another page of the site
   is a view transition: the browser lays a picture of the old page over
   the new one, and site.js cuts a growing hole in it from the click, with
   a ring of random characters round the inside of the hole. The usual
   cross-fade is switched off and the old page is put on top; with no
   script nothing animates and the transition ends at once, which is an
   ordinary page load. Not on phones and tablets (a touch screen as the
   main pointer) and not under reduced motion; site.js checks the same. */
@media (prefers-reduced-motion: no-preference) and (not (pointer: coarse)) {
  @view-transition { navigation: auto; }
}
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 1; }
/* The ring is a canvas over the viewport. The script draws it; these are
   its colours, read from the element, so they follow the theme and the
   page hue. --cell is the background of a noisy cell, --i1 to --i3 the
   characters from faint to strong, --crest the front of the wave, --lock
   a cell about to settle into text. */
.ripple {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  --cell: var(--bg);
  --i1: color-mix(in oklab, var(--fg) 22%, var(--bg));
  --i2: color-mix(in oklab, var(--fg) 42%, var(--bg));
  --i3: color-mix(in oklab, var(--fg) 65%, var(--bg));
  --crest: var(--accent);
  --lock: var(--fg);
}

/* Image gallery: square tiles, click to open the full image in a lightbox. */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(22ch, 1fr));
  gap: var(--lh) 2ch;
  padding: 0;
  list-style: none;
}
.gallery li::before { content: none; }
.gallery button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--rule);
  overflow: hidden;
  cursor: zoom-in;
}
.gallery img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; object-position: var(--pos, center); }
.lightbox {
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: #e8e8e4;
}
.lightbox::backdrop { background: oklch(12% 0.02 var(--hue) / 0.9); }
.lightbox figure { margin: 0; display: flex; flex-direction: column; align-items: center; }
.lightbox img { display: block; max-width: 94vw; max-height: 84vh; cursor: zoom-out; }
.lightbox figcaption { color: inherit; display: flex; align-items: center; gap: 2ch; }
.lightbox button {
  padding: 0 1ch;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  opacity: 0.7;
}
.lightbox button:hover { opacity: 1; background: rgb(255 255 255 / 0.12); }

/* Tables: no rules, header row reads like a heading over its column. */
/* Interactive diagrams (the tick explorer): the SVGs, a line of text-button
   controls, then a live readout that reserves its height so the page
   doesn't jump as it changes. */
.explorer { margin-bottom: var(--lh); }
.explorer .diagram { cursor: default; }
/* Server and screen side by side, stacked on phones. */
.tx-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2ch; }
@media (max-width: 34rem) { .tx-panels { grid-template-columns: 1fr; } }
.explorer .diagram:focus-visible { outline-offset: 4px; }
.tx-controls { display: flex; flex-wrap: wrap; gap: 0 3ch; margin-bottom: var(--lh); }
.tx-controls button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.tx-controls button:hover { background: var(--accent); color: var(--bg); }
.tx-controls button[aria-pressed="true"] { color: var(--fg); font-weight: bold; }
.tx-readout { min-height: calc(6 * var(--lh)); }
.tx-readout p { margin-bottom: 0; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { border: 0; padding: 0 2ch 0 0; vertical-align: top; }
th { font-weight: 700; }

@media (max-width: 34rem) {
  body { padding-top: calc(3 * var(--lh)); }
}
