/*
 * The contract.
 *
 * groundwork's components read these custom properties and nothing else. There is
 * no palette inside a component, no hex in a stylesheet, and no assumption about
 * which design system is in the room.
 *
 * That indirection is the whole architecture. A product already in Carbon, Primer
 * or Material does not want a second token set arriving beside its own — two token
 * systems is worse than one imperfect one. So a product loads one adapter from
 * `adapters/`, which is a few dozen lines mapping these names onto that system's
 * real tokens, and groundwork's components inherit the product's palette,
 * typography, density and dark mode without knowing any of it happened.
 *
 * The values below are the system-less default, so a greenfield project works with
 * one stylesheet and no decisions. They are a generated Material 3 scheme (seed
 * #1F5673) rather than colors chosen by eye; see `tokens/md3.css`.
 *
 *
 * ─── The five tones, and the one that surprises people ───────────────────────
 *
 * The tones correspond exactly to the arms of `Outcome`, and the mapping is a
 * design decision rather than a formality:
 *
 *   done      it happened                        positive
 *   waiting   accepted, has NOT happened yet     informational, and never positive
 *   mixed     some of it happened                caution
 *   refused   the software said no               NEUTRAL AND FIRM — deliberately
 *   faulted   the software broke                 error
 *
 * **`refused` is not red, and this is the important one.** Red means the software
 * has failed. Being told "you do not have permission", "this account has not bought
 * this" or "route is closed on Sundays" is not a failure — it is the software
 * working correctly and giving an answer. Painting those in alarm red teaches
 * people that a normal answer is an emergency, and it teaches them to escalate.
 * It also flattens the exact distinction `Outcome` exists to preserve: after a
 * refusal, nothing is broken and nobody needs paging; after a fault, something is.
 *
 * `waiting` is not green for the same reason in reverse. A queued write has not
 * happened, and a green tick is the most efficient way to tell somebody it has.
 *
 *
 * ─── Contrast obligations ────────────────────────────────────────────────────
 *
 * Every pair a component actually paints is declared below and verified by
 * `scripts/check-contrast.mjs` on every adapter, in light and dark. The ramp is
 * three text steps plus one non-text step: --gw-text-faint is for rules, hatching
 * and borders only, at 3:1, and no component may set `color` to it.
 *
 * Declared against the *worst* surface a token lands on, not a flattering one.
 *
 * @contrast
 *   --gw-text on --gw-surface >= 7
 *   --gw-text on --gw-surface-sunken >= 7
 *   --gw-text-muted on --gw-surface >= 4.5
 *   --gw-text-muted on --gw-surface-sunken >= 4.5
 *   --gw-text-faint on --gw-surface >= 3
 *   --gw-border-strong on --gw-surface >= 3
 *   --gw-focus on --gw-surface >= 3
 *   --gw-tone-done-ink on --gw-tone-done-fill >= 4.5
 *   --gw-tone-waiting-ink on --gw-tone-waiting-fill >= 4.5
 *   --gw-tone-mixed-ink on --gw-tone-mixed-fill >= 4.5
 *   --gw-tone-refused-ink on --gw-tone-refused-fill >= 4.5
 *   --gw-tone-faulted-ink on --gw-tone-faulted-fill >= 4.5
 *   --gw-tone-done-edge on --gw-surface >= 3
 *   --gw-tone-waiting-edge on --gw-surface >= 3
 *   --gw-tone-mixed-edge on --gw-surface >= 3
 *   --gw-tone-refused-edge on --gw-surface >= 3
 *   --gw-tone-faulted-edge on --gw-surface >= 3
 *   --gw-action-ink on --gw-action >= 4.5
 *   --gw-action on --gw-surface >= 3
 *   --gw-action on --gw-surface-sunken >= 3
 *   --gw-action-muted-ink on --gw-action-muted >= 4.5
 *   --gw-link on --gw-surface >= 4.5
 *   --gw-link on --gw-surface-sunken >= 4.5
 *   --gw-text on --gw-field >= 4.5
 *   --gw-text on --gw-hover >= 4.5
 *   --gw-text on --gw-active >= 4.5
 *   --gw-text on --gw-surface-accent >= 4.5
 *   --gw-shell-ink on --gw-shell >= 4.5
 *   --gw-shell-ink-muted on --gw-shell >= 4.5
 *   --gw-shell-accent on --gw-shell >= 4.5
 *   --gw-shell-ink on --gw-shell-hover >= 4.5
 *
 *
 * ─── The product's own chrome ────────────────────────────────────────────────
 *
 * The first vendored app proved that the contract above was not enough to keep a
 * product honest. Its screens spoke `--gw-*`, but its shell — the header bar, the
 * links, the primary button, the field fills, the table headers, the hover
 * layers — had nowhere to resolve, so it reached past the contract into the
 * design system's own tokens, eighteen times. The adapter swap then moved the
 * components and left the shell behind.
 *
 * These are not component tokens: no groundwork component paints a header bar.
 * They exist because every product has one, and the product's own CSS deserves
 * the same indirection the components get. The groups:
 *
 *   action / action-ink            THE primary action. One per view.
 *   action-muted / action-muted-ink  the default button's filled treatment,
 *                                  where the system has one (Material's tonal,
 *                                  Carbon's secondary)
 *   link                           standalone link ink
 *   field                          input fill — most systems fill fields with
 *                                  something that is not the page surface
 *   hover / active                 resting interaction layers for rows,
 *                                  disclosure summaries and quiet buttons
 *   surface-accent                 an emphasized surface: table header rows
 *   shell / shell-ink / shell-ink-muted / shell-hover / shell-accent
 *                                  the product chrome bar. Some systems keep it
 *                                  dark in both schemes (Carbon's g100 zone),
 *                                  some follow the scheme; the adapter decides.
 *
 * Buttons carry NO hover or pressed tokens. Components paint those as state
 * layers — currentColor at 8% and 10% over the resting fill, Material's own
 * construction, and a faithful approximation of every other system's hover
 * ramp — so a fill knows its states without twenty-two more tokens.
 *
 * What no token can carry: composition. An adapter swaps what things look like,
 * never what a page is made of — a top bar does not become a nav rail because
 * the palette changed. Keep structure in the product, expression in the
 * contract, and the swap stays an afternoon.
 */
