/* ==========================================================================
 * BMX Web Components - global token layer
 * ==========================================================================
 *
 * Stencil injects this once into the document (see `globalStyle` in
 * stencil.config.ts). It defines *only* custom properties and a very small
 * amount of host-agnostic base styling - no element selectors that could
 * collide with a customer's own CSS.
 *
 * WHY TOKENS IN THE DOCUMENT RATHER THAN IN EACH SHADOW ROOT
 * ----------------------------------------------------------
 * Custom properties inherit *through* shadow boundaries. Defining them once on
 * `:root` means a page with twenty BMX components pays for one copy, and - far
 * more importantly - a customer can retheme the entire library by overriding a
 * dozen properties in their own stylesheet, without a build step, without
 * `::part` gymnastics, and without us shipping a theme compiler.
 *
 * HOW THEMING WORKS
 * -----------------
 * Each theme sets a small number of *seed* colours. Every state colour a
 * component needs - hover, active, soft background, focus ring, outline - is
 * derived from those seeds by `color-mix()` in the derivation block below, so
 * adding a theme is ten declarations rather than four hundred.
 *
 * `--bmx-state-mix` is what makes one derivation rule work for light and dark
 * alike: on a light theme a hover state gets darker, on a dark theme it gets
 * lighter, and the only difference between the two is whether that token is
 * black or white.
 *
 * Themes are selected by either of:
 *   <html data-theme="ocean">        - matches binarymission.co.uk's convention
 *   <div data-bmx-theme="ocean">     - scoped to a subtree
 * The scoped attribute wins, because it is more specific and because a page
 * that wants one dark panel on a light site should not have to fight for it.
 * ========================================================================== */

/* --------------------------------------------------------------------------
 * 1. Foundation - dimensions, motion, type. Theme-independent.
 * ----------------------------------------------------------------------- */

:root {
  /* Typography. The stack ends in the system UI font so a component never
   * blocks on a webfont; a customer who wants Inter sets --bmx-font-family. */
  --bmx-font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --bmx-font-family-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --bmx-font-size-xs: 0.75rem;
  --bmx-font-size-sm: 0.8125rem;
  --bmx-font-size-md: 0.875rem;
  --bmx-font-size-lg: 1rem;
  --bmx-font-size-xl: 1.125rem;

  --bmx-font-weight-normal: 400;
  --bmx-font-weight-medium: 500;
  --bmx-font-weight-semibold: 600;

  --bmx-line-height: 1.45;
  --bmx-letter-spacing: 0.01em;

  /* Spacing. A 4px base, exposed as tokens so a customer can scale the whole
   * library's density from one place. */
  --bmx-space-1: 0.25rem;
  --bmx-space-2: 0.5rem;
  --bmx-space-3: 0.75rem;
  --bmx-space-4: 1rem;
  --bmx-space-5: 1.25rem;
  --bmx-space-6: 1.5rem;

  /* Control geometry, per size step. Heights are in rem so the whole library
   * scales with the user's browser font-size setting - which is an
   * accessibility requirement, not a nicety. */
  --bmx-control-height-xs: 1.625rem;
  --bmx-control-height-sm: 1.9375rem;
  --bmx-control-height-md: 2.25rem;
  --bmx-control-height-lg: 2.625rem;
  --bmx-control-height-xl: 3rem;

  --bmx-control-padding-xs: 0.5rem;
  --bmx-control-padding-sm: 0.6875rem;
  --bmx-control-padding-md: 0.875rem;
  --bmx-control-padding-lg: 1.125rem;
  --bmx-control-padding-xl: 1.375rem;

  --bmx-icon-size-xs: 0.875rem;
  --bmx-icon-size-sm: 0.9375rem;
  --bmx-icon-size-md: 1.0625rem;
  --bmx-icon-size-lg: 1.1875rem;
  --bmx-icon-size-xl: 1.375rem;

  /* Density multiplier. `[data-bmx-density="compact"]` narrows every control
   * without changing font size, which is what data-dense enterprise screens
   * actually want. */
  --bmx-density-scale: 1;

  --bmx-radius-sm: 0.25rem;
  --bmx-radius-md: 0.4375rem;
  --bmx-radius-lg: 0.625rem;
  --bmx-radius-xl: 0.875rem;
  --bmx-radius-pill: 999px;

  --bmx-border-width: 1px;

  /* Focus. One ring, used by every component, so keyboard focus looks the same
   * everywhere - which is the entire point of a focus indicator. Width and
   * offset meet WCAG 2.2 SC 2.4.11 (Focus Appearance) at every size step. */
  --bmx-focus-ring-width: 2px;
  --bmx-focus-ring-offset: 2px;

  /* Motion. Every duration routes through these, so the reduced-motion block
   * at the bottom of this file can zero the lot in three declarations. */
  --bmx-duration-instant: 60ms;
  --bmx-duration-fast: 120ms;
  --bmx-duration-base: 190ms;
  --bmx-duration-slow: 320ms;
  --bmx-ease-standard: cubic-bezier(0.2, 0, 0.13, 1);
  --bmx-ease-emphasis: cubic-bezier(0.16, 1, 0.3, 1);
  --bmx-ease-exit: cubic-bezier(0.4, 0, 1, 1);

  /* Stacking. Overlays are the one thing a component library cannot get right
   * without the customer's help, so the numbers are tokens rather than magic. */
  --bmx-z-sticky: 100;
  --bmx-z-dropdown: 1000;
  --bmx-z-overlay: 1100;
  --bmx-z-dialog: 1200;
  --bmx-z-toast: 1300;
  --bmx-z-tooltip: 1400;
}

