/* =========================================================
   Portal 2.0 · tokens (design system v2)
   THE ONLY v2 FILE THAT MAY HOLD A COLOUR VALUE. Every other v2
   stylesheet and component reads these variables. The guard
   scripts/check-v2-static.py fails any hex, rgb, rgba or
   color-mix anywhere else in the v2 scope.

   Authority: docs/authorities/portal-2-design-system-v2.md,
   "tokens". Values as the canvas's css/d2.css (28 Sept 2026),
   r2.css winning where they differ.

   SCOPE. Everything here hangs off :root[data-v2], which only a
   portal.v2 holder's page ever carries. Without the attribute this
   file defines nothing, so today's portal renders unchanged.

   NAMES. Semantic tokens carry a --z- prefix because the legacy
   stack already uses the bare names (--accent, --ok, --warn,
   --text …) with other values, and a v2 holder still loads legacy
   pages under the new shell until each page moves.

   THEMES. data-theme on the root: light, dark, or absent / system
   (follow prefers-color-scheme). A nested [data-theme] re-themes
   its subtree, which is how the gallery shows both side by side.
   Dark is designed, not inverted: black grounds, warm paper text,
   orange stays orange.
   ========================================================= */

:root[data-v2] {
  /* ── brand values, unchanged from colors_and_type.css ── */
  --z-orange: #FF5800;
  --z-ink: #000000;
  --z-warm-grey: #DBC8B6;
  --z-paper: #F4EEE8;                /* warm grey at 25% */
  --z-white: #FFFFFF;                /* the brand's white: the reading register's statement on orange, in either theme */
  /* Zeal purple, the brand's second colour, for the reading register's
     purple panels (culture's strategic imagination, brand's positioning).
     Like orange, it stays itself in both themes, so its text tokens are
     fixed too: white, a softer white, a rule, and the orange that reads on
     it at AA for small text (#FF5800 is 4.4:1 on purple; this is 5.6:1). */
  --z-purple: #470A68;
  --z-on-purple-2: rgba(255, 255, 255, 0.84);
  --z-purple-line: rgba(255, 255, 255, 0.24);
  --z-purple-accent: #FF8200;
  /* a hairline on the orange panels, which stay orange in both themes */
  --z-accent-line: rgba(255, 255, 255, 0.28);
  /* small orange text on a ground that is light in both themes (brand's
     white and warm swatches): the light theme's accent text, fixed */
  --z-orange-text: #C93200;
  /* the playbooks' ramps (PB-01's lifecycle, PB-04's day, the flow's
     automated step): today's orange tints, which read on both grounds */
  --z-ramp-1: rgba(255, 125, 51, 0.08);
  --z-ramp-2: rgba(255, 125, 51, 0.14);
  --z-ramp-3: rgba(255, 125, 51, 0.22);
  --z-orange-press: #F03C00;         /* the primary button's pressed and hover fill */

  /* css/system owns its own base values now, instead of borrowing
     them from legacy portal.css */
  --warm-grey: var(--z-warm-grey);

  /* ── type: Aktiv Grotesk (Typekit yag7uwn), each with its sized fallback ── */
  --z-f-ex: "aktiv-grotesk-extended", "aktiv-grotesk-extended-fallback", "aktiv-grotesk", "aktiv-grotesk-fallback", Helvetica, Arial, sans-serif;
  --z-f-std: "aktiv-grotesk", "aktiv-grotesk-fallback", Helvetica, Arial, sans-serif;
  --z-f-cd: "aktiv-grotesk-condensed", "aktiv-grotesk-condensed-fallback", "aktiv-grotesk", "aktiv-grotesk-fallback", Helvetica, Arial, sans-serif;
  --z-f-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* the working scale; 12px is the floor everywhere */
  --z-t-hero: 44px;
  --z-t-h1: 30px;
  --z-t-fig: 24px;
  --z-t-h2: 18px;
  --z-t-h3: 15px;
  --z-t-body: 14px;
  --z-t-small: 13px;
  --z-t-label: 12px;
  /* display sizes: the reading register and the home greeting only */
  --z-t-display: clamp(56px, 9vw, 160px);

  /* ── space, shape, density ── */
  --z-s-1: 4px;
  --z-s-2: 8px;
  --z-s-3: 12px;
  --z-s-4: 16px;
  --z-s-5: 20px;
  --z-s-6: 28px;
  --z-s-7: 40px;
  --z-r: 4px;
  --z-row: 40px;
  --z-control: 34px;
  --z-target: 44px;                  /* the touch minimum */

  /* ── widths ── */
  --z-sidebar-w: 224px;
  --z-drawer-w: 300px;
  --z-related-w: 320px;
  --z-related-min-main: 880px;       /* the rail drops below the main column under this */
  --z-ribbon-h: 52px;

  /* ── motion: 120ms small, 200ms panels, both ease-out ── */
  --z-dur-small: 120ms;
  --z-dur-panel: 200ms;
  --z-ease: cubic-bezier(0.2, 0, 0, 1);

  /* ── the twelve names legacy CSS reads and nothing ever defined.
     Resolved here, inside v2 only. Legacy is left alone; it is
     deleted after the reveal. ── */
  --red: var(--z-bad);
  --mono: var(--z-f-mono);
  --ink-1: var(--z-text);
  --ribbon-h: var(--z-ribbon-h);
  --accent-strong: var(--z-accent-text);
  --ease: var(--z-ease);
  --fast: var(--z-dur-small);
  --ink-6: var(--z-text-3);
  --rule-1: var(--z-line);
  --track-label: 0.03em;
  --warm-2: var(--z-bg-hover);
  --warm-25: var(--z-paper);
}

