/*
  The colour system. Two tiers, plain CSS, linked from the page's head, so the
  document is styled before any JavaScript arrives.

  This file is hand-maintained: it is the default interface, and its colours were
  chosen rather than ported. The themes in `themes/` are not — each is
  generated by `make themes` from a manifest naming an upstream palette and which
  of its colours carries each role. See `internal/theme`.

  ## Tier 1 — the palette

  A limited set of raw colours. These are the *only* colour literals in the
  codebase; `make check` fails on a literal anywhere else, including elsewhere in
  this file. Palette names describe the material, never the use: `--p-paper`, not
  `--p-card-background`.

  ## Tier 2 — the roles

  Every semantic token is a reference to a palette entry. A role never contains a
  literal, so changing a colour is a one-line edit in tier 1 and nothing has to
  be hunted down. Dark mode re-aliases the same roles to different palette
  entries — the role vocabulary is identical in both.

  This is aliasing, not computation: each value is still a colour that was
  chosen, so contrast is measurable rather than emergent.

  ## Rules

  - Every value is an explicit `oklch()` literal in the sRGB gamut, so the
    contrast a test measures is the contrast a browser paints.
  - No alpha-derived variants at the role tier. Where a wash is genuinely
    translucent (`--p-amber-strong`, `--p-scrim`) the alpha lives in the palette
    and the role aliases it like any other entry.
  - Three surface levels, hard cap: background < surface < surface-raised.
    Deeper nesting is expressed with borders, spacing and dividers, never a
    fourth tone. `surface-inset`, `surface-hover` and `surface-active` are not
    rungs on that ladder.
  - Role names only. Nothing is named for where it is used (no `--panel-bg`) or
    for what it was derived from.

  ## Org theming

  Companies will want documents to carry their own brand, so every value here is
  a real runtime custom property rather than a build-time constant: an org theme
  is a block of overrides injected into the server-rendered page, with no rebuild
  and no per-tenant bundle. Because the roles alias the palette, an org overrides
  *tier 1 only* — a handful of colours rather than forty semantic slots.

  `data-theme` is written on the root element, so a subtree can override the mode
  locally by carrying its own attribute.

  ## Themes

  A theme other than the two built in here is a stylesheet the server serves:
  the ones the product ships, built from the manifests in `backend/themes`, and
  the ones an organisation uploads. The session lists both with their addresses,
  so there is no list here to widen by hand. Its name is the id that lands in
  `data-palette`, and a comment on its first line declares the rest:

      maalstrom-theme: Tokyo Night | dark

  after the colon the name a person reads, then the modes it has. (Written
  without its comment delimiters because CSS has no nested comments: an inner
  close would end this one early and turn the rest of it into stylesheet.)

  Up to three blocks, each matching the root or any element:

      [data-palette='id']                     the material, both modes
      [data-palette='id'][data-theme='light'] the roles that carry a hue
      [data-palette='id'][data-theme='dark']  the same, other flavour

  Material is a pure tier 1 override and no role hears about it. The hue-carrying
  roles have to be stated because the default interface has no chroma to
  re-alias — its primary is ink — and because a theme's accents rarely survive
  being used in the mode they were not drawn for. They are: the three
  `--highlight*`, the seven `--accent*`, and `--ring`.

  What a theme cannot reach is as deliberate. The diff's green and red, the
  three verdict colours, and the pigments a cover is drawn in are stated once
  and never re-aliased: a reader who has learned that green means added has
  learned it everywhere, an alarm that follows the theme can be made quiet by
  choosing a quiet theme, and a project's colour is identity rather than
  decoration — `the purple one` has to mean the same thing to two people
  reading in two themes.

  Any element, not only the root, because the roles below are keyed on
  `[data-theme]` rather than on `:root[data-theme]`. A role is substituted where
  it is declared, so an element carrying both a palette and a mode restates the
  roles for itself and everything inside it resolves against that palette. Which
  is what lets a theme be drawn in miniature — a swatch in the theme menu is a
  scrap of interface wearing a theme the page is not.

  Adding a shipped theme is adding a manifest in `backend/themes` — an upstream
  palette to read and which of its sixteen carries each role. Every ladder in
  one is derived when the server starts, so a theme states what is particular to
  it and nothing that is true of all of them.
*/

/* Weightless, so a theme's material beats it whatever order the two arrive
   in. In a build this file lands at the end of the head, after the theme the
   head script linked; at equal weight the later one wins, and every theme
   would be worn on the default's neutrals. */
