# Modes and themes

Dark mode (`dark`) and the monochrome brand theme (`mono`) are the default appearance on `:root`. Adding `.light` to `<html>` switches the color mode, and setting `data-theme` on `<html>` switches the 10% brand hue.

## Selector architecture and no-flash script

| Stylesheet | Selector | Token count | Binding contract |
| --- | --- | --- | --- |
| color.css | :root | 8 scales × 12 steps + foregrounds | Dark mode (dark) primitive HSL values |
| color.css | .light | 8 scales × 12 steps + foregrounds | Light mode primitive HSL overrides with identical variable names |
| semantic.css | :root | 53 total (45 neutral/Mono + 8 feedback) | Binds neutral/Mono slots to --obsidian-* and feedback slots to --red-*, --blue-*, --orange-*, --green-* |
| semantic.css | [data-theme="verdigris"], [data-theme="brass"], [data-theme="porphyry"] | 9 brand-driven slots | Overrides --primary, --primary-hover, --primary-active, --primary-foreground, --ring, --code-keyword, --code-string, --code-number, --code-function |

| Theme | Root selector | Primitive scale | Hue | Material |
| --- | --- | --- | --- | --- |
| mono | :root (no data-theme) | obsidian | 220° | Obsidian to Alabaster neutral plinth (Mono default) |
| verdigris | [data-theme="verdigris"] | verdigris | 175° | Oxidized copper brand theme |
| brass | [data-theme="brass"] | brass | 42° | Aged gold brand theme |
| porphyry | [data-theme="porphyry"] | porphyry | 320° | Imperial purple stone brand theme |

- Default mode: `dark` on `:root`; light mode adds `.light` to `<html>`.
- Default brand theme: `mono` (no `data-theme` attribute); non-default themes set `data-theme="verdigris|brass|porphyry"`.
- Storage keys: `monoplinth-mode` and `monoplinth-theme` in `localStorage`.

Primitive color tokens use identical variable names across `:root` and `.light`, while semantic tokens bind once on `:root` and override only the brand-driven slots under `[data-theme]`. A blocking inline script runs in `<head>` before first paint to read `localStorage`, fall back to `dark` and `mono`, and ignore `prefers-color-scheme`.

## Brand-driven semantic token map

| Semantic token | Tailwind class | Mono (default) | Verdigris | Brass | Porphyry |
| --- | --- | --- | --- | --- | --- |
| --primary | bg-primary | --obsidian-9 (dark: hsl(220, 6%, 90%), light: hsl(220, 6%, 13%)) | --verdigris-9 (dark: hsl(175, 32%, 31%), light: hsl(175, 32%, 29%)) | --brass-9 (dark: hsl(42, 34%, 32%), light: hsl(42, 34%, 30%)) | --porphyry-9 (dark: hsl(320, 30%, 41%), light: hsl(320, 30%, 37%)) |
| --primary-hover | bg-primary-hover | --obsidian-10 (dark: hsl(220, 6%, 96%), light: hsl(220, 6%, 20%)) | --verdigris-10 (dark: hsl(175, 32%, 34%), light: hsl(175, 32%, 33%)) | --brass-10 (dark: hsl(42, 34%, 35%), light: hsl(42, 34%, 34%)) | --porphyry-10 (dark: hsl(320, 30%, 44%), light: hsl(320, 30%, 42%)) |
| --primary-active | bg-primary-active | --obsidian-9 (dark: hsl(220, 6%, 90%), light: hsl(220, 6%, 13%)) | --verdigris-9 (dark: hsl(175, 32%, 31%), light: hsl(175, 32%, 29%)) | --brass-9 (dark: hsl(42, 34%, 32%), light: hsl(42, 34%, 30%)) | --porphyry-9 (dark: hsl(320, 30%, 41%), light: hsl(320, 30%, 37%)) |
| --primary-foreground | text-primary-foreground | --obsidian-foreground (dark: hsl(220, 6%, 6%), light: hsl(220, 6%, 98%)) | --verdigris-foreground (dark: hsl(175, 20%, 98%), light: hsl(175, 20%, 98%)) | --brass-foreground (dark: hsl(42, 22%, 98%), light: hsl(42, 22%, 98%)) | --porphyry-foreground (dark: hsl(320, 18%, 98%), light: hsl(320, 18%, 98%)) |
| --ring | ring-ring | --obsidian-8 (dark: hsl(220, 5%, 46%), light: hsl(220, 5%, 50%)) | --verdigris-8 (dark: hsl(175, 26%, 42%), light: hsl(175, 26%, 43%)) | --brass-8 (dark: hsl(42, 26%, 43%), light: hsl(42, 26%, 44%)) | --porphyry-8 (dark: hsl(320, 24%, 49%), light: hsl(320, 24%, 51%)) |
| --code-keyword | text-code-keyword | --obsidian-12 (dark: hsl(220, 6%, 95%), light: hsl(220, 6%, 10%)) | --verdigris-12 (dark: hsl(175, 24%, 92%), light: hsl(175, 34%, 13%)) | --brass-12 (dark: hsl(42, 26%, 92%), light: hsl(42, 36%, 14%)) | --porphyry-12 (dark: hsl(320, 22%, 93%), light: hsl(320, 32%, 15%)) |
| --code-string | text-code-string | --obsidian-11 (dark: hsl(220, 5%, 68%), light: hsl(220, 5%, 36%)) | --verdigris-11 (dark: hsl(175, 28%, 68%), light: hsl(175, 30%, 28%)) | --brass-11 (dark: hsl(42, 30%, 68%), light: hsl(42, 32%, 29%)) | --porphyry-11 (dark: hsl(320, 26%, 72%), light: hsl(320, 28%, 35%)) |
| --code-number | text-code-number | --obsidian-11 (dark: hsl(220, 5%, 68%), light: hsl(220, 5%, 36%)) | --verdigris-11 (dark: hsl(175, 28%, 68%), light: hsl(175, 30%, 28%)) | --brass-11 (dark: hsl(42, 30%, 68%), light: hsl(42, 32%, 29%)) | --porphyry-11 (dark: hsl(320, 26%, 72%), light: hsl(320, 28%, 35%)) |
| --code-function | text-code-function | --obsidian-12 (dark: hsl(220, 6%, 95%), light: hsl(220, 6%, 10%)) | --verdigris-12 (dark: hsl(175, 24%, 92%), light: hsl(175, 34%, 13%)) | --brass-12 (dark: hsl(42, 26%, 92%), light: hsl(42, 36%, 14%)) | --porphyry-12 (dark: hsl(320, 22%, 93%), light: hsl(320, 32%, 15%)) |