/* ── light: the default ── */
:root[data-v2],
:root[data-v2] [data-theme="light"] {
  color-scheme: light;
  --z-bg: #FFFFFF;
  --z-bg-raised: #FFFFFF;
  --z-bg-sunk: #FAFAF8;
  --z-bg-rail: #F4EEE8;
  --z-bg-hover: #F2EDE2;
  --z-bg-select: #FFD6BF;
  --z-line: rgba(0, 0, 0, 0.09);
  --z-line-2: rgba(0, 0, 0, 0.16);
  --z-text: #000000;
  --z-text-2: rgba(0, 0, 0, 0.72);
  --z-text-3: rgba(0, 0, 0, 0.55);
  --z-accent: #FF5800;
  --z-accent-text: #C93200;
  --z-on-accent: #000000;
  --z-ok: #1F7A4A;
  --z-ok-soft: #E8F3EC;
  --z-warn: #7F5409;
  --z-warn-soft: #FBF1DC;
  --z-bad: #C62828;
  --z-bad-soft: #FDECEC;
  --z-info: #2C5A8F;
  --z-info-soft: #EAF0F7;
  --z-hatch: rgba(0, 0, 0, 0.14);
  /* The focus ring is ink, not orange. Orange on the warm rail is
     2.7:1 and on the hover ground 2.7:1, under the 3:1 non-text
     floor the authority makes a red; ink is 3:1 against anything a
     control can sit on here. */
  --z-focus: #000000;
  --z-shadow: 0 10px 32px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.06);
  --z-scrim: rgba(0, 0, 0, 0.45);
  /* the reading register (the OS and playbook pages): its warm panel, a
     strong rule, and the inverse panel (the black lens, the note), which is
     ink in light and warm paper in dark, because dark is designed, not
     inverted. Small orange text on it is the brand orange in light (6.6:1
     on black) and the accent's press in dark (5.3:1 on paper). */
  --z-panel: #F4EEE8;
  --z-line-strong: #000000;
  --z-inv: #000000;
  --z-on-inv: #FFFFFF;
  --z-on-inv-2: rgba(255, 255, 255, 0.82);
  --z-on-inv-3: rgba(255, 255, 255, 0.64);
  --z-inv-accent: #FF5800;
  --z-inv-line: rgba(255, 255, 255, 0.22);
}

/* ── the coverage language (portal-decisions, 11 July 2026), unchanged:
   solid is booked, hatched is pencilled, hatched orange is a clash,
   red is open. These two are the ONLY gradients v2 allows, and they
   live here so the gradient guard can name them. Declared on every
   theme scope, because a custom property that reads another is
   resolved where it is declared: on the root alone, a nested dark
   panel would inherit the light hatch. ── */
:root[data-v2],
:root[data-v2] [data-theme] {
  --z-cov-pencil: repeating-linear-gradient(135deg, transparent 0 5px, var(--z-hatch) 5px 7px);
  --z-cov-clash: repeating-linear-gradient(135deg, transparent 0 5px, var(--z-accent) 5px 7px);
}