:where(:root, [data-palette='default']) {
  color-scheme: light dark;

  /* ── Tier 1: palette ────────────────────────────────────────────────────
     The only colour literals in the codebase. */

  /* Absolute black and white, which no theme owns. The mark is drawn in them
     so that it is the same in every theme rather than a tint of each. */
  --p-black: #000;
  --p-white: #fff;

  /* The same, under names no theme restates (a theme's own white and black
     are often greys): what a coat of light and a coat of shade are made of. */
  --p-light: #fff;
  --p-shadow-black: #000;

  /* ── The ladder ───────────────────────────────────────────────────────────

     One lightness per material, stated once and shared by every neutral
     family. A family is a hue and a chroma; it does not get to choose how
     light its own paper is.

     This is the whole reason two grounds are affordable. Contrast is almost
     entirely a matter of lightness in OKLCH, so a ratio checked against one
     family holds for the other — ink on paper is the same distance in sand as
     it is in slate, and a rung moved here moves in both at once. Families
     free to pick their own lightnesses would need every pair checked twice,
     and would drift apart the first time one of them was adjusted alone.

     Substituted into `oklch()` rather than multiplied out, so the rung is
     still legible in the value it produces. */
  /* Three planes in light, and they have to be three. A card on the page and
     the same card lifted were both at the top of the ladder for a while, which
     made focusing a comment thread change nothing and hid a composer inside
     the card it sat in. Paper is the brightest sheet and stays where it is;
     the card sits below it, and the page below that.

     Wider steps here than in dark. Equal OKLCH steps are equal differences,
     but a light interface is looked at with the eye adapted to its own
     brightness, and the same three points that separate two darks plainly
     reads as nothing near white. */
  --l-paper: 99.5%;
  --l-paper-card: 96.5%;
  /* Between the page and a card, because a row can be on either and has to
     answer the pointer on both. On the page it lifts; on a card it darkens.
     Not the inset's rung, which it borrowed for a while: the two have nothing
     to do with each other, and the first time the inset moved for its own
     reasons the hover went with it and landed half a point off the page. */
  --l-paper-hover: 95%;
  --l-paper-shade: 93.5%;
  --l-canvas: 93%;
  /* Under the page, as every edge in light mode is. Half a point under it, as
     it was, an edge drawn on the page itself — the rail's, the bar's, a
     column's — was the page's own colour and could not be seen; it only showed
     on a card. Two points under it shows on both, and stays softer than the
     hairline. */
  --l-rule-soft: 91%;
  --l-canvas-sunk: 91%;
  --l-rule: 89.5%;
  --l-rule-strong: 78%;

  --l-ink-subtle: 64%;
  --l-ink-muted: 48%;
  --l-ink: 25%;

  --l-chalk: 93.5%;
  --l-chalk-muted: 74%;
  --l-chalk-subtle: 60%;

  --l-rule-dark-strong: 44%;
  --l-soot-press: 30%;
  --l-rule-dark: 29.5%;
  --l-soot-hover: 23.5%;
  --l-soot-lift: 30%;
  --l-rule-dark-soft: 25%;
  --l-soot-raised: 21.5%;
  --l-soot-sunk: 19.5%;
  --l-soot: 17.5%;

  /* ── Sand ─────────────────────────────────────────────────────────────────

     The warm family, and the default. Hue 97–99 at a chroma low enough that
     nobody would call it yellow — what it reads as is paper rather than
     screen, which is the point in something made for reading documents.

     Against the blue it is nearly opposite on the wheel, 163° away, so the
     blue is at its loudest here and the green at 148 sits quiet. */

  /* Paper — the light material. */
  --p-canvas: oklch(var(--l-canvas) 0.0161 99); /* #f0eee2 */
  --p-canvas-sunk: oklch(var(--l-canvas-sunk) 0.017 99);
  --p-paper: oklch(var(--l-paper) 0.0067 97); /* #fdfcf7 */
  --p-paper-card: oklch(var(--l-paper-card) 0.009 98);
  --p-paper-hover: oklch(var(--l-paper-hover) 0.01 98);
  --p-paper-shade: oklch(var(--l-paper-shade) 0.011 98);

  /* Ink — the dark material, faintly cool against the warm paper. */
  --p-ink: oklch(var(--l-ink) 0.0177 271); /* #1e212a */
  --p-ink-muted: oklch(var(--l-ink-muted) 0.013 271);
  --p-ink-subtle: oklch(var(--l-ink-subtle) 0.01 271);

  /* Rules — hairlines on paper. */
  --p-rule-soft: oklch(var(--l-rule-soft) 0.01 99);
  --p-rule: oklch(var(--l-rule) 0.012 99);
  --p-rule-strong: oklch(var(--l-rule-strong) 0.012 99);

  /* Soot — the dark material as a surface. Same hue as paper, so the two modes
     read as one material under different light. */
  --p-soot: oklch(var(--l-soot) 0.008 99);
  --p-soot-sunk: oklch(var(--l-soot-sunk) 0.008 99);
  --p-soot-raised: oklch(var(--l-soot-raised) 0.009 99);
  --p-soot-hover: oklch(var(--l-soot-hover) 0.0095 99);
  --p-soot-lift: oklch(var(--l-soot-lift) 0.01 99);
  --p-soot-press: oklch(var(--l-soot-press) 0.01 99);

  /* Chalk — ink's counterpart on soot. */
  --p-chalk: oklch(var(--l-chalk) 0.008 99);
  --p-chalk-muted: oklch(var(--l-chalk-muted) 0.008 99);
  --p-chalk-subtle: oklch(var(--l-chalk-subtle) 0.008 99);

  --p-rule-dark-soft: oklch(var(--l-rule-dark-soft) 0.008 99);
  --p-rule-dark: oklch(var(--l-rule-dark) 0.009 99);
  --p-rule-dark-strong: oklch(var(--l-rule-dark-strong) 0.01 99);

  /* Amber — the anchor colour, and the only chroma in the interface. The
     translucent rungs are palette entries because they layer over running text
     and cannot be solved from the solid at the role tier. */
  /* On the wheel, at ochre's hue. It sat at 75 while the interface had no
     other chroma in it and nothing to be off from; with the pigments anchored
     on the blue it was the one colour that was a member of nothing — seven
     degrees from ochre, which is near enough to read as a mistake and too far
     to read as a relationship.

     Its own token rather than `--p-ochre` because the two are different
     claims. A pigment is identity, picked by a hash and meaning nothing; this
     is vocabulary, and a reader who has learned that yellow means somebody
     wrote something here has learned it everywhere. Every shipped theme
     restates it in its own yellow for that reason. */
  --p-amber: oklch(80% 0.165 82);
  --p-amber-strong: oklch(80% 0.165 82 / 0.45);
  --p-amber-soft: oklch(80% 0.165 82 / 0.16);
  /* Chroma spent down rather than alpha: a settled anchor should be visible as
     a mark on the page and not as a claim on attention. Dropping only the alpha
     makes it the same signal turned down, which still reads as amber. */
  --p-amber-spent: oklch(80% 0.02 82 / 0.11);

  /* Sap and madder — added and removed.

     Kept clean and a little cool, against the instinct to harmonise them with
     the warm paper. A green warmed toward the page turns khaki over cream and
     a red warmed the same way turns brick — both go muddy exactly where they
     have to be legible. Sitting slightly apart from the paper is what makes
     them read as marks on it.

     Translucent because they layer over running text, and the alpha cannot be
     solved from the solid at the role tier. The washes carry more chroma than
     the solids: a tint has to survive being a fifth of itself. */
  --p-sap: oklch(66% 0.16 158);
  /* Strong enough to be read at a glance rather than found. A diff is the one
     place a reader is already scanning for exactly two colours, so a wash that
     only suggests a changed line is a wash doing half its job.

     Removed sits a little under added on both counts, because red carries
     further than green at the same strength and matching the numbers would
     make the deletions louder than the additions. */
  --p-sap-soft: oklch(76% 0.21 158 / 0.48);
  --p-madder: oklch(58% 0.19 18);
  --p-madder-soft: oklch(68% 0.22 18 / 0.42);

  /* ── Hues ───────────────────────────────────────────────────────────────
     The six ANSI colours and their bright forms, which is the vocabulary every
     terminal theme is already written in — Tokyo Night, Catppuccin, Melange and
     Galaxy all publish these upstream. Carrying them means porting a theme is
     transcription rather than invention, and a theme that wants its own look
     overrides twelve values instead of restating a dozen roles.

     Twelve rather than sixteen: ANSI's black, white and their bright forms are
     greys, and the five-rung surface ladder above is a better-considered answer
     for those than four flat values. A theme port should map its greys onto the
     ladder and leave these to the hues.

     Material, not meaning. Nothing here says "added" or "anchored" — the roles
     below do, by aliasing specific entries. What these are for is the places
     that want colour without wanting to say anything: a project's cover, a tag,
     a chart series.

     The light and dark sets differ, and are stated in the mode blocks below for
     the same reason the surfaces are: a red that carries on paper is not the
     red that carries on soot. */

  /* Alarm — a field for something that must not be missed, and the ink on it.
     Not the diff's red, which is borrowed every time this is needed and means
     something else: `--diff-removed` is a wash under text that was taken out,
     tuned to be quiet enough to read through. A thing that went wrong needs the
     opposite of quiet, and a role that has to be solid cannot be the one that
     has to be translucent. */
  --p-alarm: oklch(55% 0.2 18);
  --p-alarm-ink: oklch(98% 0.012 18);

  /* What is legible on sap and on amber, for the two verdicts that have a
     solid form. Not `--p-paper` and `--p-ink`: those are the page's, and a
     theme moves them — so a success field would be struck in whatever the
     theme calls white, over a green it cannot move. The field and its ink have
     to be decided together or not at all. */
  --p-sap-ink: oklch(99% 0.01 158);
  --p-amber-ink: oklch(26% 0.05 82);

  /* ── Pigments ───────────────────────────────────────────────────────────
     The drawing set: six hues and a lighter form of each, used for covers,
     the marks beside rows, and a project's code in the rail. Nothing that
     means anything — these are what a thing is, not how it is going.

     Outside every theme, like the printing stock they are struck on, and for
     the stronger version of the same reason. A cover's colour is the one piece
     of identity a project carries that is not words: `the purple one` has to
     mean the same thing to two people reading in two themes, and it cannot if
     the hue is whatever their theme calls magenta.

     They were the ANSI twelve, which is the one set every theme overrides —
     so every project changed colour with the reader's preferences, and half
     the time into something a cover cannot be drawn in. A palette tuned for
     syntax is tuned to sit quietly behind text at low chroma, and a 4x4 field
     of flat tiles needs the opposite.

     Pigment names, like sap and madder above, because that is what these are:
     a fixed set of inks a press has, rather than slots a theme fills.

     Poster ink: pitched off a screen-printed one, and the numbers are the ones
     measured from it. Near the gamut wall where a hue has room and honest
     where it has not — 0.21 of chroma in the red, 0.23 in the magenta, and
     0.125 in the cyan because cyan runs out at 0.138 and no amount of wanting
     moves it.

     Not matched across the six. One figure for all of them is the figure the
     weakest hue can reach, and holding the other five down to meet it is what
     made the first version of this set look washed — a palette where nothing
     is allowed to be louder than cyan is a palette of cyans. The poster does
     not do that: its reds are at the wall and its blues are not, and it reads
     as one press run anyway because the lightnesses are close and the hues are
     spaced.

     Lightness differs per hue, which is not a flaw: a blue cannot be both pale
     and vivid in sRGB and a yellow cannot be dark and vivid, so each sits
     where its hue has something to give.

     One strength each, and no lighter form. The paler blocks on a cover are
     overprints of these — the ink laid down at a fraction of itself, the way
     the reference makes its tints — rather than separate inks. A second
     printed colour that is only a weaker version of the first is a plate
     nobody needed.

     Anchored on the blue the mark's tile is struck in, and spaced at exact
     sixths from it. `--p-ultramarine` *is* that blue — `#095FFD`, which is
     `oklch(55% 0.246 262)` — so the one colour the product asserts is a
     member of the set rather than a seventh thing standing beside it.

     Spaced at sixths, except where a hue is better slightly off it. Even
     spacing was held to for a while on the grounds that it makes the
     arithmetic above exact — the opposite of a hue really three steps away,
     the two beside it really one. Nothing performs that arithmetic: a
     fragment's ink is a hash of its id onto a name. A rule that is paid for
     in worse greens and buys nothing is not a rule.

     The chroma is as far as sRGB goes at each hue's chosen lightness, near
     enough. A blue at this lightness carries more of it than a cyan does,
     which is why the numbers differ and not an inconsistency to even out —
     evened out, every pigment would be as weak as the weakest hue. */
  --p-vermilion: oklch(62% 0.22 22);
  --p-ochre: oklch(80% 0.165 82);
  /* Deeper than the rest of the set and off the sixth by eight degrees. A
     green at the lightness the others take is a lime, which reads as a state
     — a thing passing a check — rather than as an identity. Carried down to
     where green is still green, it stops making that claim. */
  --p-viridian: oklch(58.4% 0.161 148);
  --p-cerulean: oklch(72% 0.12 202);
  --p-ultramarine: oklch(55% 0.246 262);
  --p-tyrian: oklch(62% 0.225 322);
  /* Three strengths, one hue.

     A pigment above is the full strength. These are the two weaker draws of
     the same ink: `light`, which still has colour in it and can carry text of
     its own hue; and `wash`, which is a tinted ground and nothing else. Not a
     continuous ramp — three steps, far enough apart that choosing between
     them is a decision rather than a nudge.

     Chroma falls as lightness rises because the gamut closes there, so a wash
     holds about a sixth of the full strength's and a light about two thirds.
     Those are not ratios anybody picked; they are where sRGB stops.

     Only the hues that have a use here have one. A set of three for every
     pigment would be eighteen colours, most of which nothing would ever
     name. */
  --p-ultramarine-light: oklch(82.8% 0.086 262);
  --p-ultramarine-wash: oklch(90.8% 0.044 262);

  /* Either side of the full strength, close enough that pressing a control
     reads as the same control under a thumb. The three strengths above are
     about how much ink is on the page; these two are about what a button does
     when it is touched, which wants a step small enough to be a state rather
     than a second colour. */
  --p-ultramarine-lift: oklch(63% 0.21 262);
  --p-ultramarine-press: oklch(45.4% 0.221 262);

  /* Dragged-over text. Translucent, and the alpha is here rather than at the
     role tier because it has to lie over running text on whatever it lands on
     — a page, a card, a field — and a solid would need one value per surface.

     The blue, because nothing else can have it: green and red are a diff,
     yellow is an annotation, and a selection is the one transient thing in the
     interface, so it never sits on the same glyphs as a focus ring. Inside a
     document this is not used — a selection there is the beginning of a
     comment and is painted in the colour that comment will become. */
  --p-ultramarine-select: oklch(55% 0.246 262 / 0.38);

  /* The same job on soot, and not the same value. A wash is composited against
     what is under it, so one alpha cannot serve both grounds: the brand blue
     is darker than a dark page and sinks into it, where on paper it is the
     thing that stands out. This one is lighter than the ground rather than
     darker, which is what makes a selection read as laid *over* the text in
     both modes instead of cut out of it in one. */
  --p-ultramarine-select-dark: oklch(66% 0.2 262 / 0.36);

  /* The same mark at rest. An anchor is a selection that was kept, so it is
     the colour the selection was — quiet while nobody is looking at it, and
     back to full strength when its comment is under the pointer. */
  --p-ultramarine-trace: oklch(55% 0.246 262 / 0.14);
  --p-ultramarine-trace-dark: oklch(66% 0.2 262 / 0.15);

  /* Blue is the one that also goes the other way: it is the colour the
     product asserts, so it is the one that has to hold a ground with white
     type on it, and the full strength is too light for that. */
  --p-ultramarine-deep: oklch(37.1% 0.245 262);

  /* Mint is the one member of any of these that has a use beyond its own hue:
     at this lightness it carries the blue rather than competing with it, the
     two being far enough apart to read as two colours and close enough in
     weight to read as a pair. */
  --p-viridian-light: oklch(82.8% 0.134 154);
  --p-viridian-wash: oklch(96.1% 0.041 154);

  /* Printing stock — the sheet a cover is struck on, and the ink on it.
     Outside every theme on purpose, and the one pair here that is. A cover is
     an object lying on the page rather than part of the page, so its paper is
     paper under any theme; taken from the theme's own white it was cream in
     melange and yellow in gruvbox, which is a theme deciding what colour paper
     is. Barely off white, because a flat #ffffff on a screen is a light
     source rather than a sheet. */
  --p-stock: oklch(98.6% 0.0015 106);
  --p-stock-ink: oklch(21.5% 0.011 271);

  /* Scrims and shadow tints. */
  --p-scrim: oklch(20% 0.01 90 / 0.3);
  --p-scrim-dark: oklch(10% 0.005 90 / 0.55);
  --p-shadow-soft: oklch(20% 0.01 90 / 0.07);
  --p-shadow: oklch(20% 0.01 90 / 0.11);
  --p-shadow-dark-soft: oklch(0% 0 0 / 0.4);
  --p-shadow-dark: oklch(0% 0 0 / 0.45);
  --p-hairline-light: oklch(20% 0.01 90 / 0.05);
  --p-hairline-dark: oklch(100% 0 0 / 0.07);

  /* ── Non-colour scales ─────────────────────────────────────────────────── */

  /* The height of a small control standing in a row of them — a select, a
     search field, a segmented toggle. Stated once because a row of controls at
     two heights reads as two rows, and each of them working its own height out
     of its contents is a row that agrees only by coincidence. */
  --control: 2.1rem;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-full: 999px;

  /* How wide a page of interface is, and how far its content sits from the
     edges. Shared because the answer has to be: the rail is fixed, so two
     pages with different measures have their left edges in different places
     and moving between them slides the whole interface sideways.

     Not the document, which is its own layout — a reading column with a margin
     for comments beside it, sized to the text rather than to the chrome. */
  --page: 72rem;
  --page-pad: 2.5rem 1.5rem 4rem;

  /* Where anything that sticks to the top of the page sticks. Nothing is
     across the top, so the edge of the window; one number so they all agree. */
  --topbar: 0px;

  /* `serif` is the document; `sans` is the interface around it. */
  --font-serif: 'Literata Variable', ui-serif, Georgia, serif;
  /* The wordmark, and nothing else. Listed here because it is type, but it is
     not part of the scale below — there is one string set in it. */
  --font-display: 'Gabarito', ui-sans-serif, system-ui, sans-serif;
  --font-sans: 'Inter Variable', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono Variable', ui-monospace, 'SF Mono', Menlo, monospace;

  /* The interface's type scale: the ui-kit's, in Instruqt's frontend
     (ui-kit/foundation/typography.ts), step for step, so a size means the same
     thing in both products. Seven sizes, each with its line height, and a rule
     for when it is the one:

       xs    12/18  fine print: badges, timestamps, eyebrows
       sm    13/20  dense body: table cells, sidebars, list metadata, code
       base  14/22  the default body: anything read as prose in a panel,
                    a form or a dialog, the chat and the comments among them
       lg    16/24  long reading, and subsection headings at semibold
       xl    20/28  card, dialog and panel titles
       2xl   24/32  page and section titles
       3xl   32/40  rare: an empty state's headline

     A size and its line height are one decision: set `--leading-<step>` with
     `--text-<step>`. There is no step between base and lg; emphasis at the
     body size is a weight, not a pixel. */
  --text-xs: 0.75rem;
  --leading-xs: 18px;
  --text-sm: 0.8125rem;
  --leading-sm: 20px;
  --text-base: 0.875rem;
  --leading-base: 22px;
  --text-lg: 1rem;
  --leading-lg: 24px;
  --text-xl: 1.25rem;
  --leading-xl: 28px;
  --text-2xl: 1.5rem;
  --leading-2xl: 32px;
  --text-3xl: 2rem;
  --leading-3xl: 40px;

  /* Three weights: normal for anything read in sentences, medium for what
     names something — a label, a list's titles — and semibold for headings,
     and only headings. */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Five roles, each a size and a weight from above and never numbers of its
     own, for the compositions that repeat: `font: var(--type-body)`. They set
     no colour; secondary text is a role and a colour token, not a smaller
     size. */
  --type-heading-1: var(--weight-semibold) var(--text-2xl) / var(--leading-2xl) var(--font-sans);
  --type-heading-2: var(--weight-semibold) var(--text-xl) / var(--leading-xl) var(--font-sans);
  --type-body: var(--weight-normal) var(--text-base) / var(--leading-base) var(--font-sans);
  --type-label: var(--weight-medium) var(--text-sm) / var(--leading-sm) var(--font-sans);
  --type-code: var(--weight-normal) var(--text-sm) / var(--leading-sm) var(--font-mono);

  /* The document's own scale, apart from the interface's: it is a page read
     at length in the serif, not a panel, and it is the part of the product a
     reader will set for themselves — a size, a face, a leading, as an e-reader
     lets them. Everything the document draws its type from is here, so that
     setting is these tokens and nothing else.

     Headings roughly a 1.33 step from the 16px text, so each level is
     unmistakably a level rather than slightly larger text. */
  --doc-text: 1rem;
  --doc-small: 0.9375rem;
  --doc-h3: 1.4375rem;
  --doc-h2: 1.9375rem;
  --doc-h1: 2.75rem;

  --leading-tight: 1.3;
  --leading-normal: 1.65;

  /* Code, coloured.

     Aliases onto the sixteen rather than onto colours of their own, which is
     what makes a highlighted block wear whatever theme is on: every theme
     states all sixteen, so these follow without a theme having to know that
     syntax colouring exists. The default's set is here too, for the same
     reason.

     Conventional assignments. A reader who has seen a JSON document coloured
     anywhere else should not have to learn this one. */
  --syntax-key: var(--p-blue);
  --syntax-string: var(--p-green);
  --syntax-number: var(--syntax-constant);
  --syntax-atom: var(--p-yellow);
  /* Braces, brackets, commas. Quiet: they are structure, and structure that
     competes with content is punctuation somebody has to read past. */
  --syntax-punctuation: var(--foreground-subtle);

  /* The rest of a program, assigned as vim's own colours assign its syntax
     groups to the sixteen: statements yellow, types and identifiers cyan,
     constants magenta, specials red. Comments are the exception, set back in
     the page's quiet text rather than given a hue: a comment is read after the
     code it is beside, not instead of it. Normal slots in both modes, never
     the bright ones, which a light theme makes for a dark background. */
  --syntax-comment: var(--foreground-subtle);
  --syntax-keyword: var(--p-yellow);
  --syntax-type: var(--p-cyan);
  --syntax-function: var(--p-blue);
  --syntax-constant: var(--p-magenta);
  --syntax-special: var(--p-red);

  --z-base: 0;
  --z-sticky: 10;
  --z-float: 20;
  --z-overlay: 100;

  /* A resolved thread's mark: still there, no longer live. Nearly without
     chroma on purpose — it is the one anchor state that is not asking for
     anything, and a settled conversation that still carries the live colour is
     a conversation a reader keeps re-reading to find out whether it is over.

     Mode-invariant, which the live states can no longer be: this one is faint
     enough that the ground it sits on does not change what it costs.

     The live states — `--highlight` and `--highlight-soft` — are stated per
     mode further down, because they are the selection's blue and a wash has to
     be darker than paper and lighter than soot to read as laid over the text
     rather than cut out of it. */
  --highlight-settled: var(--p-amber-spent);

  /* Added text when reading a diff. Its own wash rather than the anchor amber:
     "there is a conversation here" and "this is new since the last version"
     are different claims and must not look alike. */
  /* Green added, red removed — the vocabulary every reviewer already knows.
     Mode-invariant like the anchor wash: a diff means the same thing in both
     themes, so the hues do not shift. Only the text colour re-aliases, since
     deep red on soot is unreadable. */
  --diff-added: var(--p-sap-soft);
  --diff-added-border: var(--p-sap);
  --diff-removed: var(--p-madder-soft);
  --diff-removed-border: var(--p-madder);

  /* ── Verdicts ───────────────────────────────────────────────────────────
     How something went: it worked, it needs looking at, it failed. For
     outcomes rather than for anything a person decided — a resolved thread is
     settled, not "good".

     In the theme's own green, yellow and red, so a theme is worn all the way
     through: Dracula's green says it worked on a Dracula page. Still green,
     yellow and red in every theme, which is what a reader learns them by.

     Three forms each. The solid is a field with something written on it, so it
     comes with its own ink: the hues are tuned to sit on their mode's
     surfaces, light on dark and dark on light, so what is written on one is
     the other end — `--hue-ink`, set per mode. The soft is a wash that goes
     under running text. */
  --success: var(--p-green);
  --success-foreground: var(--hue-ink);
  --success-soft: color-mix(in oklab, var(--p-green) 28%, transparent);

  --warning: var(--p-yellow);
  --warning-foreground: var(--hue-ink);
  --warning-soft: color-mix(in oklab, var(--p-yellow) 26%, transparent);

  --danger: var(--p-red);
  --danger-foreground: var(--hue-ink);
  --danger-soft: color-mix(in oklab, var(--p-red) 28%, transparent);

  /* Something is happening. Not a verdict — nothing has gone any way yet — so
     it is the one state here that takes the theme's own colour, and the only
     thing it has to be is different from the three that mean an outcome. */
  --going: var(--accent);
}