/* --------------------------------------------------------------------------
 * 2. Seed palettes
 *
 * `--bmx-state-mix` is the direction hover/active states move in; `--bmx-tint`
 * is its opposite. `--bmx-scheme` tells `color-scheme` what to do with native
 * scrollbars and form controls inside a themed subtree.
 * ----------------------------------------------------------------------- */

:root,
[data-theme='light'],
[data-bmx-theme='light'] {
  color-scheme: light;
  --bmx-state-mix: #000;
  --bmx-tint: #fff;

  --bmx-surface: #ffffff;
  --bmx-surface-sunken: #f4f6f9;
  --bmx-surface-raised: #ffffff;
  --bmx-surface-overlay: #ffffff;
  --bmx-text: #0f172a;
  --bmx-text-muted: #5a6a83;
  --bmx-text-subtle: #596478; /* 4.63:1; lighter greys fail AA - #8592a6 is 2.91:1 on this theme, #647083 4.05-4.25:1 on the accent-tinted dropzone ground */
  --bmx-border: #dfe4ec;
  --bmx-border-strong: #c3ccdb;

  --bmx-primary: #2563eb;
  --bmx-neutral: #64748b;
  --bmx-success: #15803d;
  --bmx-warning: #b45309;
  --bmx-danger: #dc2626;
  --bmx-info: #0369a1;
  --bmx-accent: #7c3aed;
  --bmx-accent-on-solid: #f3f1ff;
  --bmx-primary-on-solid: #edf3ff;
  --bmx-success-on-solid: #ffffff;
  --bmx-warning-on-solid: #ffffff;
  --bmx-danger-on-solid: #ffffff;
  --bmx-info-on-solid: #edf3f8;

  --bmx-shadow-color: 220 45% 20%;
}

[data-theme='dark'],
[data-bmx-theme='dark'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  /* Deliberately dark rather than mid-grey: a washed-out grey panel on a dark
   * page reads as an unstyled default, not a theme. */
  --bmx-surface: #0b1020;
  --bmx-surface-sunken: #070b17;
  --bmx-surface-raised: #131b30;
  --bmx-surface-overlay: #161f36;
  --bmx-text: #e7edf8;
  --bmx-text-muted: #9dabc4;
  --bmx-text-subtle: #7a88a2; /* no darker: #71809b is only 4.29:1 on the upload dropzone ground */
  --bmx-border: #23304d;
  --bmx-border-strong: #35446a;

  --bmx-primary: #5b8dff;
  --bmx-neutral: #8695ae;
  --bmx-success: #34d399;
  --bmx-warning: #fbbf24;
  --bmx-danger: #f87171;
  --bmx-info: #38bdf8;
  --bmx-accent: #a78bfa;
  --bmx-accent-on-solid: #15141e;
  --bmx-primary-on-solid: #11141e;
  --bmx-success-on-solid: #111818;
  --bmx-warning-on-solid: #1a1715;
  --bmx-danger-on-solid: #1a1316;
  --bmx-info-on-solid: #11161e;

  --bmx-shadow-color: 225 60% 3%;
}

