/*
 * GENESIS design tokens — the one source for desktop, dw-web and frontend.
 *
 * Every name carries the `--ui-` prefix so an app can import this file next to
 * its own tokens without either set overwriting the other: an app adopts the
 * language by pointing its own names at these (`--bg: var(--ui-bg)`), one rule
 * at a time, instead of in one big-bang rename.
 *
 * Selectors are zero-specificity (`:where`) on purpose, and theme-scoped: light
 * on the root and on any [data-theme='light'] / .light subtree, dark on any
 * [data-theme='dark'] / .dark subtree. An app that themes a
 * scoped root (dw-web's `.app-root.web[data-theme]`) or writes inline values
 * on `:root` still wins, and the dark set applies to whatever element carries
 * `data-theme="dark"` or `.dark`. Custom properties inherit their COMPUTED
 * value, so an app that aliases these (`--bg: var(--ui-bg)`) must declare the
 * alias on its theme selectors too, not on :root alone, or a dark subtree keeps
 * the light alias (the desktop's globals.css does). Floating layers portal to
 * <body>; the package's Layer re-declares the opener's theme for them.
 *
 * Colour values are the ones measured for contrast in
 * docs/haind60/desktop_chat_first_plan_311026.md (phase W table, D8); tokens.test.ts re-checks every
 * text/surface pair in both themes, so a value edited here cannot quietly drop
 * below 4.5:1.
 *
 * Meaning of colour, the whole palette in five sentences:
 *   1. Ink and greys are the page.
 *   2. Accent (orange) is "your move": primary action, focus, a thing waiting on you.
 *   3. Run (blue) is work happening now — a dot and its words, never a filled card.
 *   4. Ok green, warn amber, err red — for state only.
 *   5. Charts keep their own categorical series; their grounds stay neutral.
 */

/* Light is the default on the root AND an explicit theme a subtree can ask
   for, so a light gallery tile can sit inside a dark page (and vice versa). */
:where(:root, [data-theme='light'], .light) {
  /* surfaces — the ground (frame: rail, title bar, sidebars) sits one step
     below the sheet it holds (D8, the balanced level) */
  --ui-bg: #f3f2f0;
  --ui-surface: #ffffff;
  --ui-sunken: #f5f5f4;
  --ui-hover: #f0efee;
  --ui-selected: #e7e5e4;

  /* lines */
  --ui-line: #e7e5e4;
  --ui-rule: #f0efee;
  --ui-control-edge: #d6d3d1;
  /* A field's edge: 48% of the ink, the share that clears WCAG 2.2 SC 1.4.11
     (3:1) on the page and on a card in both themes — the control edge above
     measured 1.12-1.33:1 on inputs (owner 11/11: the UI reads pale). */
  --ui-field-edge: color-mix(in oklab, var(--ui-text) 48%, transparent);
  --ui-field-edge-hover: color-mix(in oklab, var(--ui-text) 62%, transparent);

  /* text */
  --ui-text: #1c1917;
  --ui-text-soft: #57534e;
  /* darker than the dw-web plan's #78716c, which fell to 3.82:1 on --ui-selected */
  --ui-text-muted: #6b645f;

  /* accent — "your move" */
  --ui-accent: #c2410c;
  --ui-on-accent: #ffffff;
  --ui-accent-tint: #fff7ed;
  /* the accent as text on its own tint: an avatar's initials, a "waits on you" label */
  --ui-accent-ink: #9a3412;
  --ui-focus-ring: var(--ui-accent);

  /* the brand orange itself: logos only, too weak for a label (2.95:1 on white) */
  --ui-brand: #f36f21;

  /* state — text/dot colour and the tint behind a pill or banner */
  --ui-ok: #15803d;
  --ui-ok-bg: #f0fdf4;
  --ui-warn: #b45309;
  --ui-warn-bg: #fffbeb;
  --ui-err: #b91c1c;
  --ui-err-bg: #fef2f2;
  --ui-run: #1d4ed8;
  --ui-run-bg: #eff6ff;

  /* identity (D8) — an agent, a swarm, a DW or a person keeps a hue of its own
     on its icon, drawing or avatar ink, never on the surface behind it. Eight
     hues, so a list of eight never repeats one; each reads at 4.5:1 or better
     on the surface and the sunken tile in both themes (tokens.test.ts). */
  --ui-hue-blue: #1f5fbf;
  --ui-hue-peach: #a8461a;
  --ui-hue-lilac: #5b3fc0;
  --ui-hue-mint: #0f7a5a;
  --ui-hue-rose: #b3262f;
  --ui-hue-sky: #0b6f8f;
  --ui-hue-teal: #0f6e6a;
  --ui-hue-ochre: #7f6200;

  /* shape — four radii, nothing else: cards, controls (a button, an input:
     design-taste-frontend app-screens §8.3, 6-8px in the tight styles), status
     pills, avatars and dots */
  --ui-radius: 12px;
  --ui-radius-control: 8px;
  --ui-radius-pill: 999px;
  --ui-radius-round: 50%;

  /* type — one UI sans across the three apps; the display face is for web page titles only */
  --ui-font-sans: 'IBM Plex Sans', -apple-system, system-ui, 'Segoe UI', sans-serif;
  --ui-font-display: 'Bricolage Grotesque', var(--ui-font-sans);
  --ui-font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ui-text-xs: 12px;
  --ui-text-sm: 14px;
  --ui-text-md: 16px;
  --ui-text-lg: 22px;
  --ui-weight-regular: 400;
  --ui-weight-medium: 500;
  --ui-weight-strong: 600;

  /* space — one 4px ladder; there is no density setting (D12) */
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-space-5: 20px;
  --ui-space-6: 24px;
  --ui-space-8: 32px;
  --ui-space-10: 40px;
  --ui-page-gap: var(--ui-space-3);

  /* controls — one height ladder for buttons, inputs, selects, segmented tabs */
  --ui-control-sm: 28px;
  --ui-control-md: 32px;
  --ui-control-lg: 36px;

  /* layout */
  --ui-sidebar-w: 240px;
  /* the desktop's icon rail and conversation rail (the mockup's .rail, .conv) */
  --ui-rail-w: 60px;
  --ui-conv-w: 272px;
  --ui-header-h: 56px;

  /* depth — flat by default; one shadow for things that float (menu, dialog, toast, drawer) */
  --ui-float-shadow: 0 12px 32px rgb(28 25 23 / 0.12), 0 2px 6px rgb(28 25 23 / 0.06);
  --ui-scrim: rgb(28 25 23 / 0.32);

  /* motion — colour changes on hover/press; only waiting and running things move */
  --ui-duration-fast: 120ms;
  --ui-duration-base: 200ms;
  --ui-ease: cubic-bezier(0.2, 0, 0, 1);
  /* entrances and morphs under 600ms: motion.md's quint-out, which starts moving the instant the eye arrives */
  --ui-ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  /* native controls and scrollbars follow a light subtree inside a dark page */
  color-scheme: light;
}