/* ── Slate ────────────────────────────────────────────────────────────────

   The cool family: the same ladder, the blue's own hue, and a chroma low
   enough that it reads as grey rather than as blue-grey.

   Not a theme — a ground. A theme replaces the palette and brings its own
   neutrals with it, so this applies to the default palette only and says
   nothing once one is chosen. `data-ground` rather than a second value of
   `data-palette` for exactly that reason: they are not alternatives to each
   other, and spending a palette id on one would mean the eight that exist
   today become sixteen the moment either axis grows.

   Deliberately not at zero chroma. A dead neutral beside a pigment at 0.246
   reads as missing something rather than as restraint — the eye takes the
   grey for a failed colour. A sixth of a hundredth is below anything anyone
   would name, and is the difference between a grey that belongs to this blue
   and one that merely sits near it.

   Only the neutrals. The pigments, the amber and every alarm colour are the
   same in both: a reader who has learned that a project is the green one has
   not also learned which ground they were standing on at the time. */
[data-ground='slate'] {
  --p-canvas: oklch(var(--l-canvas) 0.006 262);
  --p-canvas-sunk: oklch(var(--l-canvas-sunk) 0.007 262);
  --p-paper: oklch(var(--l-paper) 0.003 262);
  --p-paper-card: oklch(var(--l-paper-card) 0.005 262);
  --p-paper-hover: oklch(var(--l-paper-hover) 0.006 262);
  --p-paper-shade: oklch(var(--l-paper-shade) 0.005 262);

  --p-ink: oklch(var(--l-ink) 0.018 262);
  --p-ink-muted: oklch(var(--l-ink-muted) 0.013 262);
  --p-ink-subtle: oklch(var(--l-ink-subtle) 0.01 262);

  --p-rule-soft: oklch(var(--l-rule-soft) 0.006 262);
  --p-rule: oklch(var(--l-rule) 0.008 262);
  --p-rule-strong: oklch(var(--l-rule-strong) 0.009 262);

  /* Carrying more than the light side does, and more than looks right written
     down. Chroma reads as less the darker a colour is — the same 0.009 that is
     plainly cool on a near-white page is five units per channel at 21% and the
     ground stops being a choice at all. This is roughly twice the light
     family's and still nobody would call it blue. */
  --p-soot: oklch(var(--l-soot) 0.018 262);
  --p-soot-sunk: oklch(var(--l-soot-sunk) 0.018 262);
  --p-soot-raised: oklch(var(--l-soot-raised) 0.02 262);
  --p-soot-hover: oklch(var(--l-soot-hover) 0.02 262);
  --p-soot-lift: oklch(var(--l-soot-lift) 0.021 262);
  --p-soot-press: oklch(var(--l-soot-press) 0.022 262);

  --p-chalk: oklch(var(--l-chalk) 0.005 262);
  --p-chalk-muted: oklch(var(--l-chalk-muted) 0.007 262);
  --p-chalk-subtle: oklch(var(--l-chalk-subtle) 0.008 262);

  --p-rule-dark-soft: oklch(var(--l-rule-dark-soft) 0.009 262);
  --p-rule-dark: oklch(var(--l-rule-dark) 0.01 262);
  --p-rule-dark-strong: oklch(var(--l-rule-dark-strong) 0.011 262);
}