[data-theme='ocean'],
[data-bmx-theme='ocean'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #061a24;
  --bmx-surface-sunken: #03121a;
  --bmx-surface-raised: #0a2734;
  --bmx-surface-overlay: #0c2e3d;
  --bmx-text: #dff3fb;
  --bmx-text-muted: #90b8c8;
  --bmx-text-subtle: #6d97a9;
  --bmx-border: #12394b;
  --bmx-border-strong: #1d5169;

  --bmx-primary: #22d3ee;
  --bmx-neutral: #7ba3b4;
  --bmx-success: #2dd4bf;
  --bmx-warning: #fbbf24;
  --bmx-danger: #fb7185;
  --bmx-info: #60a5fa;
  --bmx-accent: #818cf8;
  --bmx-accent-on-solid: #13141e;
  --bmx-primary-on-solid: #11181d;
  --bmx-success-on-solid: #11181a;
  --bmx-warning-on-solid: #1a1715;
  --bmx-danger-on-solid: #1b1317;
  --bmx-info-on-solid: #11151e;

  --bmx-shadow-color: 197 70% 3%;
}

[data-theme='sunset'],
[data-bmx-theme='sunset'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #1c0f14;
  --bmx-surface-sunken: #130a0e;
  --bmx-surface-raised: #2a161d;
  --bmx-surface-overlay: #321a22;
  --bmx-text: #ffeae2;
  --bmx-text-muted: #d3a99f;
  --bmx-text-subtle: #ac8279;
  --bmx-border: #3d2029;
  --bmx-border-strong: #572e3b;

  --bmx-primary: #fb7185;
  --bmx-neutral: #b08a86;
  --bmx-success: #4ade80;
  --bmx-warning: #fbbf24;
  --bmx-danger: #ef4444;
  --bmx-info: #f0abfc;
  --bmx-accent: #fb923c;
  --bmx-accent-on-solid: #1a1414;
  --bmx-primary-on-solid: #1b1317;
  --bmx-success-on-solid: #111817;
  --bmx-warning-on-solid: #1a1715;
  --bmx-danger-on-solid: #1a1114;
  --bmx-info-on-solid: #19151e;

  --bmx-shadow-color: 345 65% 4%;
}

[data-theme='aurora'],
[data-bmx-theme='aurora'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #06121a;
  --bmx-surface-sunken: #030c12;
  --bmx-surface-raised: #0b1f2b;
  --bmx-surface-overlay: #0e2634;
  --bmx-text: #e2fbf4;
  --bmx-text-muted: #93bdb4;
  --bmx-text-subtle: #6d968e;
  --bmx-border: #13323f;
  --bmx-border-strong: #1d4859;

  --bmx-primary: #2dd4bf;
  --bmx-neutral: #7fa6a0;
  --bmx-success: #4ade80;
  --bmx-warning: #facc15;
  --bmx-danger: #fb7185;
  --bmx-info: #38bdf8;
  --bmx-accent: #a78bfa;
  --bmx-accent-on-solid: #15141e;
  --bmx-primary-on-solid: #11181a;
  --bmx-success-on-solid: #111817;
  --bmx-warning-on-solid: #1a1815;
  --bmx-danger-on-solid: #1b1317;
  --bmx-info-on-solid: #11161e;

  --bmx-shadow-color: 190 70% 3%;
}

