<!-- generated by scripts/gen-docs.mjs from docs/system/theming.md. Edit the source and rerun. -->
# Theming

## Description

How another system is built on Cobalt without forking it. Behaviour comes from Base UI, every look comes from the tokens in `registry/cobalt/tokens.css`, and the components read only the tokens. A derived system is one block of token overrides on the element that carries the `cobalt` class. It changes colour, type, corners, sizes, padding, shadows and motion everywhere at once and touches no component.

## Tokens

| Knob | Tokens | What a derived system changes |
| --- | --- | --- |
| Colour | `--background`, `--foreground`, `--card`, `--popover`, `--muted`, `--border`, `--primary` and its family, `--good`, `--bad`, `--warning`, `--chart-1` to `--chart-6`, `--chart-spare` | Every surface, text and accent; hover and soft fills follow `--primary` |
| Type | `--font`, `--mono`, `--type-xs` to `--type-4xl` | The faces and the size of each step; each step keeps its leading as a ratio |
| Corners | `--r-xs`, `--r-sm`, `--r-md`, `--r-lg`, `--r-2xl`, `--r-4xl` | The base corners; `--r-xl` and `--r-3xl` derive from them, so tracks and popups stay concentric |
| Size | `--control-sm`, `--control`, `--control-lg`, `--nav-item`, `--row`, `--touch` | The height of every button, field, nav item and table row |
| Padding | `--pad-card`, `--pad-card-sm`, `--pad-popup`, `--gutter`, `--page` | A card's padding and gaps, a popup's inset, the page's side padding and column |
| Elevation | `--edge`, `--elev-glass`, `--elev-raised`, `--elev-floating`, `--elev-sheet`, `--blur-glass` | The shadows and the hairline built into them |
| Motion | `--t-press` to `--t-travel`, `--curve`, `--curve-in-out`, `--curve-sheet`, `--curve-shake`, `--curve-layout`, `--curve-settle` | Every CSS transition; the four pieces animated in script (Crossfade, Grow, StateButton, Swap) read `registry/cobalt/lib/motion.ts`, which `registry/cobalt/lib/motion.test.ts` holds equal to the tokens |
| Focus | `--line-focus`, `--focus-offset`, `--ring` | The keyboard outline |

## Specimens

The same card twice. On the left is Cobalt with the reader's own settings. On the right is a derived system of 30 overrides, with its CSS one press away under the frames. It has warm paper surfaces, an ochre accent with dark labels, corners of 2 to 8px, 32px controls, 16px card padding and the system font, in both themes. Its hue is far from every accent preset and no reader setting changes surfaces, so the two frames never look alike. Its text holds 4.5:1 and its accent 3:1 on every surface in both themes (the Follow label is 5.1:1 in light and 7.5:1 in dark). The docs apply the reader's settings to every `cobalt` element, so the derived frame also sets the tokens its file leaves alone (`--primary-soft`, `--r-control`, `--r-track` and `--r-tag`) back to tokens.css's own values, with selectors that outrank the reader's.

## Usage

A derived system is a stylesheet loaded after Cobalt's:

```css
.cobalt.ledger {
  --primary: oklch(0.52 0.09 190);
  --r-xs: 2px;
  --r-sm: 3px;
  --r-md: 3px;
  --r-lg: 4px;
  --r-2xl: 6px;
  --control: 32px;
  --pad-card: 16px;
  --t-layout: 300ms;
}
```

- `rule/theming-tokens-not-components`: When a derived system needs a different look, override tokens on the root instead of passing `className` overrides or editing files in `components/cobalt`, because a token reaches every component at once and an edited component forks the system and stops taking its fixes. Evidence: person D41; principle platform: CSS custom properties cascade to every descendant. Check: lint rule/component-override (scripts/check-system.mjs); review of a derived system's diff for edits under `components/cobalt`.
  - Don't: `<Button className="rounded-sm h-8">Save</Button>` on every call site
  - Do: `.cobalt.ledger { --r-lg: 4px; --control: 32px; }`
- `rule/theming-override-on-the-root`: When overriding tokens, put the block on the element that carries the `cobalt` class instead of a wrapper inside it, because a derived token such as `--primary-hover`, `--r-xl` or `--chart-1` is computed where it is declared, and an override further down changes `--primary` but leaves its hover and its chart series on the old colour. Evidence: principle platform: a custom property's `var()` references resolve on the element that declares it, and descendants inherit the computed value; person D41. Check: review of where a derived system's override block sits.
  - Don't: `<div class="cobalt"><div style="--primary: teal">…</div></div>`
  - Do: `<div class="cobalt ledger">…</div>` with `.cobalt.ledger { --primary: … }`
- `rule/theming-derive-corners`: When changing corners, set the base corners (`--r-xs` to `--r-lg`, `--r-2xl`, `--r-4xl`) and leave `--r-xl` and `--r-3xl` to derive, because those two are the inner corner plus a padding and a fixed value breaks the concentric pair. Evidence: measured 10px where 14px is concentric, a corner preset that fixed `--r-xl` at 6px and `--r-3xl` at 10px around rows inset 8px (site/prefs-script.ts, 2026-10-17); person D38. Check: review of a derived system's override block for `--r-xl` or `--r-3xl`.
  - Don't: `--r-3xl: 10px;`
  - Do: `--r-md: 4px;` and let `--r-xl` and `--r-3xl` follow
- `rule/theming-keep-contrast`: When a derived system changes colour, keep text at 4.5:1 and marks, edges and focus at 3:1 against the surface they sit on, in both themes, because the components assume those pairs hold and draw no extra outline when they do not. Evidence: principle platform: WCAG 2.2 1.4.3 and 1.4.11; person D41. Check: review of each changed pair with a contrast tool, in light and dark.
  - Don't: `--muted-foreground: oklch(0.75 0 0);` on a white card
  - Do: `--muted-foreground: oklch(0.5 0 0);`

## Accessibility

Tokens change looks, never behaviour: focus order, keyboard handling, names and roles come from Base UI and stay the same in every derived system. Contrast is the one thing a derived system can break, so `rule/theming-keep-contrast` holds it to the same pairs Cobalt holds.

## Not tokens

- Behaviour: keyboard handling, focus order, roles and live regions live in the Base UI parts each component wraps.
- Composition: which parts a component has, such as a card's header and footer, is its API, not a token.