/* ── Tier 2: roles ──────────────────────────────────────────────────────── */

/* What every quiet control is filled with under a pointer, and while it is the
   one that is on — current, open, pressed, chosen. One rule for all of them,
   in every theme and both modes: the writing laid thinly over whatever is
   behind it. Translucent, so it is the same step on the page, on a card, in
   the rail and in a raised menu, where an opaque tone tuned for one ground
   vanishes into another. `make check` fails on a hover drawn any other way. */
[data-theme] {
  --hover: color-mix(in oklch, var(--foreground) 7%, transparent);
  --selected: color-mix(in oklch, var(--foreground) 11%, transparent);
}

/* ── Layers ───────────────────────────────────────────────────────────────

   Surfaces as layers of light. The window is the darkest surface, and every
   level up lays the same thin coat over whatever is under it, so a thing's
   height is how many coats it has rather than which of several named tones it
   was given. The coats are translucent and composite: a card on a pane is the
   pane plus one more.

     0  the window: the rail, the tab strip, the gaps between panes
     1  a pane, the tab it shows, the rail's current section
     2  a card in a pane — the document, a comment — a chip, a field
     -  a recess: a shade under what it is cut into rather than a coat over it

   Every raised role is one coat and the recessed one a coat of shade, so
   everything that stands on a surface is converted at once. The strength of a
   coat and what it is made of are per mode (above). What floats over the work
   is a coat too, and so would show the work through it: it is frosted where
   it is drawn, so it shows its colour and not the words under it.

   Edges are quieter than the coats, so levels read by light rather than by
   lines. Focus is light too: the brightest edge on the screen rather than a
   colour laid over the wash. */