[data-theme='royal'],
[data-bmx-theme='royal'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #120b26;
  --bmx-surface-sunken: #0c0719;
  --bmx-surface-raised: #1c1139;
  --bmx-surface-overlay: #221645;
  --bmx-text: #ece5ff;
  --bmx-text-muted: #b3a5d6;
  --bmx-text-subtle: #8d80b1;
  --bmx-border: #2c1c56;
  --bmx-border-strong: #3f2a78;

  --bmx-primary: #a78bfa;
  --bmx-neutral: #9186b8;
  --bmx-success: #4ade80;
  --bmx-warning: #fbbf24;
  --bmx-danger: #fb7185;
  --bmx-info: #60a5fa;
  --bmx-accent: #f472b6;
  --bmx-accent-on-solid: #1a121a;
  --bmx-primary-on-solid: #15141e;
  --bmx-success-on-solid: #111817;
  --bmx-warning-on-solid: #1a1715;
  --bmx-danger-on-solid: #1b1317;
  --bmx-info-on-solid: #11151e;

  --bmx-shadow-color: 265 70% 4%;
}

[data-theme='mint'],
[data-bmx-theme='mint'] {
  color-scheme: light;
  --bmx-state-mix: #000;
  --bmx-tint: #fff;

  --bmx-surface: #ffffff;
  --bmx-surface-sunken: #eff9f4;
  --bmx-surface-raised: #ffffff;
  --bmx-surface-overlay: #ffffff;
  --bmx-text: #06281d;
  --bmx-text-muted: #4a6b5e;
  --bmx-text-subtle: #4e6c60; /* 4.63:1; lighter greys fail AA - #7a968a is 2.98:1 on this theme, #58766a 4.05-4.25:1 on the accent-tinted dropzone ground */
  --bmx-border: #cfeadf;
  --bmx-border-strong: #a6d6c3;

  --bmx-primary: #00857a;
  --bmx-neutral: #5f7d72;
  --bmx-success: #15803d;
  --bmx-warning: #b45309;
  --bmx-danger: #dc2626;
  --bmx-info: #0369a1;
  --bmx-accent: #00875e;
  --bmx-accent-on-solid: #ffffff;
  --bmx-primary-on-solid: #ffffff;
  --bmx-success-on-solid: #ffffff;
  --bmx-warning-on-solid: #ffffff;
  --bmx-danger-on-solid: #ffffff;
  --bmx-info-on-solid: #edf3f8;

  --bmx-shadow-color: 165 40% 18%;
}

[data-theme='forest'],
[data-bmx-theme='forest'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #08150f;
  --bmx-surface-sunken: #050e0a;
  --bmx-surface-raised: #0e2118;
  --bmx-surface-overlay: #12291d;
  --bmx-text: #dff5e8;
  --bmx-text-muted: #93b8a3;
  --bmx-text-subtle: #729684;
  --bmx-border: #173625;
  --bmx-border-strong: #235037;

  --bmx-primary: #34d399;
  --bmx-neutral: #7fa38d;
  --bmx-success: #4ade80;
  --bmx-warning: #facc15;
  --bmx-danger: #f87171;
  --bmx-info: #38bdf8;
  --bmx-accent: #a3e635;
  --bmx-accent-on-solid: #151915;
  --bmx-primary-on-solid: #111818;
  --bmx-success-on-solid: #111817;
  --bmx-warning-on-solid: #1a1815;
  --bmx-danger-on-solid: #1a1316;
  --bmx-info-on-solid: #11161e;

  --bmx-shadow-color: 150 60% 3%;
}

[data-theme='slate'],
[data-bmx-theme='slate'] {
  color-scheme: dark;
  --bmx-state-mix: #fff;
  --bmx-tint: #000;

  --bmx-surface: #0f1115;
  --bmx-surface-sunken: #0a0c0f;
  --bmx-surface-raised: #171a21;
  --bmx-surface-overlay: #1c2029;
  --bmx-text: #e5e7eb;
  --bmx-text-muted: #9aa3b2;
  --bmx-text-subtle: #828b99; /* no darker: #737d8c is only 4.05-4.25:1 on the accent-tinted dropzone ground */
  --bmx-border: #262b36;
  --bmx-border-strong: #39404f;

  --bmx-primary: #38bdf8;
  --bmx-neutral: #8b95a5;
  --bmx-success: #34d399;
  --bmx-warning: #fbbf24;
  --bmx-danger: #f87171;
  --bmx-info: #818cf8;
  --bmx-accent: #22d3ee;
  --bmx-accent-on-solid: #11181d;
  --bmx-primary-on-solid: #11161e;
  --bmx-success-on-solid: #111818;
  --bmx-warning-on-solid: #1a1715;
  --bmx-danger-on-solid: #1a1316;
  --bmx-info-on-solid: #13141e;

  --bmx-shadow-color: 220 30% 3%;
}

