Core Concepts

The Cortex Theme Engine architecture — Three-Layer API, 12-step color scales, and the Dumb Serializer pattern.

The Cortex Theme Engine generates every FlexPixels design token from one small configuration file and writes them out as plain CSS custom properties. The page needs no JavaScript to use them.

What a theme is made of

A theme config has a handful of sections. These are the ones that shape the look:

  • Color seeds — three required hex colours (primary, secondary, neutral), up to four optional semantic ones (success, danger, warning, info), and an optional dark surface anchor. The engine turns each role seed into a 12-step OKLCH ramp: it keeps the seed’s hue and gamut-capped chroma as --fp-{role}-h / --fp-{role}-c, takes lightness from a fixed ramp, and shapes chroma with a fixed curve. The surface anchor gets no ramp of its own: it replaces neutral’s dark steps 1–5. For primary, secondary and any semantic seed you give, step 9 is the seed colour itself. A low-chroma neutral takes the primary hue, so greys lean towards the brand.
  • Spacing — a base unit (default 4px) that sets --fp-spacing-base and the semantic scale --fp-s-1 … --fp-s-12. The --fp-dim-* primitives come from spacing.mode (or a spacing.scale you give), not from the base.
  • Typography — three family slots, a font-size scale, line heights computed from it, fluid clamp() sizes for the larger roles, semantic text roles, leading-trim tokens and reading-comfort tokens.
  • Border — width primitives, named widths, semantic stroke tokens (--fp-stroke-control, --fp-stroke-divider, --fp-stroke-strong, …) and gradient presets.
  • Radius — radius primitives plus the semantic corners --fp-corner-control, --fp-corner-surface, --fp-corner-overlay and --fp-corner-circle.
  • Elevation — a four-level shadow ladder with semantic aliases and neutral surface tints; elevation.style switches between flat, neumorphic, brutalism and liquid-glass shadow models.

Interaction, layout, sizes, scrollbars, charts and output each have their own section too. The theme-config.json reference lists every key.


Three-Layer API

Spacing, radius and border tokens follow the same structure.

Layer 1 — Primitives

Raw, context-free values. These are the building blocks.

css
--fp-dim-4: 0.25rem;
--fp-dim-8: 0.5rem;
--fp-dim-16: 1rem;
--fp-radius-1: 0.125rem;
--fp-radius-2: 0.25rem;
--fp-font-size-3: 1rem;
--fp-border-1: 1px;
--fp-border-2: 2px;

Layer 2 — DNA

The configured base values, pointing at a primitive.

css
--fp-spacing-base: var(--fp-dim-4);
--fp-radius-base: var(--fp-radius-2);
--fp-border-base: var(--fp-border-1);

Layer 3 — Semantics

The tokens components read. Values below are the engine defaults.

css
/* Spacing semantic scale: the base × a fixed multiplier, precomputed, times density */
--fp-s-1: calc(0.125rem * var(--fp-density, 1)); /* 2px */
--fp-s-4: calc(0.5rem * var(--fp-density, 1)); /* 8px */
--fp-s-8: calc(2rem * var(--fp-density, 1)); /* 32px */

/* Radius semantics */
--fp-corner-control: var(--fp-radius-base); /* buttons, inputs */
--fp-corner-surface: var(--fp-radius-4); /* cards, panels */
--fp-corner-overlay: var(--fp-radius-5); /* modals, popovers */
--fp-corner-circle: var(--fp-radius-full); /* avatars, dots */

/* Border semantics */
--fp-stroke-control: var(--fp-border-base); /* buttons, inputs */
--fp-stroke-divider: var(--fp-border-w-hairline); /* separators */
--fp-stroke-strong: var(--fp-border-w-medium); /* emphasis, focus */
--fp-stroke-accent: var(--fp-border-w-thick); /* decorative */