[data-theme] {
  --coat-fill: color-mix(in srgb, var(--coat-from) var(--coat), transparent);
  --shade-fill: color-mix(in srgb, var(--p-shadow-black) var(--shade), transparent);
  --focus-fill: color-mix(in srgb, var(--p-light) var(--focus-coat), transparent);

  --surface: var(--coat-fill);
  --surface-raised: var(--coat-fill);
  /* A quiet fill for small things set into a surface: a badge, a chip, a
     table's head. Not a state; those are `--hover` and `--selected`. */
  --surface-active: var(--coat-fill);
  --surface-inset: var(--shade-fill);
  /* A secondary control is a coat over whatever it stands on, and sinks
     under it when pressed. */
  --neutral: var(--coat-fill);
  --neutral-active: var(--shade-fill);
  /* Furniture that is not a surface the page sits on: on the window itself. */
  --chrome: transparent;

  --border-subtle: color-mix(in oklch, var(--foreground) 5%, transparent);
  --border: color-mix(in oklch, var(--foreground) 9%, transparent);
  /* The hairline round a recessed field, its own role rather than a reuse of
     `--border-subtle`: a recess is close to what it is cut into, so its edge
     is most of what says it is recessed at all. */
  --border-inset: color-mix(in oklch, var(--foreground) 9%, transparent);

  /* What floats over the work: a coat, frosted. */
  --frost: blur(24px) saturate(1.4);

  /* What something stuck over scrolling text — a page's head — fills with so
     the text does not read through it. The ground, solid, where the page is
     on the window; inside a pane, which is a translucent coat, no fill and a
     blur instead, so the head is the pane's own colour with the text going by
     under it blurred (see workspace.css). A blur alone, without the floats'
     saturation, which turned a band of blurred text the theme's colour. */
  --stuck-fill: var(--background);
  --stuck-frost: none;

  /* The window, kept by name: `--background` is redefined inside a pane to
     what a page there is laid on (see workspace.css), and the window is still
     the window. */
  --window: var(--background);
}