[data-theme='amber'],
[data-bmx-theme='amber'] {
  color-scheme: light;
  --bmx-state-mix: #000;
  --bmx-tint: #fff;

  --bmx-surface: #fffdf7;
  --bmx-surface-sunken: #fdf4e3;
  --bmx-surface-raised: #ffffff;
  --bmx-surface-overlay: #ffffff;
  --bmx-text: #2b1c05;
  --bmx-text-muted: #6b5424;
  --bmx-text-subtle: #7b6436; /* 4.65:1; lighter values fail AA - #967c47 is 3.65:1 on this theme, #836b3b 4.05-4.25:1 on the accent-tinted dropzone ground */
  --bmx-border: #f1e0bd;
  --bmx-border-strong: #dcc491;

  --bmx-primary: #b45309;
  --bmx-neutral: #78716c;
  --bmx-success: #15803d;
  --bmx-warning: #a16207;
  --bmx-danger: #dc2626;
  --bmx-info: #0369a1;
  --bmx-accent: #c28400;
  --bmx-accent-on-solid: #020101;
  --bmx-primary-on-solid: #ffffff;
  --bmx-success-on-solid: #ffffff;
  --bmx-warning-on-solid: #ffffff;
  --bmx-danger-on-solid: #ffffff;
  --bmx-info-on-solid: #edf3f8;

  --bmx-shadow-color: 35 50% 20%;
}

/* --------------------------------------------------------------------------
 * 3. Derivation
 *
 * Every state colour in the library is produced here, from the seeds above.
 * A new theme therefore never has to enumerate hover, active, soft, outline
 * and ring for seven tones - it sets seven seeds and inherits forty-nine
 * derived values.
 *
 * `color-mix(in oklab, ...)` rather than `in srgb`: mixing towards black in
 * sRGB desaturates as it darkens, which turns a confident primary blue into
 * a muddy navy on hover. Oklab keeps the hue and only moves the lightness,
 * which is what "the same colour, pressed" should look like.
 * ----------------------------------------------------------------------- */