:where([data-theme='dark'], .dark) {
  --ui-bg: #0b0b0d;
  --ui-surface: #17171a;
  --ui-sunken: #1e1e22;
  --ui-hover: #232328;
  --ui-selected: #2a2a30;

  --ui-line: #26262b;
  --ui-rule: #1f1f23;
  --ui-control-edge: #3a3a41;
  /* A field's edge: 48% of the ink, the share that clears WCAG 2.2 SC 1.4.11
     (3:1) on the page and on a card in both themes — the control edge above
     measured 1.12-1.33:1 on inputs (owner 11/11: the UI reads pale). */
  --ui-field-edge: color-mix(in oklab, var(--ui-text) 48%, transparent);
  --ui-field-edge-hover: color-mix(in oklab, var(--ui-text) 62%, transparent);

  --ui-text: #ededef;
  --ui-text-soft: #b4b4bb;
  --ui-text-muted: #9a9aa3;

  --ui-accent: #f0782a;
  --ui-on-accent: #0e0e10;
  --ui-accent-tint: #2a1c12;
  --ui-accent-ink: #fdba74;
  /* Redeclared, not inherited: a var() resolves where it is declared, so a
     dark subtree under a light root would otherwise keep the light ring. */
  --ui-focus-ring: var(--ui-accent);

  --ui-ok: #4ade80;
  --ui-ok-bg: #0f2418;
  --ui-warn: #fbbf24;
  --ui-warn-bg: #2a2110;
  --ui-err: #f87171;
  --ui-err-bg: #2c1414;
  --ui-run: #60a5fa;
  --ui-run-bg: #121f36;

  --ui-hue-blue: #8bb8ff;
  --ui-hue-peach: #ffaa7f;
  --ui-hue-lilac: #bba9ff;
  --ui-hue-mint: #62d8b0;
  --ui-hue-rose: #ff8d96;
  --ui-hue-sky: #6fd0f0;
  --ui-hue-teal: #5fd0c8;
  --ui-hue-ochre: #f0cc5a;

  --ui-float-shadow: 0 12px 32px rgb(0 0 0 / 0.5), 0 2px 6px rgb(0 0 0 / 0.3);
  --ui-scrim: rgb(0 0 0 / 0.55);

  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  :where(:root) {
    --ui-duration-fast: 0ms;
    --ui-duration-base: 0ms;
  }
}