[data-theme='light'] {
  /* The logo: black on a light ground, never a theme's ink. */
  --mark: var(--p-black);

  /* The window, darker than the paper so the coats over it have somewhere to
     climb from. White over paper shows far less than white over soot, so
     light takes a heavier coat, and a darker window under it, for the same
     step. See "Layers" below.

     No lighter than the default's own window, whatever the theme's paper. A
     coat of white closes half the distance to white, so a window that starts
     near it leaves every level after it a smaller step, and a theme drawn on
     near-white paper had its levels run together. The hue and chroma are
     still the theme's. */
  --p-window: oklch(from color-mix(in oklch, var(--p-canvas) 90%, var(--p-ink)) min(l, 0.862) c h);
  --background: var(--p-window);
  --coat-from: var(--p-light);
  --coat: 50%;
  --shade: 6%;
  --focus-coat: 18%;

  --overlay: var(--p-scrim);

  --foreground: var(--p-ink);
  --foreground-muted: var(--p-ink-muted);
  --foreground-subtle: var(--p-ink-subtle);

  --border-strong: var(--p-rule-strong);

  /* What is written on a solid verdict: the hues are dark here, so paper. */
  --hue-ink: var(--p-paper);

  /* The window's light (see body in document.css): how much of the accent, at
     most how saturated, and how much of the lifted surface. More of the
     surface than in dark, where a coat of white is a stronger step. */
  --tint: 15%;
  --tint-chroma: 0.153;
  --glow: 70%;

  /* The primary action is ink, not a colour. */
  /* The blue, which is the one colour the product asserts and so is the one a
     primary control is struck in. Ink was here for a long time and was the
     safe answer: a black button is nobody's brand and clashes with nothing.
     It also meant the thing a reader is meant to press looked exactly like the
     thing they are meant to read.

     A theme replaces all of this. What is here is what the product looks like
     wearing its own ground, and a theme that kept this blue would be a theme
     that had not been allowed to finish. */
  --accent: var(--p-ultramarine);
  --accent-hover: var(--p-ultramarine-press);
  --accent-active: var(--p-ultramarine-deep);
  --accent-foreground: var(--p-paper);
  /* Asked of each state as of the resting one: light on all three here. */
  --accent-hover-foreground: var(--p-paper);
  --accent-active-foreground: var(--p-paper);
  --accent-subtle: var(--p-ultramarine-wash);
  --accent-border: var(--p-ultramarine-light);
  --accent-text: var(--p-ultramarine-deep);

  /* A secondary control stands on the page as often as on a card, so it is
     held above both rather than tucked between them — aimed at the inset's
     rung it was half a point off the page, and its hover was the page exactly.
     It lifts to the card's tone and sinks under the page when pressed. */
  --neutral-foreground: var(--p-ink);

  --ring: var(--p-ultramarine);
  --selection: var(--p-ultramarine-select);

  /* An anchor is a selection that was kept, so it is drawn in the colour it
     was made in. Amber said "somebody wrote something here" in a product whose
     only other colour was ink; now that the blue is what the interface is made
     of, a yellow mark on the page is the one thing in it that belongs to
     nothing. `--highlight` is the mark with its comment under the pointer,
     `--highlight-soft` the same mark at rest. */
  --highlight: var(--p-ultramarine-select);
  --highlight-soft: var(--p-ultramarine-trace);

  /* The hues, tuned to carry on paper: darker and a little denser than the
     dark set, because a pale colour on a light ground is a smudge. */
  --p-red: oklch(55% 0.19 22);
  --p-green: oklch(52% 0.13 150);
  --p-yellow: oklch(62% 0.13 80);
  --p-blue: oklch(52% 0.17 258);
  --p-magenta: oklch(52% 0.19 328);
  --p-cyan: oklch(55% 0.10 210);

  --p-bright-red: oklch(64% 0.20 22);
  --p-bright-green: oklch(62% 0.15 150);
  --p-bright-yellow: oklch(72% 0.14 80);
  --p-bright-blue: oklch(62% 0.17 258);
  --p-bright-magenta: oklch(62% 0.19 328);
  --p-bright-cyan: oklch(65% 0.11 210);

  /* The shadow tones on their own, for the few things that need to build an
     elevation rather than pick one — a book on a shelf casts a contact shadow
     and an ambient one, and neither of the two below is that. */
  --shadow-soft: var(--p-shadow-soft);
  --shadow: var(--p-shadow);

  --elevation-low: 0 1px 2px var(--p-shadow-soft), 0 0 0 1px var(--p-hairline-light);
  --elevation-high: 0 10px 30px var(--p-shadow), 0 0 0 1px var(--p-hairline-light);
}