Only the brand-driven semantic tokens change when `data-theme` switches. Neutral surfaces and functional feedback tokens remain constant across every brand theme.

## Usage

Apply mode and theme state on the root `<html>` element and consume semantic tokens in components:

```tsx
// Root layout (<head> blocking script; APPEARANCE_INIT_SCRIPT is a static build-time constant)
<html lang="en" suppressHydrationWarning>
  <head>
    <script dangerouslySetInnerHTML={{ __html: APPEARANCE_INIT_SCRIPT }} />
  </head>
  <body className="min-h-screen bg-background font-sans text-foreground">
    {children}
  </body>
</html>
```

```css
/* Default: dark mode + Mono theme on :root */
/* Light mode + Verdigris theme on <html class="light" data-theme="verdigris"> */
.brand-callout {
  background-color: var(--card);
  color: var(--card-foreground);
  border-left: var(--border-width-4) solid var(--primary);
}

.brand-callout:focus-visible {
  outline: var(--focus-ring-width) solid var(--ring);
  outline-offset: var(--focus-ring-offset);
}
```

## Do and don't

- **Do: Resolve appearance in <head> and use semantic classes** — Run APPEARANCE_INIT_SCRIPT synchronously in <head> and style components with bg-background, text-foreground, bg-primary, and ring-ring so mode and theme switches require zero component re-renders.
- **Don't: Follow OS prefers-color-scheme or branch in JSX** — Do not query window.matchMedia('(prefers-color-scheme: light)') or conditionally swap Tailwind classes in React state for dark and light modes.

## Accessibility

| Surface or control | Dimensions and matrix | WCAG and keyboard contract |
| --- | --- | --- |
| Appearance matrix | 2 modes (dark, light) × 4 themes (mono, verdigris, brass, porphyry) | >= 4.5:1 text/syntax contrast and >= 3.0:1 control/focus contrast |
| ModeToggle button | Target height 40px (2.5rem) | Announces Switch to light mode or Switch to dark mode |
| ThemePicker radiogroup | Target size 32px (2rem); 2px active border | Roving tabIndex with ArrowRight, ArrowDown, ArrowLeft, ArrowUp, Home, End |

Every mode and brand theme combination passes automated contrast verification for text, syntax, controls, and focus rings. The mode toggle and theme radiogroup expose explicit accessible labels, keyboard navigation, and non-color selection borders.

## Rationale

Dark mode is the architectural default of Monoplinth, so ignoring OS `prefers-color-scheme` guarantees a predictable first visit unless the user explicitly selects `.light`. Reusing identical custom property names across `:root`, `.light`, and `[data-theme]` keeps CSS specificity flat and eliminates duplicate `dark:` utility classes in component templates.