The spacing steps are snapped to whole pixels: round(nearest, calc(0.5rem * var(--fp-density, 1)), 0.0625rem). Browsers without round() need output.legacyFallback: true, which writes the unrounded value first.


12-Step Color Scale

Each colour role gets a 12-step scale built from a lightness ramp (a fixed lightness per step and scheme, inlined into each token), a chroma curve (--fp-C-1 … --fp-C-12) and the seed hue and chroma (--fp-{role}-h, --fp-{role}-c). Config uses hex; the engine converts at build time.

For a role with a brand seed, step 9 is the seed itself (--fp-{role}-9: var(--fp-{role}-seed)) and step 10 is its hover, derived from the seed. Every other step is computed from the ramp.

StepsUsageExamples
1-2BackgroundsPage canvas, sidebars, cards
3-5UI elementsInputs, hover states, active/selected
6-7BordersSeparators, focus rings, input borders
8InteractiveIcons, links
9Solid surfacesButtons, badges — the “brand” step
10Solid hoverButton hover state
11-12TextSecondary copy, headings

Each role also gets three single tokens: --fp-{role}-seed (the hex you configured, brand roles only), --fp-{role}-text (the role’s colour adjusted until it reaches 4.5:1 as text on the page backgrounds; 7:1 with settings.accessibility: "AAA") and --fp-{role}-border (step 8 adjusted until it reaches 3:1 against the page, for control outlines; 4.5:1 with AAA).

Contrast pairs

Each step has a -contrast token: a black or white foreground, chosen at build time by measuring the step’s luminance in each scheme, and emitted as a light-dark() pair.

css
--fp-primary-9-contrast: light-dark(oklch(1 0 0), oklch(1 0 0));

With the default contrastAlgorithm: "apca", the engine prefers white while it still clears 4.5:1 (7:1 with AAA) and otherwise uses the better of black and white; with "wcag2" it picks whichever of the two contrasts more. Either way the label meets WCAG 2.1 AA on that step in both schemes. The default (lean) stylesheet carries -contrast for steps 8–11; the full stylesheet has it on every step.

APCA contrast matrix

The engine also computes three tinted foregrounds per step, taken from the same role’s scale:

css
--fp-primary-3-on-text: …; /* targets Lc 90 — body text */
--fp-primary-3-on-text-soft: …; /* targets Lc 60 — large or secondary text */
--fp-primary-3-on-icon: …; /* targets Lc 45 — icons, non-text */

Each one is solved with apca-w3 at build time and must also clear a WCAG 2.x floor (4.5:1 for the text tiers, 3:1 for icons; 7:1 and 4.5:1 with AAA, where black or white can reach 7:1 at all). Where no step of the role’s scale reaches the target, the token falls back to black or white; on step 9 it always does in the themes we checked. The matrix is not in the default stylesheet: set output.contrastMatrix: true, output.tokens: "full", or load theme-full.css (see Build & Import).

Alpha stops (a1–a5)

Each role gets 5 translucent variants of step 9 (its lightness held where a very light seed or a lifted dark surface would leave the paired text unreadable; see Color system):

TokenOpacityUsage
a15%Ghost hover
a210%Subtle tint
a320%Active press
a430%Focus ring
a545%Badge / chip

Dark mode

With settings.schemes: "both" (the default), every ramp step carries both lightnesses in light-dark(), so both schemes live in one stylesheet (a brand role’s step 9 is the seed in both schemes):

css
--fp-neutral-1: light-dark(oklch(0.985 …), oklch(0.15 …));
--fp-neutral-9: light-dark(oklch(0.5 …), oklch(0.61 …));

The scheme follows the OS preference. To force one, set data-theme="light" or data-theme="dark" on <html> (or any element); the engine emits attribute selectors, never class selectors. schemes: "light" or "dark" ships one scheme only, with no switching.


Elevation

Depth comes from a shadow ladder plus neutral surface tints. With the default flat style:

css
/* Shadow DNA: a light-dark() pair, tinted from neutral step 9 in light mode */
--fp-shadow-tint: light-dark(oklch(from var(--fp-neutral-9) 0.1 0.01 h / 0.12), oklch(0 0 0 / 0.4));

/* Elevation: four-step drop-shadow ladder */
--fp-elevation-1: 0 0.0625rem 0.1875rem 0 var(--fp-shadow-tint);
--fp-elevation-2: 0 0.125rem 0.25rem -0.0625rem var(--fp-shadow-tint), …;
--fp-elevation-3: 0 0.625rem 0.9375rem -0.1875rem var(--fp-shadow-tint), …;
--fp-elevation-4: 0 1.25rem 1.5625rem -0.3125rem var(--fp-shadow-tint), …;

/* Surface tints: neutral step 9 at increasing opacity (white in dark mode) */
--fp-surface-tint-2: linear-gradient(…/ 0.03 …);
--fp-surface-tint-3: linear-gradient(…/ 0.05 …);
--fp-surface-tint-4: linear-gradient(…/ 0.07 …);

The main knobs in theme-config.json:

json
{
  "elevation": {
    "shadowIntensity": 0.12,
    "shadowIntensityDark": 0.4,
    "tintChroma": 0.01
  }
}

shadowIntensity sets the shadow opacity in light mode, shadowIntensityDark in dark mode, and tintChroma how coloured (versus grey) the light-mode shadow is. See Elevation for the other styles and options.


Line heights

Line heights are computed from font sizes with the configured lineHeightFormula (default ratio-1.5):

text
lineHeight = ceil(fontSize × ratio / 2) × 2

ratio is 1.5 (default, UI), 1.618 (golden, editorial) or 1.3 (compact, dashboards). Results snap to a 2px grid, or to 1px when strictGrid: false. See Typography for the rest of the type system: roles, fluid sizes, leading trim and reading-comfort tokens.


Global tokens

A few tokens act on the whole system:

TokenDefault (engine config)Purpose
--fp-density1Spacing density multiplier. Presets --fp-density-{compact,default,relaxed} = 0.75 / 1 / 1.25
--fp-type-scale1Multiplier for the icon sizes below
--fp-icon-size-{sm,md,lg}1rem / 1.25rem / 1.5rem × type-scaleIcon sizes
--fp-font-family-bodyInterVariable, Inter, system-ui, sans-serifBody font stack
--fp-focus-ring-colorvar(--fp-primary-text)Focus ring colour — the text colour of the role set in interaction.focusRing.color
--fp-transition-durationvar(--fp-transition-duration-normal)Shorthand for the standard transition duration
--fp-transition-easingvar(--fp-transition-easing-ease-out)Shorthand for the standard easing curve
--fp-line-height-snugvar(--fp-line-height-2)Named line height (step 2)
--fp-line-height-normalvar(--fp-line-height-3)Named line height (step 3, body text)
--fp-contrast-threshold0.6 (AA) or 0.45 (AAA)Legacy value kept for older consumers; not used by the -contrast or matrix tokens. Full theme only

The “Dumb Serializer”

The CSS output layer (generateFullThemeCSS) is mostly a serializer of the engines’ token tree:

  • It walks the token tree the engines produce and writes --fp-{name}: {value};.
  • It also writes the scheme blocks and attribute rules, the surface overrides an elevation style needs (glass fills, glow, ambient light), and, with output.legacyFallback: true, static rgb() fallbacks, gamut-clipped from the oklch() values, for engines without light-dark().
  • Token values come from the engines — colour in the color engine, spacing in the spacing engine, and so on.

So when a token value is wrong, look first in the engine that generates it; for a surface-style or fallback value, look in the output layer.


Precomputed rem values

Spacing, radius and type sizes are written as precomputed rem values (px / 16) at build time, so they follow browser zoom and the root font size. Border widths, focus-ring sizes and touch targets stay in px.