/* @jowheeman/tokens — the values layer. Hand-maintained; keep index.js in sync. */
/* Naming: --brand-* is canonical, --wisse-* is the back-compat alias (retire once
   the fleet is rebuilt). See docs/TOKEN-REFERENCE.md. */

/* ---------------------------------------------------------------------------
   HOW THIS FILE WORKS — read before editing.

   1. SEEDS are the handful of values a tenant actually owns. The gateway
      injects them into a later :root at serve time (BRAND_COLOR_PRIMARY /
      _ACCENT / _SURFACE / BRAND_FONT_SANS, plus any --brand-* via BRAND_TOKENS),
      so they must stay plain literals that a later declaration can replace.

   2. Everything else is DERIVED from a seed with color-mix(in oklab, …). That
      is why one tenant colour re-tints the whole system — light *and* dark —
      with no fork and no rebuild.

   3. DARK is a scheme, not a theme: [data-theme="dark"]. Nothing here
      stamps a prefers-color-scheme media query — the consumer decides and
      stamps data-theme (see @jowheeman/desktop useAppearance), so a product
      that never opts in keeps today's light rendering exactly.

   4. Because [data-theme="dark"] outranks the gateway's injected :root, the
      dark block would otherwise silently beat a tenant's own values. So every
      dark declaration reads var(--brand-dark-…, <derived>) first: a tenant
      that wants explicit dark control sets --brand-dark-* through BRAND_TOKENS
      and still wins. Tenant authority survives in both schemes.

   5. SCOPES — seeds inherit, derivations recompute (0.5, platform/docs/design.md
      §8). A custom property is computed on the element that declares it, and
      descendants inherit the finished value. With every derivation on :root, a
      subtree carrying another party's seed re-tinted nothing, and a dark island
      in a light page could not exist. So the file is four blocks:

        seeds        :root, [data-brand]                       literals only
        derivations  :root, [data-brand], [data-theme='dark']  every var()
        aliases      same as derivations
        dark         :root[data-theme='dark'], [data-theme='dark'],
                     [data-theme='dark'] [data-brand]:not([data-theme='light'])

      - A GROUND is `<el data-brand="<ref>" style="<its flattened seeds>">`:
        another party's surface inside this page. Seeds reset there to the
        platform defaults (a ground is that party's full white-label, never the
        host's colours with one swapped), its own seeds win inline, and
        everything derived re-evaluates. It follows the scheme around it unless
        it says data-theme='light' itself. Fill it from the party's RESOLVED
        brand, never from content (design.md §4 — a mark is resolved, never
        supplied).
      - A DARK ISLAND is `<el data-theme="dark">` in a light page: seeds
        inherit (the tenant's colours carry in), derivations re-run dark.
      - A LIGHT ISLAND is `<el data-theme="light">` in a dark page (0.6): the
        names the dark block overwrites in place keep their light value under a
        seed twin (--brand-seed-*), restored by the light-island block below.
      - A seed with a default BY REFERENCE (the accent, the desktop knobs)
        is still a seed: it lives in the seeds block, so an island inherits the
        tenant's value instead of re-running the default.
      - A tenant override of a DERIVED token (e.g. --brand-color-surface-page
        in BRAND_TOKENS) holds on the root it was injected on; islands
        re-derive. check-tokens.mjs enforces the split: a var() outside the
        seed allow-list must sit in a scoped block.
--------------------------------------------------------------------------- */

/* Root-only: what a ground must never reset. Density is the APP's dial (design.md §3), so it lives on :root alone. On the
   seeds block it would sit on every [data-brand] too, and a guest's ground inside
   an app — a host at popronde, a tenant card in appmanager — would reset the app's
   register to 1: the ground carries the guest's identity, never the host app's
   structure. Declared once here, it inherits through grounds; the space scale on
   each scope (below) re-reads it. A region that wants its own register sets it on
   itself ([data-character] or any element). */
:root {
  --brand-density: 1;
  /* The smallest a control may render — WCAG 2.2 2.5.8 (AA): 24 CSS px. The PERSON's
     (design.md §3, legibility): never scaled by a dial, never reset by a ground, so a
     compact register tightens rhythm around a control but cannot shrink what a finger or
     a cursor has to hit. ui's controls read it as min-height/min-width. A person who
     needs bigger targets raises it here, once, and every control follows; 44px is
     --brand-space-touch-target (the AAA / platform-guideline size). */
  --brand-space-target-min: 24px;
}

