Tokens
Every design value passes through a three-tier token architecture: primitive scales feed semantic role tokens, and semantic tokens feed component contracts. Components never read primitive tokens directly.
Three-tier architecture
| Layer | TS source → CSS output | Examples | Contract |
|---|---|---|---|
| 1. Primitive | color.ts, scales.ts, layout.ts → color.css, scales.css, layout.css | --obsidian-1 (hsl(220, 6%, 5%)), --verdigris-9 (hsl(175, 32%, 31%)), --space-4 (1rem / 16px), --radius-md (0.5rem / 8px) | 8 color scales × 12 steps, 12 spacing steps, 7 radii, 3 border widths, 4 shadows, 10 type steps, 5 durations, 3 easings, 6 z-index steps. Never read directly by components. |
| 2. Semantic | semantic.ts → semantic.css, theme.css | --background, --foreground, --primary, --border, --input, --ring, --code-keyword | 53 role tokens mapped across 4 brand themes (mono, verdigris, brass, porphyry) and 2 modes (dark, light). Bridged to Tailwind utilities via @theme inline. |
| 3. Component | components.ts → components.css | --control-height-md (2.5rem / 40px), --focus-ring-width (2px), --card-radius (var(--radius-lg)) | 4 control size contracts (xs, sm, md, lg), focus ring geometry (2px width, 2px offset), and card radius (16px / 1rem). |
| Control size | Height token | Icon token | Radius token |
|---|---|---|---|
| xs | --control-height-xs: 1.5rem (24px) | --control-icon-xs: 1rem (16px) | --control-radius-xs: var(--radius-sm) (0.25rem / 4px) |
| sm | --control-height-sm: 2rem (32px) | --control-icon-sm: 1rem (16px) | --control-radius-sm: var(--radius-sm) (0.25rem / 4px) |
| md | --control-height-md: 2.5rem (40px) | --control-icon-md: 1.25rem (20px) | --control-radius-md: var(--radius-md) (0.5rem / 8px) |
| lg | --control-height-lg: 3rem (48px) | --control-icon-lg: 1.5rem (24px) | --control-radius-lg: var(--radius-md) (0.5rem / 8px) |
TypeScript modules under packages/monoplinth/src/tokens/ are the single source of truth. Running npm run tokens:build emits deterministic CSS custom properties that theme.css bridges into Tailwind CSS v4.
Primitive scale inventory
| Scale | Unit | Defined steps from TS |
|---|---|---|
| Spacing (--space-*) | 16px = 1rem (step = px / 4) | --space-1: 0.25rem (4px) · --space-2: 0.5rem (8px) · --space-3: 0.75rem (12px) · --space-4: 1rem (16px) · --space-6: 1.5rem (24px) · --space-8: 2rem (32px) · --space-10: 2.5rem (40px) · --space-12: 3rem (48px) · --space-16: 4rem (64px) · --space-20: 5rem (80px) · --space-24: 6rem (96px) · --space-32: 8rem (128px) |
| Sizing | px / rem | 16px (1rem) · 24px (1.5rem) · 32px (2rem) · 40px (2.5rem) · 48px (3rem) |
| Radius (--radius-*) | rem | --radius-none: 0rem (0px) · --radius-xs: 0.125rem (2px) · --radius-sm: 0.25rem (4px) · --radius-md: 0.5rem (8px) · --radius-lg: 1rem (16px) · --radius-xl: 1.5rem (24px) · --radius-full: 624.9375rem (9999px) |
| Border width (--border-width-*) | px | --border-width-1: 1px · --border-width-2: 2px · --border-width-4: 4px |
| Fonts (--font-*) | family stack | --font-display: Sora, system-ui, -apple-system, sans-serif · --font-sans: Sora, system-ui, -apple-system, sans-serif · --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace |
| Motion duration (--duration-*) | ms (φ-based) | --duration-100: 100ms · --duration-162: 162ms · --duration-262: 262ms · --duration-424: 424ms · --duration-686: 686ms |
| Motion easing (--ease-*) | cubic-bezier | --ease-standard: cubic-bezier(0.2, 0, 0, 1) · --ease-enter: cubic-bezier(0, 0, 0.2, 1) · --ease-exit: cubic-bezier(0.4, 0, 1, 1) |
| Z-index (--z-*) | integer layer | --z-base: 0 · --z-sticky: 10 · --z-dropdown: 20 · --z-overlay: 30 · --z-modal: 40 · --z-toast: 50 |
Default Tailwind CSS scales are reset with --*: initial in theme.css. Only the defined Monoplinth token steps resolve to utility classes.
Semantic color mapping
| Semantic token | Tailwind class | Mono (default) | Verdigris | Brass | Porphyry |
|---|---|---|---|---|---|
| --background | bg-background | --obsidian-1 | --obsidian-1 | --obsidian-1 | --obsidian-1 |
| --foreground | text-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --card | bg-card | --obsidian-3 | --obsidian-3 | --obsidian-3 | --obsidian-3 |
| --card-foreground | text-card-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --popover | bg-popover | --obsidian-3 | --obsidian-3 | --obsidian-3 | --obsidian-3 |
| --popover-foreground | text-popover-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --primary | bg-primary | --obsidian-9 | --verdigris-9 | --brass-9 | --porphyry-9 |
| --primary-hover | bg-primary-hover | --obsidian-10 | --verdigris-10 | --brass-10 | --porphyry-10 |
| --primary-active | bg-primary-active | --obsidian-9 | --verdigris-9 | --brass-9 | --porphyry-9 |
| --primary-foreground | text-primary-foreground | --obsidian-foreground | --verdigris-foreground | --brass-foreground | --porphyry-foreground |
| --secondary | bg-secondary | --obsidian-3 | --obsidian-3 | --obsidian-3 | --obsidian-3 |
| --secondary-hover | bg-secondary-hover | --obsidian-4 | --obsidian-4 | --obsidian-4 | --obsidian-4 |
| --secondary-active | bg-secondary-active | --obsidian-5 | --obsidian-5 | --obsidian-5 | --obsidian-5 |
| --secondary-foreground | text-secondary-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --muted | bg-muted | --obsidian-2 | --obsidian-2 | --obsidian-2 | --obsidian-2 |
| --muted-foreground | text-muted-foreground | --obsidian-11 | --obsidian-11 | --obsidian-11 | --obsidian-11 |
| --accent | bg-accent | --obsidian-4 | --obsidian-4 | --obsidian-4 | --obsidian-4 |
| --accent-foreground | text-accent-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --border | border-border | --obsidian-7 | --obsidian-7 | --obsidian-7 | --obsidian-7 |
| --input | border-input | --obsidian-8 | --obsidian-8 | --obsidian-8 | --obsidian-8 |
| --ring | ring-ring | --obsidian-8 | --verdigris-8 | --brass-8 | --porphyry-8 |
| --destructive | bg-destructive | --red-9 | --red-9 | --red-9 | --red-9 |
| --destructive-hover | bg-destructive-hover | --red-10 | --red-10 | --red-10 | --red-10 |
| --destructive-active | bg-destructive-active | --red-9 | --red-9 | --red-9 | --red-9 |
| --destructive-foreground | text-destructive-foreground | --red-foreground | --red-foreground | --red-foreground | --red-foreground |
| --destructive-text | bg-destructive-text | --red-11 | --red-11 | --red-11 | --red-11 |
| --destructive-subtle | bg-destructive-subtle | --red-3 | --red-3 | --red-3 | --red-3 |
| --destructive-border | bg-destructive-border | --red-6 | --red-6 | --red-6 | --red-6 |
| --disabled | bg-disabled | --obsidian-3 | --obsidian-3 | --obsidian-3 | --obsidian-3 |
| --disabled-foreground | text-disabled-foreground | --obsidian-8 | --obsidian-8 | --obsidian-8 | --obsidian-8 |
| --info | bg-info | --blue-9 | --blue-9 | --blue-9 | --blue-9 |
| --info-foreground | text-info-foreground | --blue-foreground | --blue-foreground | --blue-foreground | --blue-foreground |
| --info-subtle | bg-info-subtle | --blue-3 | --blue-3 | --blue-3 | --blue-3 |
| --info-border | bg-info-border | --blue-6 | --blue-6 | --blue-6 | --blue-6 |
| --info-text | bg-info-text | --blue-11 | --blue-11 | --blue-11 | --blue-11 |
| --warning | bg-warning | --orange-9 | --orange-9 | --orange-9 | --orange-9 |
| --warning-foreground | text-warning-foreground | --orange-foreground | --orange-foreground | --orange-foreground | --orange-foreground |
| --warning-subtle | bg-warning-subtle | --orange-3 | --orange-3 | --orange-3 | --orange-3 |
| --warning-border | bg-warning-border | --orange-6 | --orange-6 | --orange-6 | --orange-6 |
| --warning-text | bg-warning-text | --orange-11 | --orange-11 | --orange-11 | --orange-11 |
| --success | bg-success | --green-9 | --green-9 | --green-9 | --green-9 |
| --success-foreground | text-success-foreground | --green-foreground | --green-foreground | --green-foreground | --green-foreground |
| --success-subtle | bg-success-subtle | --green-3 | --green-3 | --green-3 | --green-3 |
| --success-border | bg-success-border | --green-6 | --green-6 | --green-6 | --green-6 |
| --success-text | bg-success-text | --green-11 | --green-11 | --green-11 | --green-11 |
| --code-background | bg-code-background | --obsidian-3 | --obsidian-3 | --obsidian-3 | --obsidian-3 |
| --code-foreground | text-code-foreground | --obsidian-12 | --obsidian-12 | --obsidian-12 | --obsidian-12 |
| --code-keyword | text-code-keyword | --obsidian-12 | --verdigris-12 | --brass-12 | --porphyry-12 |
| --code-comment | text-code-comment | --obsidian-11 | --obsidian-11 | --obsidian-11 | --obsidian-11 |
| --code-string | text-code-string | --obsidian-11 | --verdigris-11 | --brass-11 | --porphyry-11 |
| --code-number | text-code-number | --obsidian-11 | --verdigris-11 | --brass-11 | --porphyry-11 |
| --code-function | text-code-function | --obsidian-12 | --verdigris-12 | --brass-12 | --porphyry-12 |
| --code-punctuation | text-code-punctuation | --obsidian-11 | --obsidian-11 | --obsidian-11 | --obsidian-11 |
Each semantic token references a primitive color variable (var(--<scale>-<step>)). Switching modes updates the primitive values under .light, while switching brand themes updates only the brand-driven semantic slots under [data-theme].
Usage
Reference semantic and component tokens through Tailwind CSS v4 utilities or CSS custom properties:
<button
type="button"
className="inline-flex items-center justify-center rounded-md border border-input bg-primary px-4 font-sans text-body font-medium text-primary-foreground transition-colors duration-162 ease-standard"
style={{ height: "var(--control-height-md)" }}
>
Confirm action
</button>.control-md {
height: var(--control-height-md);
padding-inline: var(--space-4);
border-radius: var(--control-radius-md);
background-color: var(--primary);
color: var(--primary-foreground);
transition: background-color var(--duration-162) var(--ease-standard);
}
.control-md:focus-visible {
outline: var(--focus-ring-width) solid var(--focus-ring-color);
outline-offset: var(--focus-ring-offset);
}Do and don't
Accessibility
| Category | TS source | Output unit and tokens | Accessibility rule |
|---|---|---|---|
| Fluid and scalable dimensions | scales.ts, components.ts, layout.ts | rem (16px root base, px / 16) | Scales spacing, control heights, and typography with browser zoom |
| Crisp structural hairlines | scales.ts | --border-width-1 (1px), --border-width-2 (2px), --border-width-4 (4px) | Keeps borders sharp in px at every zoom level |
| Focus ring geometry | components.ts | --focus-ring-width (2px), --focus-ring-offset (2px) | Maintains a visible outline on :focus-visible |
Scalable layout and typography dimensions convert to rem so interfaces respect browser zoom and user font-size preferences. Structural hairlines and focus rings stay in px, and every semantic foreground pair is verified against WCAG 2.2 AA contrast thresholds.
Rationale
Separating primitive scales from semantic roles allows a single component stylesheet to support dark mode, light mode, and four brand themes without conditional class branches. Generating CSS from typed TypeScript modules prevents drift between runtime calculations, contrast audits, and compiled stylesheets.