/*
 * The default theme lives in a cascade layer so that an ADAPTER — plain,
 * unlayered CSS loaded after this file — beats it in every mode without
 * matching its selectors. Before the layer, the dark block below
 * (`:root:not([data-theme="light"])`, specificity 0-2-0) outranked every
 * adapter's `:root` mapping (0-1-0) the moment the OS preference was dark, so
 * a product themed onto Carbon or Material got groundwork's own dark palette
 * instead of its design system's. Found by the first vendored app that went
 * dark; true of every adapter. Unlayered author styles win over layered ones
 * regardless of specificity, which is exactly what the contract wanted: the
 * defaults apply when nothing else speaks, and never argue with a system that
 * does.
 */
@layer groundwork-default {
  :root {
    color-scheme: light dark;

    /* Surfaces and ink ------------------------------------------------------- */
    --gw-surface: #f6fafe;
    /* One step down, for the inside of a table or a well. Tables live here, which
       is why --gw-text-muted declares against it too. */
    --gw-surface-sunken: #ebeef3;
    --gw-surface-raised: #ffffff;

    --gw-text: #181c1f;
    /* Secondary text: column headers, captions, timestamps. Still text, still 4.5. */
    --gw-text-muted: #41484d;
    /* NON-TEXT ONLY. Rules, hatching, disabled marks. Never a `color:`. */
    --gw-text-faint: #71787e;

    --gw-border: #c1c7ce;
    --gw-border-strong: #71787e;
    --gw-focus: #206487;

    /* Tones ------------------------------------------------------------------ */
    /* fill: the block behind the message. ink: the words on it. edge: the rule or
       stripe that identifies it, which also has to work against the page. */
    --gw-tone-done-fill: #b9f0b8;
    --gw-tone-done-ink: #1f5027;
    --gw-tone-done-edge: #37693c;

    --gw-tone-waiting-fill: #c6e7ff;
    --gw-tone-waiting-ink: #004c6b;
    --gw-tone-waiting-edge: #206487;

    --gw-tone-mixed-fill: #ffdea2;
    --gw-tone-mixed-ink: #5c4200;
    --gw-tone-mixed-edge: #79590c;

    /* Neutral on purpose. See the note above. */
    --gw-tone-refused-fill: #e5e8ed;
    --gw-tone-refused-ink: #181c1f;
    --gw-tone-refused-edge: #71787e;

    --gw-tone-faulted-fill: #ffdad6;
    --gw-tone-faulted-ink: #93000a;
    --gw-tone-faulted-edge: #ba1a1a;

    /* The product's own chrome (see the note above) ---------------------------- */
    --gw-action: #206487;
    --gw-action-ink: #ffffff;
    --gw-action-muted: #d2e5f4;
    --gw-action-muted-ink: #374955;
    --gw-link: #206487;
    --gw-field: #dfe3e7;
    --gw-hover: #e5e8ed;
    --gw-active: #dfe3e7;
    --gw-surface-accent: #e5e8ed;
    /* The default shell is a dark bar in both schemes — the common product-chrome
       idiom, and the one that never argues with content. */
    --gw-shell: #2c3135;
    --gw-shell-ink: #eef1f6;
    --gw-shell-ink-muted: #c1c7ce;
    --gw-shell-hover: #41484d;
    --gw-shell-accent: #92cef5;

    /* The scrim behind a modal layer. Declared once rather than per scheme: its
       job is to say "the page is not available" in both, and a dark theme that
       lightens its scrim says the opposite. Deliberately not transparent enough to
       read the page through — a scrim you can read through invites the reader to
       try, and everything behind it is inert. */
    --gw-scrim: rgb(16 20 24 / 55%);

    /* Space ------------------------------------------------------------------ */
    /* A 4px grid. Adapters remap these to their own scale — Carbon's 8px mini-unit,
       Primer's size scale — so density follows the host product. */
    --gw-space-1: 4px;
    --gw-space-2: 8px;
    --gw-space-3: 12px;
    --gw-space-4: 16px;
    --gw-space-5: 24px;
    --gw-space-6: 32px;

    /* Shape ------------------------------------------------------------------ */
    --gw-radius-1: 4px;
    --gw-radius-2: 12px;

    /* Type ------------------------------------------------------------------- */
    --gw-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --gw-font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
    /* Four steps, and an 11px floor. Nine ad-hoc sizes per stylesheet is how a
       ramp stops meaning anything. */
    --gw-size-micro: 11px;
    --gw-size-small: 12px;
    --gw-size-datum: 13px;
    --gw-size-body: 14px;
    --gw-size-title: 16px;
    --gw-line: 1.5;
    --gw-weight-strong: 600;

    /* Controls --------------------------------------------------------------- */
    --gw-control-height: 40px;
    /* The hit area, which is padded out rather than drawn. WCAG 2.5.8 floors this
       at 24px; 44 is Apple's number and the one worth meeting. */
    --gw-target-min: 44px;

    /* Motion ------------------------------------------------------------------
       Three steps, because one duration cannot serve both a hover and a panel:
       fast is the micro tier (hover, state layers, toggles — anything a person
       triggers twenty times a session), the default is small expansion and
       short movement, slow is large expansion. Each adapter maps them onto its
       system's own published scale; a system that rejects motion (GOV.UK) maps
       all three to zero and everything still works. */
    --gw-duration-fast: 100ms;
    --gw-duration: 150ms;
    --gw-duration-slow: 300ms;
    --gw-ease: cubic-bezier(0.2, 0, 0, 1);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --gw-surface: #0f1417;
      --gw-surface-sunken: #1c2024;
      --gw-surface-raised: #262b2e;

      --gw-text: #dfe3e7;
      --gw-text-muted: #c1c7ce;
      --gw-text-faint: #8b9198;

      --gw-border: #41484d;
      --gw-border-strong: #8b9198;
      --gw-focus: #92cef5;

      --gw-tone-done-fill: #1f5027;
      --gw-tone-done-ink: #b9f0b8;
      --gw-tone-done-edge: #9dd49d;

      --gw-tone-waiting-fill: #004c6b;
      --gw-tone-waiting-ink: #c6e7ff;
      --gw-tone-waiting-edge: #92cef5;

      --gw-tone-mixed-fill: #5c4200;
      --gw-tone-mixed-ink: #ffdea2;
      --gw-tone-mixed-edge: #ebc16c;

      --gw-tone-refused-fill: #262b2e;
      --gw-tone-refused-ink: #dfe3e7;
      --gw-tone-refused-edge: #8b9198;

      --gw-tone-faulted-fill: #93000a;
      --gw-tone-faulted-ink: #ffdad6;
      --gw-tone-faulted-edge: #ffb4ab;

      --gw-action: #92cef5;
      --gw-action-ink: #00344b;
      --gw-action-muted: #374955;
      --gw-action-muted-ink: #d2e5f4;
      --gw-link: #92cef5;
      --gw-field: #313539;
      --gw-hover: #262b2e;
      --gw-active: #313539;
      --gw-surface-accent: #262b2e;
      --gw-shell: #262b2e;
      --gw-shell-ink: #dfe3e7;
      --gw-shell-ink-muted: #c1c7ce;
      --gw-shell-hover: #41484d;
      --gw-shell-accent: #92cef5;
    }
  }

  /* An explicit choice wins in both directions, and is applied before first paint
     by whatever sets data-theme. Defining dark only inside the media query is what
     makes a theme toggle flash. */
  :root[data-theme="dark"] {
    --gw-surface: #0f1417;
    --gw-surface-sunken: #1c2024;
    --gw-surface-raised: #262b2e;

    --gw-text: #dfe3e7;
    --gw-text-muted: #c1c7ce;
    --gw-text-faint: #8b9198;

    --gw-border: #41484d;
    --gw-border-strong: #8b9198;
    --gw-focus: #92cef5;

    --gw-tone-done-fill: #1f5027;
    --gw-tone-done-ink: #b9f0b8;
    --gw-tone-done-edge: #9dd49d;

    --gw-tone-waiting-fill: #004c6b;
    --gw-tone-waiting-ink: #c6e7ff;
    --gw-tone-waiting-edge: #92cef5;

    --gw-tone-mixed-fill: #5c4200;
    --gw-tone-mixed-ink: #ffdea2;
    --gw-tone-mixed-edge: #ebc16c;

    --gw-tone-refused-fill: #262b2e;
    --gw-tone-refused-ink: #dfe3e7;
    --gw-tone-refused-edge: #8b9198;

    --gw-tone-faulted-fill: #93000a;
    --gw-tone-faulted-ink: #ffdad6;
    --gw-tone-faulted-edge: #ffb4ab;

    --gw-action: #92cef5;
    --gw-action-ink: #00344b;
    --gw-action-muted: #374955;
    --gw-action-muted-ink: #d2e5f4;
    --gw-link: #92cef5;
    --gw-field: #313539;
    --gw-hover: #262b2e;
    --gw-active: #313539;
    --gw-surface-accent: #262b2e;
    --gw-shell: #262b2e;
    --gw-shell-ink: #dfe3e7;
    --gw-shell-ink-muted: #c1c7ce;
    --gw-shell-hover: #41484d;
    --gw-shell-accent: #92cef5;
  }
}