:root,
[data-brand] {
  color-scheme: light;

  /* ---- Character — four dials (platform/docs/design.md §5, 0.7) -------------
     A handful of numbers that move many tokens coherently, instead of thirty
     values edited one by one. 1 is today, exactly. Who owns which dial (§3):
       shape    corners       0 sharp · 1 · 2 round        the tenant (brand `character`)
       depth    shadows       0 flat · 1 · 2 deep          the tenant
       motion   durations     0 still · 1 · 2 slow/lively  the tenant — but the PERSON's
                                                            reduced-motion wins (below)
       density  spacing       0.8 compact · 1 · 1.2 airy   the APP (its register): an app
                                                            sets it on its own :root —
                                                            declared on :root only, below
     A tenant can still override any single token; a dial only moves defaults. */
  --brand-shape: 1;
  --brand-depth: 1;
  --brand-motion-scale: 1;

  /* ---- Seeds — tenant-owned, gateway-injectable ------------------------- */
  --brand-seed-color-primary: #101418;
  --brand-color-primary: var(--brand-seed-color-primary);
  --brand-seed-color-secondary: #ffffff;
  --brand-color-secondary: var(--brand-seed-color-secondary);
  --brand-color-status-info: #2271b1;
  --brand-seed-color-status-success: #00a32a;
  --brand-color-status-success: var(--brand-seed-color-status-success);
  --brand-seed-color-status-error: #d63638;
  --brand-color-status-error: var(--brand-seed-color-status-error);
  --brand-seed-color-status-warning: #ffc107;
  --brand-color-status-warning: var(--brand-seed-color-status-warning);

  /* The accent SEED — see the two-name split under the derivations. A seed
     with a default by reference is still a seed: it lives here, so a dark
     island inherits the tenant's accent instead of re-running the default. */
  --brand-color-semantic-accent: var(--brand-color-status-info);

  /* Provenance — one vocabulary for "where did this come from", shared by the
     chat log, the jam rows and the werkbank. */
  --brand-seed-prov-ai: #8b5cf6;
  --brand-prov-ai: var(--brand-seed-prov-ai);
  --brand-seed-prov-tool: #0e9f7e;
  --brand-prov-tool: var(--brand-seed-prov-tool);
  --brand-seed-prov-grammar: #b0671f;
  --brand-prov-grammar: var(--brand-seed-prov-grammar);

  /* ---- Typography ------------------------------------------------------- */
  --brand-typography-font-family-sans: 'Inter var', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --brand-typography-font-family-display: 'Fraunces var', 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --brand-typography-font-family-reading: 'Fraunces var', 'Fraunces', Georgia, 'Times New Roman', serif;
  --brand-typography-font-family-mono: 'JetBrains Mono var', 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  /* A real scale. The old one collapsed base==md and lg==xl, so "one step up"
     was a no-op half the time and chrome drifted down to 8px literals.

     rem at a 16px root (0.9, platform/docs/iedereen.md): px never grows with
     the browser/OS text-size setting or a person's data-tekstgrootte; rem
     does, because it reads the root's font-size on every relayout. Each
     value below is the old px ÷ 16, so the rendered size at the 16px/100%
     default is byte-for-byte unchanged — only what happens when the root
     stops being 16px is new. index.js's `typography.fontSize` stays in px
     on purpose: it feeds canvas/WebGL/native-titlebar contexts that resolve
     a font string with no DOM to read a root size from, and its numbers are
     the resolved default, same value either way at 16px. */
  --brand-typography-font-size-2xs: 0.65625rem; /* 10.5px */
  --brand-typography-font-size-xs: 0.71875rem; /* 11.5px */
  --brand-typography-font-size-sm: 0.78125rem; /* 12.5px */
  --brand-typography-font-size-base: 0.875rem; /* 14px */
  --brand-typography-font-size-md: 0.9375rem; /* 15px */
  --brand-typography-font-size-lg: 1.0625rem; /* 17px */
  --brand-typography-font-size-xl: 1.25rem; /* 20px */
  --brand-typography-font-size-xxl: 1.5rem; /* 24px */
  --brand-typography-font-size-xxxl: 1.875rem; /* 30px */
  --brand-typography-font-size-huge: 2.375rem; /* 38px */
  --brand-typography-font-size-display: clamp(1.875rem, 4.2vw, 2.875rem); /* 30px..46px; the vw midpoint is viewport-relative on purpose and does not follow text-size, same as any fluid clamp() */

  --brand-typography-font-weight-normal: 400;
  --brand-typography-font-weight-medium: 500;
  --brand-typography-font-weight-semibold: 600;
  --brand-typography-font-weight-bold: 700;

  --brand-typography-line-height-tight: 1.15;
  --brand-typography-line-height-normal: 1.35;
  --brand-typography-line-height-base: 1.5;
  --brand-typography-line-height-relaxed: 1.62;
  --brand-typography-line-height-loose: 1.8;

  --brand-typography-letter-spacing-tighter: -0.022em;
  --brand-typography-letter-spacing-tight: -0.012em;
  --brand-typography-letter-spacing-normal: 0;
  --brand-typography-letter-spacing-wide: 0.02em;
  --brand-typography-letter-spacing-wider: 0.08em;

  /* Variable-font axes, exposed so a surface can ask for optical sizing without
     hardcoding font-variation-settings in twenty places. */
  --brand-typography-optical-ui: 'opsz' 14;
  --brand-typography-optical-display: 'opsz' 72;
  --brand-typography-numeric-tabular: tabular-nums;

  /* ---- Space ------------------------------------------------------------ */
  --brand-space-touch-target: 44px;

  /* ---- Radii ------------------------------------------------------------ */
  --brand-border-radius-pill: 999px;
  --brand-border-radius-full: 50%;

  /* ---- Lines ------------------------------------------------------------ */
  --brand-border-width: 1px;
  --brand-border-width-thin: 1px;
  --brand-border-width-thick: 2px;
  --brand-hairline: 1px;

  /* ---- Elevation — ambient + key, two layers ---------------------------- */
  --brand-shadow-umbra: 0deg 0% 4%;
  --brand-elevation-0: none;

  /* ---- Materials -------------------------------------------------------- */
  /* Glass: what the dock, the prompt and the pills are made of. */
  --brand-seed-material-glass-alpha: 74%;
  --brand-material-glass-alpha: var(--brand-seed-material-glass-alpha);
  --brand-material-glass-blur: 18px;
  --brand-material-glass-saturate: 1.5;
  --brand-seed-material-glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.62);
  --brand-material-glass-highlight: var(--brand-seed-material-glass-highlight);
  /* Plate: what a window body is made of. */
  --brand-seed-material-plate-edge: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --brand-material-plate-edge: var(--brand-seed-material-plate-edge);

  /* ---- Motion — durations and curves are values, not literals ----------- */

  --brand-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --brand-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --brand-ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
  --brand-ease-spring-soft: cubic-bezier(0.28, 1.16, 0.45, 1);

  /* ---- z ---------------------------------------------------------------- */
  --brand-z-base: 1;
  --brand-z-dropdown: 100;
  --brand-z-sticky: 200;
  --brand-z-fixed: 300;
  --brand-z-modal-backdrop: 100000;
  --brand-z-modal: 100001;

  /* ---- Desktop knobs — the surface's own values, tenant-overridable ------
     @jowheeman/desktop reads these through its --wui-* layer. They live here,
     in --brand-*, so they ride the brand `extends` chain and BRAND_TOKENS: a
     sub-tenant inherits its parent's desktop and departs by one value. */
  --brand-desktop-ambient: 1;
  --brand-desktop-ambient-strength: 0.55;
  --brand-desktop-grain: 0.5;
  --brand-desktop-motion-scale: 1;
  --brand-desktop-rail-collapsed: 68px;
  --brand-desktop-rail-expanded: 248px;
  --brand-desktop-prompt-width: min(720px, 62vw);
  --brand-desktop-glass-alpha: var(--brand-material-glass-alpha);
  --brand-desktop-glass-blur: var(--brand-material-glass-blur);
}
/* ---- Dial-scaled seeds (0.7) — recomputed wherever a character is set -------
   Radii follow shape, the space scale follows density, durations follow motion.
   Declared on the root, on a ground (another party's character), and on any
   [data-character] region — a dense ledger table inside an airy page — so a dial
   set there moves the tokens there. A tenant's override of one of these tokens
   holds on the root it was injected on; a character region re-derives. */
:root,
[data-brand],
[data-character] {
  --brand-space-2xs: calc(2px * var(--brand-density));
  --brand-space-xs: calc(4px * var(--brand-density));
  --brand-space-sm: calc(8px * var(--brand-density));
  --brand-space-md: calc(12px * var(--brand-density));
  --brand-space-lg: calc(16px * var(--brand-density));
  --brand-space-xl: calc(24px * var(--brand-density));
  --brand-space-xxl: calc(32px * var(--brand-density));
  --brand-space-xxxl: calc(48px * var(--brand-density));
  --brand-space-huge: calc(64px * var(--brand-density));
  --brand-border-radius-xs: calc(4px * var(--brand-shape));
  --brand-border-radius-sm: calc(6px * var(--brand-shape));
  --brand-border-radius: calc(10px * var(--brand-shape));
  --brand-border-radius-lg: calc(14px * var(--brand-shape));
  --brand-border-radius-xl: calc(20px * var(--brand-shape));
  /* The desktop's corner follows the same dial (0.8.3): as a seed it was computed
     once on the root, so inside a character region the desktop kept the root's
     corner while every other radius took the region's shape. */
  --brand-desktop-radius: var(--brand-border-radius-lg);
  --brand-motion-instant: calc(90ms * var(--brand-motion-scale));
  --brand-motion-fast: calc(140ms * var(--brand-motion-scale));
  --brand-motion-base: calc(220ms * var(--brand-motion-scale));
  --brand-motion-slow: calc(380ms * var(--brand-motion-scale));
  --brand-motion-slower: calc(560ms * var(--brand-motion-scale));
}


