# tokens.css template

`.mockups/design-system/tokens.css` is the contract that every screen and
flow mock inherits. It carries the locked palette and typography decisions
plus the spacing and radius scales.

## Structure

```css
/*
 * Design tokens for {project}
 * Generated by /ux-ui-design:palette on {date}
 * Palette: Option N — {label}
 * Typography: Option N — {label}
 *
 * Edit by re-running /ux-ui-design:palette (it preserves this header).
 */

:root {
  /* Color tokens (light mode) */
  --color-bg-primary: #...;
  --color-bg-secondary: #...;
  --color-bg-tertiary: #...;
  --color-bg-inverse: #...;
  --color-text-primary: #...;
  --color-text-secondary: #...;
  --color-text-tertiary: #...;
  --color-text-inverse: #...;
  --color-text-link: #...;
  --color-text-link-hover: #...;
  --color-border: #...;
  --color-border-strong: #...;
  --color-accent: #...;
  --color-accent-hover: #...;
  --color-accent-muted: #...;
  --color-success: #...;
  --color-warning: #...;
  --color-danger: #...;
  --color-info: #...;

  /* Typography tokens */
  --font-sans: ...;
  --font-mono: ...;
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 32px;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --line-height-tight: 1.25;
  --line-height-base: 1.5;
  --line-height-loose: 1.75;

  /* Spacing scale (8pt baseline) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg-primary: #...;
    --color-bg-secondary: #...;
    /* ... all dark-mode color overrides ... */
  }
}
```

## Loading hosted fonts

When `palette` picks a hosted face (Google Fonts, Fontsource, etc.),
include the `@import` at the top of `tokens.css` so every mock that links
`tokens.css` automatically gets the font:

```css
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, ui-sans-serif, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  /* ... */
}
```

Always declare a full system-stack fallback after the hosted face name.
Offline rendering, slow networks, and tracker-blocking extensions all
benefit from a clean fallback chain — the mock degrades gracefully
instead of falling back to Times New Roman.

`display=swap` lets the system stack render immediately and swap to the
hosted face when it loads. Better than the flash-of-invisible-text
default.

If the project chooses system fonts only, skip the `@import` entirely
and declare just the system stack in the tokens.

## Dark-mode mechanism

Pick the dark-mode mechanism that fits the project:

- **`@media (prefers-color-scheme: dark)`** — for system-following behavior.
  Default for most projects. No user toggle needed; the OS theme drives it.
- **`[data-theme="dark"]`** — for projects that need explicit toggling
  (saved user preference, in-app switcher). Mocks demonstrate the toggle
  by setting the attribute on `<html>` or `<body>`.

Document the chosen mechanism in the header comment so subsequent
`palette` runs know which to preserve.

## Header comment contract

The header comment is preserved across refinement-mode runs. Future
`palette` invocations parse:

- **Project name** — informational, not validated
- **Generation date** — updated to current date on every lock-in
- **Palette option label** — recorded for traceability
- **Typography option label** — recorded for traceability

Adding fields to the header is fine; removing the canonical four breaks
refinement-mode parsing.

## What goes here vs what doesn't

**In `tokens.css`:** color, typography, spacing, radius — the durable
visual contract that every mock inherits.

**Not in `tokens.css`:** layout-specific values (grid templates, breakpoints,
component-specific dimensions). Those live in each mock's `<style>` block.
A mock that needs a 280px sidebar writes `width: 280px` inline; it doesn't
add `--sidebar-width: 280px` to the global token file.

## Refinement-mode preservation

When `palette` runs in refinement mode against an existing `tokens.css`:

1. Read the existing tokens and the header comment.
2. Generate a before/after preview for the proposed change in
   `palette.html`.
3. Run the same contrast check from the canonical Phase 4 on the new
   values. If a pairing degrades below WCAG AA, surface the specific
   pairing and ratio to the user and require confirmation before locking.
4. After approval, update `tokens.css` AND the header comment's
   "Generated" date and option labels if they changed.

Never overwrite `tokens.css` in refinement mode without explicit user
confirmation. Every downstream mock reads from this file.