/* ── dark: designed, not inverted ── */
:root[data-v2][data-theme="dark"],
:root[data-v2] [data-theme="dark"] {
  color-scheme: dark;
  --z-bg: #0F0E0E;
  --z-bg-raised: #181716;
  --z-bg-sunk: #0A0A0A;
  --z-bg-rail: #000000;
  --z-bg-hover: #211F1E;
  --z-bg-select: rgba(255, 88, 0, 0.20);
  --z-line: rgba(244, 238, 232, 0.10);
  --z-line-2: rgba(244, 238, 232, 0.18);
  --z-text: #F4EEE8;
  --z-text-2: rgba(244, 238, 232, 0.74);
  --z-text-3: rgba(244, 238, 232, 0.58);
  --z-accent: #FF5800;
  --z-accent-text: #FF8200;
  --z-on-accent: #000000;
  --z-ok: #4FB37F;
  --z-ok-soft: rgba(79, 179, 127, 0.15);
  --z-warn: #E0A33A;
  --z-warn-soft: rgba(224, 163, 58, 0.15);
  --z-bad: #F0625D;
  --z-bad-soft: rgba(240, 98, 93, 0.15);
  --z-info: #6F9BD1;
  --z-info-soft: rgba(111, 155, 209, 0.15);
  --z-hatch: rgba(244, 238, 232, 0.18);
  --z-focus: #F4EEE8;
  --z-shadow: 0 14px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(244, 238, 232, 0.08);
  --z-scrim: rgba(0, 0, 0, 0.6);
  --z-panel: #181716;
  --z-line-strong: rgba(244, 238, 232, 0.62);
  --z-inv: #F4EEE8;
  --z-on-inv: #000000;
  --z-on-inv-2: rgba(0, 0, 0, 0.76);
  --z-on-inv-3: rgba(0, 0, 0, 0.66);
  --z-inv-accent: #C93200;
  --z-inv-line: rgba(0, 0, 0, 0.18);
}

/* ── system: no data-theme, or data-theme="system", follows the OS ── */
@media (prefers-color-scheme: dark) {
  :root[data-v2]:not([data-theme]),
  :root[data-v2][data-theme="system"] {
    color-scheme: dark;
    --z-bg: #0F0E0E;
    --z-bg-raised: #181716;
    --z-bg-sunk: #0A0A0A;
    --z-bg-rail: #000000;
    --z-bg-hover: #211F1E;
    --z-bg-select: rgba(255, 88, 0, 0.20);
    --z-line: rgba(244, 238, 232, 0.10);
    --z-line-2: rgba(244, 238, 232, 0.18);
    --z-text: #F4EEE8;
    --z-text-2: rgba(244, 238, 232, 0.74);
    --z-text-3: rgba(244, 238, 232, 0.58);
    --z-accent: #FF5800;
    --z-accent-text: #FF8200;
    --z-on-accent: #000000;
    --z-ok: #4FB37F;
    --z-ok-soft: rgba(79, 179, 127, 0.15);
    --z-warn: #E0A33A;
    --z-warn-soft: rgba(224, 163, 58, 0.15);
    --z-bad: #F0625D;
    --z-bad-soft: rgba(240, 98, 93, 0.15);
    --z-info: #6F9BD1;
    --z-info-soft: rgba(111, 155, 209, 0.15);
    --z-hatch: rgba(244, 238, 232, 0.18);
    --z-focus: #F4EEE8;
    --z-shadow: 0 14px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(244, 238, 232, 0.08);
    --z-scrim: rgba(0, 0, 0, 0.6);
    --z-panel: #181716;
    --z-line-strong: rgba(244, 238, 232, 0.62);
    --z-inv: #F4EEE8;
    --z-on-inv: #000000;
    --z-on-inv-2: rgba(0, 0, 0, 0.76);
    --z-on-inv-3: rgba(0, 0, 0, 0.66);
    --z-inv-accent: #C93200;
    --z-inv-line: rgba(0, 0, 0, 0.18);
  }
}

/* ── touch density: tablet and phone widths ── */
@media (max-width: 1023px) {
  :root[data-v2] {
    --z-row: 56px;
    --z-control: 48px;
    --z-ribbon-h: 60px;
  }
}