/* ---- Derivations — recomputed wherever a scope carries its own seeds ---- */
:root,
[data-brand],
[data-theme='dark'],
[data-theme='light'],
[data-character] {
  /* The seed the whole system is tuned from. Defaults to the accent, but can be
     steered on its own (a tenant may want chrome tinted differently from its
     call-to-action colour).

     NOTE the two-name split around the accent, and do not collapse it: the SEED
     is --brand-color-semantic-accent (what the gateway writes from
     BRAND_COLOR_ACCENT, identical in both schemes) and the USED value is
     --brand-accent (scheme-resolved — the seed's own lightness rarely carries on
     a dark field). Redefining the seed in terms of itself is a var() cycle,
     which makes both names invalid-at-computed-value-time and silently collapses
     the palette. Everything downstream reads --brand-accent. */
  --brand-tint: var(--brand-color-semantic-accent);

  /* ---- Derived colour — light ("paper") --------------------------------- */
  --brand-color-surface-page: color-mix(in oklab, var(--brand-tint) 4%, #fbfcfd);
  --brand-color-surface-panel: color-mix(in oklab, var(--brand-tint) 2%, #ffffff);
  --brand-color-surface-elevated: color-mix(in oklab, var(--brand-tint) 1%, #ffffff);
  --brand-color-surface-input: color-mix(in oklab, var(--brand-tint) 3%, #ffffff);
  --brand-color-surface-card: color-mix(in oklab, var(--brand-tint) 2%, #ffffff);
  --brand-color-surface-hover: color-mix(in oklab, var(--brand-tint) 7%, #f3f5f8);
  --brand-color-surface-muted: color-mix(in oklab, var(--brand-tint) 5%, #eceff3);
  --brand-color-surface-sunken: color-mix(in oklab, var(--brand-tint) 6%, #e6eaef);

  --brand-color-on-surface-primary: color-mix(in oklab, var(--brand-tint) 8%, #14181d);
  --brand-color-on-surface-secondary: color-mix(in oklab, var(--brand-tint) 8%, #4a5259);
  --brand-color-on-surface-muted: color-mix(in oklab, var(--brand-tint) 8%, #6d767f);

  /* Hairlines, not borders. A 1px pure-black rule reads as a drawing mistake at
     this density; an alpha rule reads as an edge. */
  --brand-color-outline-subtle: color-mix(in oklab, var(--brand-color-on-surface-primary) 12%, transparent);
  --brand-color-outline-default: color-mix(in oklab, var(--brand-color-on-surface-primary) 26%, transparent);
  --brand-color-outline-strong: color-mix(in oklab, var(--brand-color-on-surface-primary) 46%, transparent);


  /* used — light needs no lift, so it is the seed */
  --brand-accent: var(--brand-color-semantic-accent);
  --brand-accent-hover: color-mix(in oklab, var(--brand-accent) 82%, #ffffff);
  --brand-accent-dim: color-mix(in oklab, var(--brand-accent) 22%, transparent);
  --brand-accent-quiet: color-mix(in oklab, var(--brand-accent) 10%, transparent);
  --brand-color-on-accent: #ffffff;

  --brand-color-semantic-accent-hover: var(--brand-accent-hover);
  --brand-color-semantic-accent-dim: var(--brand-accent-dim);
  --brand-color-semantic-accent-quiet: var(--brand-accent-quiet);

  --brand-color-bg-secondary: var(--brand-color-surface-muted);
  --brand-color-bg-tertiary: var(--brand-color-surface-sunken);
  --brand-color-text-secondary: var(--brand-color-on-surface-secondary);
  --brand-color-text-tertiary: var(--brand-color-on-surface-muted);

  /* Provenance of a person's own act follows the accent. */
  --brand-prov-user: var(--brand-accent);

  /* ---- Work state — one vocabulary for "how far along is this" ----------
     The companion to --brand-prov-* above: provenance says where a thing came
     from, state says where it stands. Five steps, in the order they displace
     each other — behind beats everything, done is the quietest.

     Three faces per step, because a state is shown three ways and every
     surface that mixed its own ended up with a different colour for the same
     word: -text (foreground on a normal surface), -edge (the hairline), and
     -field (the quiet fill behind it). Never use the raw status colour for
     text: it is tuned to sit ON a surface, not to be read against one.

     Each face is mixed toward an on-surface colour rather than used raw.
     That is what keeps amber legible on paper AND on ink: the mix partner
     flips with the scheme, so one declaration reads in both. The percentages
     are not taste — they are the point where every -text face clears WCAG AA
     (4.5:1) on both surface-page and surface-panel, in both schemes; the
     weakest is draft at 4.73 on paper. Move one and re-check it.

     Derived from the status seeds, so a tenant's own error/warning/success
     colours flow all the way through to every badge in every app. */
  --brand-state-behind-text: color-mix(in oklab, var(--brand-color-status-error) 62%, var(--brand-color-on-surface-primary));
  --brand-state-behind-edge: color-mix(in oklab, var(--brand-color-status-error) 45%, transparent);
  --brand-state-behind-field: color-mix(in oklab, var(--brand-color-status-error) 10%, transparent);

  /* Idle has no hue on purpose: "nothing has happened yet" is the absence of
     a signal, and a colour would make it one. The dashed edge that usually
     goes with it is geometry, so it belongs to the component, not here. */
  --brand-state-idle-text: var(--brand-color-on-surface-muted);
  --brand-state-idle-edge: var(--brand-color-outline-subtle);
  --brand-state-idle-field: transparent;

  --brand-state-draft-text: color-mix(in oklab, var(--brand-color-status-warning) 50%, var(--brand-color-on-surface-primary));
  --brand-state-draft-edge: color-mix(in oklab, var(--brand-color-status-warning) 45%, transparent);
  --brand-state-draft-field: color-mix(in oklab, var(--brand-color-status-warning) 10%, transparent);

  --brand-state-ready-text: color-mix(in oklab, var(--brand-color-status-success) 52%, var(--brand-color-on-surface-primary));
  --brand-state-ready-edge: color-mix(in oklab, var(--brand-color-status-success) 45%, transparent);
  --brand-state-ready-field: color-mix(in oklab, var(--brand-color-status-success) 10%, transparent);

  /* Done is ready, turned down. Ready still asks for a hand (it is made, but
     not out the door yet); done asks for nothing. Giving them the same weight
     — which is what every surface did while each mixed its own — means the
     one row that still needs you looks exactly like the forty that do not. */
  --brand-state-done-text: color-mix(in oklab, var(--brand-color-status-success) 26%, var(--brand-color-on-surface-secondary));
  --brand-state-done-edge: color-mix(in oklab, var(--brand-color-status-success) 22%, var(--brand-color-outline-subtle));
  --brand-state-done-field: transparent;

  /* ---- People — eight colours a PERSON wears (0.8, design.md §4) ----------
     Party mark ⊃ person mark ⊃ screen hue. A person's colour is the person's: no
     tenant token reaches it, so it lives here with the scheme-resolved values, not
     in the seeds. Eight hues evenly spaced in OKLCH (25° apart × 45°), one lightness
     per scheme, each ≥ 3.5:1 on every light surface and ≥ 7:1 on every dark one — a
     dot, a cursor, an initial stays legible whatever ground it lands on. The wire
     carries the SLOT (generalinput-client personSlot: hash(user) % 8 + 1), never a
     colour: each viewer resolves var(--brand-person-<slot>) in its own scheme. */
  --brand-person-1: #bc4945;
  --brand-person-2: #aa6000;
  --brand-person-3: #737d00;
  --brand-person-4: #008e55;
  --brand-person-5: #008b9e;
  --brand-person-6: #1577c8;
  --brand-person-7: #7c5ec2;
  --brand-person-8: #ab4b90;

  /* ---- Lines (derived) ---- */
  --brand-border-color-light: var(--brand-color-outline-subtle);
  --brand-border-color-lighter: color-mix(in oklab, var(--brand-color-on-surface-primary) 7%, transparent);
  --brand-hairline-color: var(--brand-color-outline-subtle);

  /* ---- Elevation (derived from ink) ---- */
  /* depth moves strength (opacity × depth) AND reach (offset/blur × 0.5 + depth/2):
     0 is flat, 1 is exactly today, 2 is deeper and longer. */
  --brand-depth-reach: calc(0.5 + var(--brand-depth) * 0.5);
  --brand-elevation-1:
    0 calc(1px * var(--brand-depth-reach)) calc(1px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(4% * var(--brand-depth)), transparent),
    0 calc(2px * var(--brand-depth-reach)) calc(6px * var(--brand-depth-reach)) calc(-2px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(7% * var(--brand-depth)), transparent);
  --brand-elevation-2:
    0 calc(1px * var(--brand-depth-reach)) calc(2px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(5% * var(--brand-depth)), transparent),
    0 calc(6px * var(--brand-depth-reach)) calc(16px * var(--brand-depth-reach)) calc(-6px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(11% * var(--brand-depth)), transparent);
  --brand-elevation-3:
    0 calc(2px * var(--brand-depth-reach)) calc(4px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(5% * var(--brand-depth)), transparent),
    0 calc(12px * var(--brand-depth-reach)) calc(28px * var(--brand-depth-reach)) calc(-10px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(15% * var(--brand-depth)), transparent);
  --brand-elevation-4:
    0 calc(4px * var(--brand-depth-reach)) calc(8px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(6% * var(--brand-depth)), transparent),
    0 calc(24px * var(--brand-depth-reach)) calc(56px * var(--brand-depth-reach)) calc(-18px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(20% * var(--brand-depth)), transparent);
  --brand-elevation-5:
    0 calc(8px * var(--brand-depth-reach)) calc(16px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(8% * var(--brand-depth)), transparent),
    0 calc(40px * var(--brand-depth-reach)) calc(90px * var(--brand-depth-reach)) calc(-28px * var(--brand-depth-reach)) color-mix(in oklab, var(--brand-color-on-surface-primary) calc(26% * var(--brand-depth)), transparent);

  /* ---- Materials (derived) ---- */
  --brand-material-glass-tint: var(--brand-color-surface-panel);
  --brand-material-plate: var(--brand-color-surface-panel);

  --brand-transition-fast: var(--brand-motion-fast) var(--brand-ease-out);
  --brand-transition-normal: var(--brand-motion-base) var(--brand-ease-out);
  --brand-transition-slow: var(--brand-motion-slow) var(--brand-ease-out);

  /* ---- Focus ------------------------------------------------------------ */
  --brand-focus-ring:
    0 0 0 2px var(--brand-color-surface-page),
    0 0 0 4px color-mix(in oklab, var(--brand-accent) 70%, transparent);
  --brand-focus-ring-inset: inset 0 0 0 2px color-mix(in oklab, var(--brand-accent) 70%, transparent);
}

/* =====================================================================
   Aliases — kept whole. Everything above is the source; everything below
   is a name an existing consumer already uses.
   ===================================================================== */
:root,
[data-brand],
[data-theme='dark'],
[data-theme='light'],
[data-character] {
  /* semantic → colour */
  --brand-color-bg-inverse: var(--brand-color-primary);
  --brand-color-bg-primary: var(--brand-color-secondary);
  --brand-color-text-inverse: var(--brand-color-secondary);
  --brand-color-text-primary: var(--brand-color-primary);
  --brand-color-error: var(--brand-color-status-error);
  --brand-color-success: var(--brand-color-status-success);
  --brand-color-warning: var(--brand-color-status-warning);
  --brand-color-info: var(--brand-color-status-info);
  --brand-border-color: var(--brand-color-outline-default);

  --brand-surface-page: var(--brand-color-surface-page);
  --brand-surface-panel: var(--brand-color-surface-panel);
  --brand-surface-elevated: var(--brand-color-surface-elevated);
  --brand-surface-input: var(--brand-color-surface-input);
  --brand-surface-card: var(--brand-color-surface-card);
  --brand-surface-hover: var(--brand-color-surface-hover);
  --brand-surface-muted: var(--brand-color-surface-muted);
  --brand-on-surface-primary: var(--brand-color-on-surface-primary);
  --brand-on-surface-secondary: var(--brand-color-on-surface-secondary);
  --brand-on-surface-muted: var(--brand-color-on-surface-muted);
  --brand-outline-default: var(--brand-color-outline-default);
  --brand-outline-subtle: var(--brand-color-outline-subtle);

  /* elevation aliases — the old three names map onto the new ramp */
  --brand-shadow-elevation-sm: var(--brand-elevation-1);
  --brand-shadow-elevation-md: var(--brand-elevation-3);
  --brand-shadow-elevation-lg: var(--brand-elevation-4);
  --brand-shadow-sm: var(--brand-elevation-1);
  --brand-shadow-md: var(--brand-elevation-2);
  --brand-shadow-lg: var(--brand-elevation-3);
  --brand-shadow-xl: var(--brand-elevation-5);
  --brand-elevation-sm: var(--brand-elevation-1);
  --brand-elevation-md: var(--brand-elevation-3);
  --brand-elevation-lg: var(--brand-elevation-4);

  --brand-spacing-xs: var(--brand-space-xs);
  --brand-spacing-sm: var(--brand-space-sm);
  --brand-spacing-md: var(--brand-space-md);
  --brand-spacing-lg: var(--brand-space-lg);
  --brand-spacing-xl: var(--brand-space-xl);
  --brand-spacing-xxl: var(--brand-space-xxl);
  --brand-spacing-xxxl: var(--brand-space-xxxl);

  --brand-primary-color: var(--brand-color-primary);
  --brand-secondary-color: var(--brand-color-secondary);
  --brand-text-secondary: var(--brand-color-text-secondary);
  --brand-text-tertiary: var(--brand-color-text-tertiary);
  --brand-font-family: var(--brand-typography-font-family-sans);
  --brand-font-size-xs: var(--brand-typography-font-size-xs);
  --brand-font-size-sm: var(--brand-typography-font-size-sm);
  --brand-font-size-base: var(--brand-typography-font-size-base);
  --brand-font-size-md: var(--brand-typography-font-size-md);
  --brand-font-size-lg: var(--brand-typography-font-size-lg);
  --brand-font-size-xl: var(--brand-typography-font-size-xl);
  --brand-font-size-xxl: var(--brand-typography-font-size-xxl);
  --brand-font-size-xxxl: var(--brand-typography-font-size-xxxl);
  --brand-font-weight-normal: var(--brand-typography-font-weight-normal);
  --brand-font-weight-medium: var(--brand-typography-font-weight-medium);
  --brand-font-weight-semibold: var(--brand-typography-font-weight-semibold);
  --brand-font-weight-bold: var(--brand-typography-font-weight-bold);
  --brand-line-height-tight: var(--brand-typography-line-height-tight);
  --brand-line-height-normal: var(--brand-typography-line-height-normal);
  --brand-line-height-base: var(--brand-typography-line-height-base);
  --brand-line-height-relaxed: var(--brand-typography-line-height-relaxed);
  --brand-line-height-loose: var(--brand-typography-line-height-loose);
  --brand-letter-spacing-tight: var(--brand-typography-letter-spacing-tight);
  --brand-letter-spacing-normal: var(--brand-typography-letter-spacing-normal);
  --brand-letter-spacing-wide: var(--brand-typography-letter-spacing-wide);
  --brand-bg-secondary: var(--brand-color-bg-secondary);
  --brand-bg-tertiary: var(--brand-color-bg-tertiary);
  --brand-text-primary: var(--brand-color-text-primary);
  --brand-text-inverse: var(--brand-color-text-inverse);
  --brand-bg-inverse: var(--brand-color-bg-inverse);
  --brand-bg-primary: var(--brand-color-bg-primary);

  /* back-compat alias: --wisse-* → --brand-* (retire once the fleet is rebuilt) */
  --wisse-color-status-success: var(--brand-color-status-success);
  --wisse-color-status-error: var(--brand-color-status-error);
  --wisse-color-status-warning: var(--brand-color-status-warning);
  --wisse-color-status-info: var(--brand-color-status-info);
  --wisse-color-semantic-accent-hover: var(--brand-accent-hover);
  --wisse-color-semantic-accent-dim: var(--brand-accent-dim);
  --wisse-color-primary: var(--brand-color-primary);
  --wisse-color-secondary: var(--brand-color-secondary);
  --wisse-color-surface-page: var(--brand-color-surface-page);
  --wisse-color-surface-panel: var(--brand-color-surface-panel);
  --wisse-color-surface-elevated: var(--brand-color-surface-elevated);
  --wisse-color-surface-input: var(--brand-color-surface-input);
  --wisse-color-surface-card: var(--brand-color-surface-card);
  --wisse-color-surface-hover: var(--brand-color-surface-hover);
  --wisse-color-surface-muted: var(--brand-color-surface-muted);
  --wisse-color-on-surface-primary: var(--brand-color-on-surface-primary);
  --wisse-color-on-surface-secondary: var(--brand-color-on-surface-secondary);
  --wisse-color-on-surface-muted: var(--brand-color-on-surface-muted);
  --wisse-color-outline-default: var(--brand-color-outline-default);
  --wisse-color-outline-subtle: var(--brand-color-outline-subtle);
  --wisse-color-bg-secondary: var(--brand-color-bg-secondary);
  --wisse-color-bg-tertiary: var(--brand-color-bg-tertiary);
  --wisse-color-text-secondary: var(--brand-color-text-secondary);
  --wisse-color-text-tertiary: var(--brand-color-text-tertiary);
  --wisse-typography-font-family-sans: var(--brand-typography-font-family-sans);
  --wisse-typography-font-family-reading: var(--brand-typography-font-family-reading);
  --wisse-typography-font-family-mono: var(--brand-typography-font-family-mono);
  --wisse-typography-font-size-xs: var(--brand-typography-font-size-xs);
  --wisse-typography-font-size-sm: var(--brand-typography-font-size-sm);
  --wisse-typography-font-size-base: var(--brand-typography-font-size-base);
  --wisse-typography-font-size-md: var(--brand-typography-font-size-md);
  --wisse-typography-font-size-lg: var(--brand-typography-font-size-lg);
  --wisse-typography-font-size-xl: var(--brand-typography-font-size-xl);
  --wisse-typography-font-size-xxl: var(--brand-typography-font-size-xxl);
  --wisse-typography-font-size-xxxl: var(--brand-typography-font-size-xxxl);
  --wisse-typography-font-size-huge: var(--brand-typography-font-size-huge);
  --wisse-typography-font-weight-normal: var(--brand-typography-font-weight-normal);
  --wisse-typography-font-weight-medium: var(--brand-typography-font-weight-medium);
  --wisse-typography-font-weight-semibold: var(--brand-typography-font-weight-semibold);
  --wisse-typography-font-weight-bold: var(--brand-typography-font-weight-bold);
  --wisse-typography-line-height-tight: var(--brand-typography-line-height-tight);
  --wisse-typography-line-height-normal: var(--brand-typography-line-height-normal);
  --wisse-typography-line-height-base: var(--brand-typography-line-height-base);
  --wisse-typography-line-height-relaxed: var(--brand-typography-line-height-relaxed);
  --wisse-typography-line-height-loose: var(--brand-typography-line-height-loose);
  --wisse-typography-letter-spacing-tight: var(--brand-typography-letter-spacing-tight);
  --wisse-typography-letter-spacing-normal: var(--brand-typography-letter-spacing-normal);
  --wisse-typography-letter-spacing-wide: var(--brand-typography-letter-spacing-wide);
  --wisse-space-xs: var(--brand-space-xs);
  --wisse-space-sm: var(--brand-space-sm);
  --wisse-space-md: var(--brand-space-md);
  --wisse-space-lg: var(--brand-space-lg);
  --wisse-space-xl: var(--brand-space-xl);
  --wisse-space-xxl: var(--brand-space-xxl);
  --wisse-space-xxxl: var(--brand-space-xxxl);
  --wisse-space-touch-target: var(--brand-space-touch-target);
  --wisse-border-radius: var(--brand-border-radius);
  --wisse-border-radius-sm: var(--brand-border-radius-sm);
  --wisse-border-radius-lg: var(--brand-border-radius-lg);
  --wisse-border-radius-full: var(--brand-border-radius-full);
  --wisse-border-width: var(--brand-border-width);
  --wisse-border-width-thin: var(--brand-border-width-thin);
  --wisse-border-width-thick: var(--brand-border-width-thick);
  --wisse-border-color-light: var(--brand-border-color-light);
  --wisse-border-color-lighter: var(--brand-border-color-lighter);
  --wisse-shadow-elevation-sm: var(--brand-shadow-elevation-sm);
  --wisse-shadow-elevation-md: var(--brand-shadow-elevation-md);
  --wisse-shadow-elevation-lg: var(--brand-shadow-elevation-lg);
  --wisse-shadow-sm: var(--brand-shadow-sm);
  --wisse-shadow-md: var(--brand-shadow-md);
  --wisse-shadow-lg: var(--brand-shadow-lg);
  --wisse-shadow-xl: var(--brand-shadow-xl);
  --wisse-transition-fast: var(--brand-transition-fast);
  --wisse-transition-normal: var(--brand-transition-normal);
  --wisse-transition-slow: var(--brand-transition-slow);
  --wisse-z-base: var(--brand-z-base);
  --wisse-z-sticky: var(--brand-z-sticky);
  --wisse-z-dropdown: var(--brand-z-dropdown);
  --wisse-z-fixed: var(--brand-z-fixed);
  --wisse-z-modal-backdrop: var(--brand-z-modal-backdrop);
  --wisse-z-modal: var(--brand-z-modal);
  --wisse-color-semantic-accent: var(--brand-accent);
  --wisse-color-bg-inverse: var(--brand-color-bg-inverse);
  --wisse-color-bg-primary: var(--brand-color-bg-primary);
  --wisse-color-text-inverse: var(--brand-color-text-inverse);
  --wisse-color-text-primary: var(--brand-color-text-primary);
  --wisse-color-error: var(--brand-color-error);
  --wisse-color-success: var(--brand-color-success);
  --wisse-color-warning: var(--brand-color-warning);
  --wisse-color-info: var(--brand-color-info);
  --wisse-border-color: var(--brand-border-color);
  --wisse-surface-page: var(--brand-surface-page);
  --wisse-surface-panel: var(--brand-surface-panel);
  --wisse-surface-elevated: var(--brand-surface-elevated);
  --wisse-surface-input: var(--brand-surface-input);
  --wisse-surface-card: var(--brand-surface-card);
  --wisse-surface-hover: var(--brand-surface-hover);
  --wisse-surface-muted: var(--brand-surface-muted);
  --wisse-on-surface-primary: var(--brand-on-surface-primary);
  --wisse-on-surface-secondary: var(--brand-on-surface-secondary);
  --wisse-on-surface-muted: var(--brand-on-surface-muted);
  --wisse-outline-default: var(--brand-outline-default);
  --wisse-outline-subtle: var(--brand-outline-subtle);
  --wisse-elevation-sm: var(--brand-elevation-sm);
  --wisse-elevation-md: var(--brand-elevation-md);
  --wisse-elevation-lg: var(--brand-elevation-lg);
  --wisse-spacing-xs: var(--brand-spacing-xs);
  --wisse-spacing-sm: var(--brand-spacing-sm);
  --wisse-spacing-md: var(--brand-spacing-md);
  --wisse-spacing-lg: var(--brand-spacing-lg);
  --wisse-spacing-xl: var(--brand-spacing-xl);
  --wisse-spacing-xxl: var(--brand-spacing-xxl);
  --wisse-spacing-xxxl: var(--brand-spacing-xxxl);
  --wisse-primary-color: var(--brand-primary-color);
  --wisse-secondary-color: var(--brand-secondary-color);
  --wisse-text-secondary: var(--brand-text-secondary);
  --wisse-text-tertiary: var(--brand-text-tertiary);
  --wisse-font-family: var(--brand-font-family);
  --wisse-font-size-xs: var(--brand-font-size-xs);
  --wisse-font-size-sm: var(--brand-font-size-sm);
  --wisse-font-size-base: var(--brand-font-size-base);
  --wisse-font-size-md: var(--brand-font-size-md);
  --wisse-font-size-lg: var(--brand-font-size-lg);
  --wisse-font-size-xl: var(--brand-font-size-xl);
  --wisse-font-size-xxl: var(--brand-font-size-xxl);
  --wisse-font-size-xxxl: var(--brand-font-size-xxxl);
  --wisse-font-weight-normal: var(--brand-font-weight-normal);
  --wisse-font-weight-medium: var(--brand-font-weight-medium);
  --wisse-font-weight-semibold: var(--brand-font-weight-semibold);
  --wisse-font-weight-bold: var(--brand-font-weight-bold);
  --wisse-line-height-tight: var(--brand-line-height-tight);
  --wisse-line-height-normal: var(--brand-line-height-normal);
  --wisse-line-height-base: var(--brand-line-height-base);
  --wisse-line-height-relaxed: var(--brand-line-height-relaxed);
  --wisse-line-height-loose: var(--brand-line-height-loose);
  --wisse-letter-spacing-tight: var(--brand-letter-spacing-tight);
  --wisse-letter-spacing-normal: var(--brand-letter-spacing-normal);
  --wisse-letter-spacing-wide: var(--brand-letter-spacing-wide);
  --wisse-bg-secondary: var(--brand-bg-secondary);
  --wisse-bg-tertiary: var(--brand-bg-tertiary);
  --wisse-text-primary: var(--brand-text-primary);
  --wisse-text-inverse: var(--brand-text-inverse);
  --wisse-bg-inverse: var(--brand-bg-inverse);
  --wisse-bg-primary: var(--brand-bg-primary);
}

/* =====================================================================
   DARK — the Instrument's home scheme.
   Every value reads --brand-dark-* first so a tenant keeps authority here
   (see note 4 at the top). The --wisse-* twin is restated for the colours
   that flip, because the gateway injects flat --wisse-* literals into a
   plain :root and this block must outrank them for the scheme to hold.
   ===================================================================== */
:root[data-theme='dark'],
[data-theme='dark'],
[data-theme='dark'] [data-brand]:not([data-theme='light']),
[data-theme='dark'] [data-character]:not([data-theme='light']) {
  color-scheme: dark;

  --brand-color-primary: var(--brand-dark-primary, #f2f5f8);
  --brand-color-secondary: var(--brand-dark-secondary, #0a0c0f);

  --brand-color-surface-page: var(--brand-dark-surface-page, color-mix(in oklab, var(--brand-tint) 7%, #0a0c0f));
  --brand-color-surface-panel: var(--brand-dark-surface-panel, color-mix(in oklab, var(--brand-tint) 8%, #14171c));
  --brand-color-surface-elevated: var(--brand-dark-surface-elevated, color-mix(in oklab, var(--brand-tint) 9%, #1b1f25));
  --brand-color-surface-input: var(--brand-dark-surface-input, color-mix(in oklab, var(--brand-tint) 7%, #101317));
  --brand-color-surface-card: var(--brand-dark-surface-card, color-mix(in oklab, var(--brand-tint) 8%, #14171c));
  --brand-color-surface-hover: var(--brand-dark-surface-hover, color-mix(in oklab, var(--brand-tint) 12%, #22262d));
  --brand-color-surface-muted: var(--brand-dark-surface-muted, color-mix(in oklab, var(--brand-tint) 6%, #101318));
  --brand-color-surface-sunken: var(--brand-dark-surface-sunken, color-mix(in oklab, var(--brand-tint) 5%, #06080a));

  --brand-color-on-surface-primary: var(--brand-dark-on-surface-primary, color-mix(in oklab, var(--brand-tint) 5%, #f2f5f8));
  --brand-color-on-surface-secondary: var(--brand-dark-on-surface-secondary, color-mix(in oklab, var(--brand-tint) 7%, #b6bec8));
  --brand-color-on-surface-muted: var(--brand-dark-on-surface-muted, color-mix(in oklab, var(--brand-tint) 8%, #89939f));

  --brand-color-outline-subtle: var(--brand-dark-outline-subtle, color-mix(in oklab, #ffffff 11%, transparent));
  --brand-color-outline-default: var(--brand-dark-outline-default, color-mix(in oklab, #ffffff 20%, transparent));
  --brand-color-outline-strong: var(--brand-dark-outline-strong, color-mix(in oklab, #ffffff 34%, transparent));

  /* The accent is the only light in the room, so it has to carry on a dark
     field — the seed's own lightness usually will not. Lifted FROM the seed,
     never from itself (see the note on the two-name split above). */
  --brand-accent: var(--brand-dark-accent, color-mix(in oklab, var(--brand-color-semantic-accent) 58%, #dbeafe));
  --brand-accent-hover: color-mix(in oklab, var(--brand-accent) 78%, #ffffff);
  --brand-accent-dim: color-mix(in oklab, var(--brand-accent) 26%, transparent);
  --brand-accent-quiet: color-mix(in oklab, var(--brand-accent) 12%, transparent);
  --brand-color-on-accent: var(--brand-dark-on-accent, #08111c);

  --brand-color-status-success: var(--brand-dark-status-success, #4ade80);
  --brand-color-status-error: var(--brand-dark-status-error, #ff7a7d);
  --brand-color-status-warning: var(--brand-dark-status-warning, #fbbf46);

  --brand-prov-ai: var(--brand-dark-prov-ai, #b48cf2);
  --brand-prov-tool: var(--brand-dark-prov-tool, #4bd8b4);
  --brand-prov-grammar: var(--brand-dark-prov-grammar, #e0a45c);

  /* People: the same eight hues, lifted for a dark ground (≥ 7:1). */
  --brand-person-1: #f98f87;
  --brand-person-2: #e5a14b;
  --brand-person-3: #afbb52;
  --brand-person-4: #5aca94;
  --brand-person-5: #00c8d8;
  --brand-person-6: #6db6ff;
  --brand-person-7: #b7a0fb;
  --brand-person-8: #e88fcb;

  /* --brand-state-* is deliberately NOT restated here, and that is not an
     omission to be helpfully corrected. Every state face is a color-mix of
     --brand-color-status-* with --brand-color-on-surface-primary, and BOTH of
     those are redeclared in this block, on this same element. A custom
     property's var() references resolve against the element it lands on, so
     the light declarations above pick up these dark values by themselves —
     one declaration that reads correctly in both schemes.

     Tenant authority is intact for the same reason: --brand-dark-status-error
     and friends steer the states in dark, one level up. Restating the mixes
     here would duplicate the formula and let the two copies drift. */

  /* Elevation on a dark field is depth of shadow *plus* a lit top edge —
     shadow alone disappears into the ground. */
  --brand-elevation-1:
    0 calc(1px * var(--brand-depth-reach)) calc(1px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.5 * var(--brand-depth))),
    0 calc(2px * var(--brand-depth-reach)) calc(8px * var(--brand-depth-reach)) calc(-3px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.6 * var(--brand-depth)));
  --brand-elevation-2:
    0 calc(1px * var(--brand-depth-reach)) calc(2px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.5 * var(--brand-depth))),
    0 calc(8px * var(--brand-depth-reach)) calc(20px * var(--brand-depth-reach)) calc(-8px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.66 * var(--brand-depth)));
  --brand-elevation-3:
    0 calc(2px * var(--brand-depth-reach)) calc(4px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.5 * var(--brand-depth))),
    0 calc(16px * var(--brand-depth-reach)) calc(34px * var(--brand-depth-reach)) calc(-12px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.72 * var(--brand-depth)));
  --brand-elevation-4:
    0 calc(4px * var(--brand-depth-reach)) calc(10px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.5 * var(--brand-depth))),
    0 calc(30px * var(--brand-depth-reach)) calc(64px * var(--brand-depth-reach)) calc(-20px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.78 * var(--brand-depth)));
  --brand-elevation-5:
    0 calc(10px * var(--brand-depth-reach)) calc(20px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.55 * var(--brand-depth))),
    0 calc(52px * var(--brand-depth-reach)) calc(110px * var(--brand-depth-reach)) calc(-32px * var(--brand-depth-reach)) rgb(0 0 0 / calc(0.84 * var(--brand-depth)));

  --brand-material-glass-alpha: 64%;
  --brand-material-glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --brand-material-plate-edge: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  --brand-border-color-lighter: color-mix(in oklab, #ffffff 6%, transparent);

  --brand-focus-ring:
    0 0 0 2px var(--brand-color-surface-page),
    0 0 0 4px color-mix(in oklab, var(--brand-accent) 78%, transparent);

  /* --wisse-* twins for the flipped colours.
     Why restate what the alias layer already forwards: the gateway injects flat
     --wisse-* literals into a plain :root at serve time (both the four legacy
     BRAND_COLOR_* keys and the twin of every BRAND_TOKENS entry). Those literals
     are light-scheme values, and a plain :root would otherwise beat the alias.
     [data-theme="dark"] outranks them, so the scheme holds for branded tenants
     too — and a tenant that wants explicit dark control still wins by setting
     --brand-dark-*, which every declaration above reads first. */
  --wisse-color-primary: var(--brand-color-primary);
  --wisse-color-secondary: var(--brand-color-secondary);
  --wisse-color-surface-page: var(--brand-color-surface-page);
  --wisse-color-surface-panel: var(--brand-color-surface-panel);
  --wisse-color-surface-elevated: var(--brand-color-surface-elevated);
  --wisse-color-surface-input: var(--brand-color-surface-input);
  --wisse-color-surface-card: var(--brand-color-surface-card);
  --wisse-color-surface-hover: var(--brand-color-surface-hover);
  --wisse-color-surface-muted: var(--brand-color-surface-muted);
  --wisse-color-on-surface-primary: var(--brand-color-on-surface-primary);
  --wisse-color-on-surface-secondary: var(--brand-color-on-surface-secondary);
  --wisse-color-on-surface-muted: var(--brand-color-on-surface-muted);
  --wisse-color-outline-subtle: var(--brand-color-outline-subtle);
  --wisse-color-outline-default: var(--brand-color-outline-default);
  --wisse-color-semantic-accent: var(--brand-accent);
  --wisse-color-semantic-accent-hover: var(--brand-accent-hover);
  --wisse-color-semantic-accent-dim: var(--brand-accent-dim);
  --wisse-color-status-success: var(--brand-color-status-success);
  --wisse-color-status-error: var(--brand-color-status-error);
  --wisse-color-status-warning: var(--brand-color-status-warning);
  --wisse-surface-page: var(--brand-color-surface-page);
  --wisse-surface-panel: var(--brand-color-surface-panel);
  --wisse-surface-elevated: var(--brand-color-surface-elevated);
  --wisse-surface-input: var(--brand-color-surface-input);
  --wisse-surface-card: var(--brand-color-surface-card);
  --wisse-surface-hover: var(--brand-color-surface-hover);
  --wisse-surface-muted: var(--brand-color-surface-muted);
  --wisse-on-surface-primary: var(--brand-color-on-surface-primary);
  --wisse-on-surface-secondary: var(--brand-color-on-surface-secondary);
  --wisse-on-surface-muted: var(--brand-color-on-surface-muted);
  --wisse-outline-subtle: var(--brand-color-outline-subtle);
  --wisse-outline-default: var(--brand-color-outline-default);
  --wisse-elevation-sm: var(--brand-elevation-1);
  --wisse-elevation-md: var(--brand-elevation-3);
  --wisse-elevation-lg: var(--brand-elevation-4);
  --wisse-shadow-elevation-sm: var(--brand-elevation-1);
  --wisse-shadow-elevation-md: var(--brand-elevation-3);
  --wisse-shadow-elevation-lg: var(--brand-elevation-4);
  --wisse-border-color-light: var(--brand-color-outline-subtle);
  --wisse-border-color-lighter: var(--brand-border-color-lighter);
  --wisse-color-bg-secondary: var(--brand-color-surface-muted);
  --wisse-color-bg-tertiary: var(--brand-color-surface-sunken);
  --wisse-color-text-secondary: var(--brand-color-on-surface-secondary);
  --wisse-color-text-tertiary: var(--brand-color-on-surface-muted);
  --wisse-color-text-primary: var(--brand-color-primary);
  --wisse-color-text-inverse: var(--brand-color-secondary);
  --wisse-color-bg-primary: var(--brand-color-secondary);
  --wisse-color-bg-inverse: var(--brand-color-primary);
}
/* =====================================================================
   LIGHT ISLAND — a `data-theme="light"` element inside a dark page (0.6).
   The dark block overwrites these names IN PLACE (every consumer reads
   --brand-color-primary as "the ink right now", so its meaning cannot move).
   Their light values survive under a seed twin (--brand-seed-*, set in the
   seeds block, never touched by a scheme), and this block restores them; the
   derivation and alias blocks recompute here too. The gateway injects a
   tenant's value under the twin as well (@jowheeman/gateway ≥0.18.6), so the
   island carries the tenant's light colours, not only the platform's.
   check-tokens rule 8: every name the dark block overwrites in the seeds block
   has a twin and a restore here — nothing flips one way only.
   ===================================================================== */
[data-theme='light']:not(:root) {
  color-scheme: light;
  --brand-color-primary: var(--brand-seed-color-primary);
  --brand-color-secondary: var(--brand-seed-color-secondary);
  --brand-color-status-success: var(--brand-seed-color-status-success);
  --brand-color-status-error: var(--brand-seed-color-status-error);
  --brand-color-status-warning: var(--brand-seed-color-status-warning);
  --brand-prov-ai: var(--brand-seed-prov-ai);
  --brand-prov-tool: var(--brand-seed-prov-tool);
  --brand-prov-grammar: var(--brand-seed-prov-grammar);
  --brand-material-glass-alpha: var(--brand-seed-material-glass-alpha);
  --brand-material-glass-highlight: var(--brand-seed-material-glass-highlight);
  --brand-material-plate-edge: var(--brand-seed-material-plate-edge);
}


/* ---- The person's layer — legibility is the PERSON's (design.md §3) -------------
   Motion, contrast and forced colours win over any tenant dial, app register or region
   character. One mechanism for all three — the one CSS already gives a reader's own
   stylesheet: the declarations are !important, and they are stated on EVERY scope that
   re-declares tokens: the root, each ground ([data-brand]), each island ([data-theme]),
   each character region ([data-character]). !important beats specificity, a later
   normal declaration and an inline brand on the same element; stating it on each scope
   beats the re-derivation there, which inheritance from <html> alone would lose to.
   check-tokens rule 11 holds a person block to exactly this shape.

   Two triggers each: the OS/browser media feature, and the attribute an app sets on
   <html> for a person whose preference never reaches the OS (a shared or kiosk device;
   products/profiel's leesbaarheid.js, platform/docs/iedereen.md): data-beweging="rustig",
   data-contrast="hoog". Contrast reads each scope's OWN derived ink, so a guest's ground
   with a dark surface in a light page gets its ink, never the page's — and the brand
   accent is left alone. */
/* Text size is the person's too (data-tekstgrootte, 0.10.0): a scale on the root, which every rem
   in this file (and in any app that writes rem) follows. !important so an app's own
   `html { font-size: 16px }` — three consumers pin one — cannot hold the person back; a
   percentage, not px, so the browser's own text-size setting still counts underneath. */
html[data-tekstgrootte='groot'] {
  font-size: 125% !important;
}
html[data-tekstgrootte='extra'] {
  font-size: 150% !important;
}

@media (prefers-reduced-motion: reduce) {
  :root,
  :root :is([data-brand], [data-theme], [data-character]) {
    --brand-motion-scale: 0 !important;
  }
}
html[data-beweging='rustig'],
html[data-beweging='rustig'] :is([data-brand], [data-theme], [data-character]) {
  --brand-motion-scale: 0 !important;
}

@media (prefers-contrast: more) {
  :root,
  :root :is([data-brand], [data-theme], [data-character]) {
    --brand-color-on-surface-secondary: var(--brand-color-on-surface-primary) !important;
    --brand-color-on-surface-muted: var(--brand-color-on-surface-primary) !important;
    --brand-color-text-secondary: var(--brand-color-on-surface-primary) !important;
    --brand-color-text-tertiary: var(--brand-color-on-surface-primary) !important;
    --brand-color-outline-subtle: var(--brand-color-on-surface-primary) !important;
    --brand-color-outline-default: var(--brand-color-on-surface-primary) !important;
    --brand-color-outline-strong: var(--brand-color-on-surface-primary) !important;
    --brand-focus-ring: 0 0 0 2px var(--brand-color-surface-page), 0 0 0 6px var(--brand-color-on-surface-primary) !important;
    --brand-focus-ring-inset: inset 0 0 0 3px var(--brand-color-on-surface-primary) !important;
  }
}
html[data-contrast='hoog'],
html[data-contrast='hoog'] :is([data-brand], [data-theme], [data-character]) {
  --brand-color-on-surface-secondary: var(--brand-color-on-surface-primary) !important;
  --brand-color-on-surface-muted: var(--brand-color-on-surface-primary) !important;
  --brand-color-text-secondary: var(--brand-color-on-surface-primary) !important;
  --brand-color-text-tertiary: var(--brand-color-on-surface-primary) !important;
  --brand-color-outline-subtle: var(--brand-color-on-surface-primary) !important;
  --brand-color-outline-default: var(--brand-color-on-surface-primary) !important;
  --brand-color-outline-strong: var(--brand-color-on-surface-primary) !important;
  --brand-focus-ring: 0 0 0 2px var(--brand-color-surface-page), 0 0 0 6px var(--brand-color-on-surface-primary) !important;
  --brand-focus-ring-inset: inset 0 0 0 3px var(--brand-color-on-surface-primary) !important;
}

/* forced-colors (Windows High Contrast and alike): the UA repaints color, background and
   border-color itself, but not box-shadow in every engine — and the focus ring and the
   outline aliases paint through it. System colours resolve per scheme, so one block. */
@media (forced-colors: active) {
  :root,
  :root :is([data-brand], [data-theme], [data-character]) {
    --brand-color-outline-subtle: CanvasText !important;
    --brand-color-outline-default: CanvasText !important;
    --brand-color-outline-strong: CanvasText !important;
    --brand-focus-ring: 0 0 0 2px Canvas, 0 0 0 4px Highlight !important;
    --brand-focus-ring-inset: inset 0 0 0 2px Highlight !important;
  }
}

/* A hairline should be a hairline, not a device pixel that happens to be 1/2pt
   wide on a retina panel. */
@media (min-resolution: 2dppx) {
  :root,
  [data-brand] {
    --brand-hairline: 0.5px;
  }
}

/* A ground paints itself. Zero specificity (:where), so any app rule wins;
   only [data-brand] — a dark island paints itself, because the one that exists
   today (.wui-desktop) deliberately draws its own field. Paint where you are:
   a colour inherited from <body> was computed for the host (design.md §8).
   Never the root (0.5.1): marketing stamps html[data-brand='1'] as its "brand
   applied" flag, and a background on <html> would stop <body>'s propagating to
   the canvas. The root is the host's ground and the app paints it already. */
:where([data-brand]:not(:root)) {
  background-color: var(--brand-color-surface-page);
  color: var(--brand-color-on-surface-primary);
}