:root,
[data-theme],
[data-bmx-theme] {
  /* -- Surfaces and text, as components refer to them ---------------------- */
  --bmx-surface-hover: color-mix(in oklab, var(--bmx-surface) 94%, var(--bmx-state-mix));
  --bmx-surface-active: color-mix(in oklab, var(--bmx-surface) 88%, var(--bmx-state-mix));
  --bmx-border-hover: color-mix(in oklab, var(--bmx-border) 70%, var(--bmx-state-mix));

  /* Disabled is expressed as a token rather than `opacity` on the host,
   * because opacity on a control also fades its focus ring and its text
   * shadow, and compounds when a disabled control sits inside a disabled
   * group - two 60% layers make 36%, which fails contrast outright. */
  --bmx-disabled-opacity: 0.55;
  --bmx-disabled-surface: color-mix(in oklab, var(--bmx-surface) 92%, var(--bmx-neutral));
  --bmx-disabled-text: var(--bmx-text-subtle);
  --bmx-disabled-border: var(--bmx-border);

  /* -- Elevation ----------------------------------------------------------- */
  /* Layered rather than single shadows: one blur reads as a drop shadow from
   * 1998, three stacked at increasing spread reads as depth. */
  --bmx-shadow-xs: 0 1px 2px hsl(var(--bmx-shadow-color) / 0.09);
  --bmx-shadow-sm: 0 1px 2px hsl(var(--bmx-shadow-color) / 0.08), 0 2px 6px hsl(var(--bmx-shadow-color) / 0.07);
  --bmx-shadow-md: 0 1px 2px hsl(var(--bmx-shadow-color) / 0.09), 0 4px 10px hsl(var(--bmx-shadow-color) / 0.09),
    0 10px 24px hsl(var(--bmx-shadow-color) / 0.07);
  --bmx-shadow-lg: 0 2px 4px hsl(var(--bmx-shadow-color) / 0.1), 0 8px 20px hsl(var(--bmx-shadow-color) / 0.12),
    0 24px 48px hsl(var(--bmx-shadow-color) / 0.12);
  --bmx-shadow-inset: inset 0 1px 0 hsl(0 0% 100% / 0.09);

  /* Declared here because component stylesheets read these names, and a name
     that is declared nowhere silently resolves to its fallback on every theme.
     scripts/check-tokens.mjs fails the build if a stylesheet reads a --bmx-*
     token that is not declared. */
  --bmx-line-height-tight: 1.3;
  --bmx-line-height-snug: 1.4;
  --bmx-line-height-normal: 1.5;
  --bmx-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  /* The tooltip's inverse pair. These match the tooltip's own fallback
     literals exactly, so declaring them changes nothing visible — but a
     consumer can retheme them, which is the point of reading a token. */
  --bmx-inverse-surface: #1e2532;
  --bmx-inverse-text: #f4f6fb;
  /* The primary itself, not a faded copy: the ring is drawn on the page beside
     the control, and WCAG 1.4.11 asks 3:1 against it - so every theme's primary
     must be 3:1 or more on its surface. */
  --bmx-focus-ring-color: var(--bmx-primary);

  /* -- Per-tone derivation -------------------------------------------------
   * Nine tokens per tone, and every component consumes only these names - so
   * `tone="danger"` is a one-line lookup in a component's CSS rather than a
   * branch in its TypeScript.
   *
   *   solid / on-solid   filled button, selected chip, checked switch
   *   soft / soft-text   tinted background with legible text on it
   *   outline / ring     border of an outline variant, focus halo
   * -------------------------------------------------------------------- */

  --bmx-primary-solid: var(--bmx-primary);
  --bmx-primary-solid-hover: color-mix(in oklab, var(--bmx-primary) 86%, var(--bmx-state-mix));
  --bmx-primary-solid-active: color-mix(in oklab, var(--bmx-primary) 74%, var(--bmx-state-mix));
  --bmx-primary-soft: color-mix(in oklab, var(--bmx-primary) 13%, var(--bmx-surface));
  --bmx-primary-soft-hover: color-mix(in oklab, var(--bmx-primary) 21%, var(--bmx-surface));
  --bmx-primary-soft-text: color-mix(in oklab, var(--bmx-primary) 72%, var(--bmx-text));
  --bmx-primary-outline: color-mix(in oklab, var(--bmx-primary) 46%, transparent);
  --bmx-primary-ring: color-mix(in oklab, var(--bmx-primary) 42%, transparent);

  /* Neutral is the one tone that does NOT derive its solid from its seed.
   *
   * A "solid neutral" button filled with the mid-grey seed is the washed-out
   * slab every dark theme is judged by, and it is wrong in a second way too:
   * neutral is what a *secondary* action uses, and a secondary action that
   * carries as much visual weight as the primary one beside it defeats the
   * point of having two. So solid neutral is a raised surface with a real
   * border - the shape every operating system gives its secondary button - and
   * the seed is left to drive soft, outline, ghost and the focus ring, where a
   * grey is exactly right. */
  --bmx-neutral-solid: var(--bmx-surface-raised);
  --bmx-neutral-solid-hover: var(--bmx-surface-hover);
  --bmx-neutral-solid-active: var(--bmx-surface-active);
  --bmx-neutral-on-solid: var(--bmx-text);
  --bmx-neutral-soft: color-mix(in oklab, var(--bmx-neutral) 13%, var(--bmx-surface));
  --bmx-neutral-soft-hover: color-mix(in oklab, var(--bmx-neutral) 21%, var(--bmx-surface));
  --bmx-neutral-soft-text: var(--bmx-text);
  --bmx-neutral-outline: var(--bmx-border-strong);
  --bmx-neutral-ring: color-mix(in oklab, var(--bmx-neutral) 42%, transparent);

  --bmx-success-solid: var(--bmx-success);
  --bmx-success-solid-hover: color-mix(in oklab, var(--bmx-success) 86%, var(--bmx-state-mix));
  --bmx-success-solid-active: color-mix(in oklab, var(--bmx-success) 74%, var(--bmx-state-mix));
  --bmx-success-soft: color-mix(in oklab, var(--bmx-success) 13%, var(--bmx-surface));
  --bmx-success-soft-hover: color-mix(in oklab, var(--bmx-success) 21%, var(--bmx-surface));
  --bmx-success-soft-text: color-mix(in oklab, var(--bmx-success) 72%, var(--bmx-text));
  --bmx-success-outline: color-mix(in oklab, var(--bmx-success) 46%, transparent);
  --bmx-success-ring: color-mix(in oklab, var(--bmx-success) 42%, transparent);

  --bmx-warning-solid: var(--bmx-warning);
  --bmx-warning-solid-hover: color-mix(in oklab, var(--bmx-warning) 86%, var(--bmx-state-mix));
  --bmx-warning-solid-active: color-mix(in oklab, var(--bmx-warning) 74%, var(--bmx-state-mix));
  --bmx-warning-soft: color-mix(in oklab, var(--bmx-warning) 13%, var(--bmx-surface));
  --bmx-warning-soft-hover: color-mix(in oklab, var(--bmx-warning) 21%, var(--bmx-surface));
  --bmx-warning-soft-text: color-mix(in oklab, var(--bmx-warning) 72%, var(--bmx-text));
  --bmx-warning-outline: color-mix(in oklab, var(--bmx-warning) 46%, transparent);
  --bmx-warning-ring: color-mix(in oklab, var(--bmx-warning) 42%, transparent);

  --bmx-danger-solid: var(--bmx-danger);
  --bmx-danger-solid-hover: color-mix(in oklab, var(--bmx-danger) 86%, var(--bmx-state-mix));
  --bmx-danger-solid-active: color-mix(in oklab, var(--bmx-danger) 74%, var(--bmx-state-mix));
  --bmx-danger-soft: color-mix(in oklab, var(--bmx-danger) 13%, var(--bmx-surface));
  --bmx-danger-soft-hover: color-mix(in oklab, var(--bmx-danger) 21%, var(--bmx-surface));
  --bmx-danger-soft-text: color-mix(in oklab, var(--bmx-danger) 72%, var(--bmx-text));
  --bmx-danger-outline: color-mix(in oklab, var(--bmx-danger) 46%, transparent);
  --bmx-danger-ring: color-mix(in oklab, var(--bmx-danger) 42%, transparent);

  --bmx-info-solid: var(--bmx-info);
  --bmx-info-solid-hover: color-mix(in oklab, var(--bmx-info) 86%, var(--bmx-state-mix));
  --bmx-info-solid-active: color-mix(in oklab, var(--bmx-info) 74%, var(--bmx-state-mix));
  --bmx-info-soft: color-mix(in oklab, var(--bmx-info) 13%, var(--bmx-surface));
  --bmx-info-soft-hover: color-mix(in oklab, var(--bmx-info) 21%, var(--bmx-surface));
  --bmx-info-soft-text: color-mix(in oklab, var(--bmx-info) 72%, var(--bmx-text));
  --bmx-info-outline: color-mix(in oklab, var(--bmx-info) 46%, transparent);
  --bmx-info-ring: color-mix(in oklab, var(--bmx-info) 42%, transparent);

  /* The *-on-solid tokens are NOT derived here. `tone 8% + tint` assumes every
     tone is dark on a light theme and light on a dark one; mid-tone colours are
     neither, and the formula gives 3.42:1 on mint's solid primary button and
     4.36:1 on danger. Each theme names them explicitly, above. Anything
     declared in this block wins over the theme blocks, so putting them back
     here would silently undo that. --bmx-neutral-on-solid stays derived: it is
     var(--bmx-text), which is right on every theme by construction. */
  --bmx-accent-solid: var(--bmx-accent);
  --bmx-accent-solid-hover: color-mix(in oklab, var(--bmx-accent) 86%, var(--bmx-state-mix));
  --bmx-accent-solid-active: color-mix(in oklab, var(--bmx-accent) 74%, var(--bmx-state-mix));
  /* --bmx-accent-on-solid is deliberately NOT set here. It is defined once
     per theme, above. Deriving it as `accent 8% + tint` assumes the accent is
     dark on a light theme and light on a dark one; mint's green and amber's
     yellow are neither, so the formula gives near-white on a mid-tone fill:
     3.46:1 and 2.73:1. This block sits after the theme blocks and has the same
     specificity, so anything declared here wins over them — a definition added
     here would silently override every theme's own value. */
  --bmx-accent-soft: color-mix(in oklab, var(--bmx-accent) 13%, var(--bmx-surface));
  --bmx-accent-soft-hover: color-mix(in oklab, var(--bmx-accent) 21%, var(--bmx-surface));
  /* 66%, not 72%: at 72 an amber accent prints 4.16:1 on --bmx-accent-soft,
     and this token is the text colour for every calendar entry, chip and
     soft-toned button. 66 clears 4.5 on all ten themes, worst 4.65. */
  --bmx-accent-soft-text: color-mix(in oklab, var(--bmx-accent) 66%, var(--bmx-text));
  --bmx-accent-outline: color-mix(in oklab, var(--bmx-accent) 46%, transparent);
  --bmx-accent-ring: color-mix(in oklab, var(--bmx-accent) 42%, transparent);
}