[data-theme='dark'] {
  --mark: var(--p-white);

  /* The theme's own sunk surface rather than its page darkened toward black:
     black takes the hue out with the light, and a Dracula window that has
     lost its blue-grey is not Dracula any more.

     A coat is the theme's own lightest surface rather than white, so every
     level keeps the theme's tint instead of greying toward neutral; it is far
     darker than white, so it is laid on thicker for a like step. */
  --background: var(--p-soot-sunk);
  --coat-from: var(--p-soot-lift);
  --coat: 40%;
  --shade: 22%;
  --focus-coat: 6%;

  --overlay: var(--p-scrim-dark);

  --foreground: var(--p-chalk);
  --foreground-muted: var(--p-chalk-muted);
  --foreground-subtle: var(--p-chalk-subtle);

  --border-strong: var(--p-rule-dark-strong);

  /* What is written on a solid verdict: the hues are light here, so soot. */
  --hue-ink: var(--p-soot);

  /* The window's light: less of the accent than in light, where the same
     colour on a dark ground shows far more. */
  --tint: 15%;
  --tint-chroma: 0.12;
  --glow: 45%;

  /* Inverted: where light mode puts ink under paper-coloured text, dark mode
     puts chalk under soot-coloured text. Both read as "the solid one". */
  /* The same blue, at the same strength. A brand colour that goes paler in
     dark to keep its contrast is a brand colour a reader has to be told is the
     same one — the states move around it instead, lifting where light presses.

     The label on it stays paper in both modes: what is readable on this blue
     is white, and whether the page around it is light or dark does not change
     what is written on the button. */
  --accent: var(--p-ultramarine);
  --accent-hover: var(--p-ultramarine-lift);
  --accent-active: var(--p-ultramarine-press);
  --accent-foreground: var(--p-paper);
  /* The lift crosses into the light, where paper on it is faint; the press
     stays dark. */
  --accent-hover-foreground: var(--p-soot);
  --accent-active-foreground: var(--p-paper);
  --accent-subtle: var(--p-ultramarine-deep);
  --accent-border: var(--p-ultramarine-press);
  --accent-text: var(--p-ultramarine-light);

  --neutral-foreground: var(--p-chalk);

  --ring: var(--p-ultramarine);
  --selection: var(--p-ultramarine-select-dark);
  --highlight: var(--p-ultramarine-select-dark);
  --highlight-soft: var(--p-ultramarine-trace-dark);

  /* The hues, tuned to carry on soot: lighter than the light set, for the
     mirror of the same reason — a dark colour on a dark ground is a hole. */
  --p-red: oklch(68% 0.17 22);
  --p-green: oklch(72% 0.14 150);
  --p-yellow: oklch(80% 0.13 80);
  --p-blue: oklch(68% 0.14 258);
  --p-magenta: oklch(68% 0.16 328);
  --p-cyan: oklch(74% 0.09 210);

  --p-bright-red: oklch(76% 0.15 22);
  --p-bright-green: oklch(80% 0.13 150);
  --p-bright-yellow: oklch(87% 0.11 80);
  --p-bright-blue: oklch(77% 0.12 258);
  --p-bright-magenta: oklch(76% 0.14 328);
  --p-bright-cyan: oklch(82% 0.08 210);

  --shadow-soft: var(--p-shadow-dark-soft);
  --shadow: var(--p-shadow-dark);

  --elevation-low: 0 1px 2px var(--p-shadow-dark-soft), 0 0 0 1px var(--p-hairline-dark);
  --elevation-high: 0 10px 30px var(--p-shadow-dark), 0 0 0 1px var(--p-hairline-dark);
}