/* --------------------------------------------------------------------------
 * 4. Density
 * ----------------------------------------------------------------------- */

[data-bmx-density='compact'] {
  --bmx-density-scale: 0.875;
}

[data-bmx-density='spacious'] {
  --bmx-density-scale: 1.125;
}

/* --------------------------------------------------------------------------
 * 5. Accessibility overrides
 *
 * These three blocks are why the library can claim WCAG 2.2 AA rather than
 * merely "we used aria attributes".
 * ----------------------------------------------------------------------- */

/* SC 2.3.3 Animation from Interactions. Every component's transitions route
 * through the duration tokens, so honouring the user's system setting is three
 * declarations - and, crucially, cannot be forgotten in a new component. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --bmx-duration-instant: 0ms;
    --bmx-duration-fast: 0ms;
    --bmx-duration-base: 0ms;
    --bmx-duration-slow: 0ms;
  }
}

/* Windows High Contrast / forced-colors. The browser replaces every colour
 * with a system one, which silently destroys any UI that signals state through
 * background colour alone - a "selected" chip becomes indistinguishable from
 * an unselected one. Components therefore also carry a structural signal
 * (border, outline, or a real `:checked` control), and this block makes the
 * ring visible again. */
@media (forced-colors: active) {
  :root {
    --bmx-focus-ring-color: Highlight;
    --bmx-shadow-xs: none;
    --bmx-shadow-sm: none;
    --bmx-shadow-md: none;
    --bmx-shadow-lg: none;
    --bmx-shadow-inset: none;
  }
}

/* SC 1.4.11 Non-text Contrast, for users who have asked for more. Borders and
 * focus indicators thicken; colours are left to the theme, because a user who
 * has chosen a theme has already expressed a preference. */
@media (prefers-contrast: more) {
  :root {
    --bmx-border-width: 2px;
    --bmx-focus-ring-width: 3px;
    --bmx-disabled-opacity: 0.75;
  }
}

/* --------------------------------------------------------------------------
 * 6. Demo-edition watermark
 *
 * Styled here rather than inside a component, because it is stamped on the
 * document once by whichever BMX element connects first - not once per
 * component, which on a showcase page would mean twenty of them.
 * ----------------------------------------------------------------------- */

.bmx-demo-notice {
  position: fixed;
  inset-block-end: 12px;
  inset-inline-end: 12px;
  z-index: 2147483000;
  padding: 6px 12px;
  border: 1px solid var(--bmx-border-strong, #888);
  border-radius: var(--bmx-radius-pill, 999px);
  background: var(--bmx-surface-overlay, #fff);
  box-shadow: var(--bmx-shadow-md, 0 4px 12px rgb(0 0 0 / 0.2));
  color: var(--bmx-text-muted, #555);
  font: var(--bmx-font-weight-medium, 500) 11px/1.3 var(--bmx-font-family, system-ui);
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
}

/* On a phone the notice sits across the foot of the screen in smaller type,
 * so it covers one line of the page rather than two. */
@media (max-width: 600px) {
  .bmx-demo-notice {
    inset-block-end: 8px;
    inset-inline: 8px;
    padding: 4px 10px;
    font-size: 10px;
    text-align: center;
  }
}
