/* ==========================================================================
   tokens.css — the design system's values. Nothing here draws anything.

   Direction: the original CVI window's powder-blue header bands and light-blue
   group wells, rebuilt as an instrument panel for a lab bench. Quiet
   everywhere except two places: the readouts (big condensed figures in a
   fixed inset) and the byte anatomy of each frame in the protocol box.

   Theming contract: the complete light palette lives on bare :root. The dark
   palette appears twice — once behind prefers-color-scheme for the system
   default (guarded by :not([data-theme='light']) so an explicit light choice
   wins), once behind [data-theme='dark'] so an explicit dark choice wins on a
   light OS. No colour is ever defined only inside a media query.

   Every text/background pair used by the components was checked against WCAG
   AA; the table and the two hexes that had to move are in docs/DESIGN.md
   (repository root, not deployed).
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- type ------------------------------------------------------------- */
  /* Barlow: a grotesk drawn from highway and rail signage — plain, slightly
     technical, very legible at small sizes. The semi-condensed cut carries
     titles and readouts: figures fit a fixed-width readout without shrinking.
     Bahnschrift is the closest face Windows ships (the original's home). */
  --font-ui: 'Barlow', 'Bahnschrift', 'Segoe UI', system-ui, -apple-system, Roboto,
    'Helvetica Neue', Arial, sans-serif;
  --font-title: 'Barlow Semi Condensed', 'Bahnschrift SemiCondensed', 'Bahnschrift',
    'Arial Narrow', 'Segoe UI', system-ui, sans-serif;
  /* JetBrains Mono: hex bytes only. */
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo,
    Consolas, 'Liberation Mono', monospace;

  /* Scale ≈ 1.2 from a 15px body. */
  --text-xs: 0.75rem;      /* 12px  byte key, chart axes */
  --text-sm: 0.8125rem;    /* 13px  hints, units in tight spots, chips */
  --text-md: 0.9375rem;    /* 15px  body, buttons, inputs */
  --text-lg: 1.125rem;     /* 18px  box and card titles */
  --text-xl: 1.375rem;     /* 22px  port identity */
  --text-2xl: 1.75rem;     /* 28px  readouts, the address figure */
  --text-mono: 0.875rem;   /* 14px  hex bytes */

  --leading-tight: 1.15;
  --leading-body: 1.45;
  --measure: 72ch;         /* prose line length (≤ 80ch) */

  /* --- spacing: 4px grid ---------------------------------------------------- */
  --space-1: 0.25rem;  /*  4 */
  --space-2: 0.5rem;   /*  8 */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.25rem;  /* 20 */
  --space-6: 1.5rem;   /* 24 */
  --space-8: 2rem;     /* 32 */
  --space-10: 2.5rem;  /* 40 */
  --space-12: 3rem;    /* 48 */

  /* --- shape: hierarchy shows in radius and border, not shadow ------------- */
  --radius-box: 10px;      /* column boxes and cards, dialogs */
  --radius-well: 6px;      /* tinted inner wells */
  --radius-control: 6px;   /* buttons, selects, inputs */
  --radius-readout: 4px;   /* readout insets, chips */
  --radius-tile: 3px;      /* byte tiles */
  --hairline: 1px;

  /* --- sizes --------------------------------------------------------------- */
  --left-width: 300px;
  --gutter: 24px;
  --app-bar-h: 56px;
  --band-h: 40px;
  --control-h: 36px;
  --control-h-sm: 30px;
  --readout-w: 9.5rem;     /* fits "-12345.67" in the title face at 28px */
  --readout-h: 44px;

  /* --- motion: only as an answer to an action ------------------------------ */
  --dur-ui: 140ms;         /* hover / press colour changes */
  --dur-dialog: 120ms;     /* dialog fade + scale */
  --dur-fresh: 600ms;      /* the "value just arrived" underline */
  --dur-reading: 1100ms;   /* one sweep of the indeterminate bar */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* --- colour: light ------------------------------------------------------- */
  --bench: #edf2f6;        /* page background */
  --panel: #ffffff;        /* boxes and cards */
  --well: #e4f0fb;         /* tinted inner groups (the original's light-blue boxes) */
  --band: #c9e2fa;         /* left box header bands (the original's blue strips) */
  --ink: #15222e;          /* text */
  --ink-2: #4a5b6b;        /* secondary text */
  --line: #c4d3e0;         /* decorative borders and dividers */
  --line-strong: #728599;  /* control boundaries: ≥ 3:1 on panel, well and bench */

  --signal: #1d5fa8;       /* primary actions, focus ring, links */
  --signal-hover: #174e8c;
  --signal-ink: #ffffff;   /* text on --signal */
  --signal-soft: #dceaf9;  /* selected tab, pressed toggle, quiet hover */

  --fresh: #276e45;        /* value just read / success   (brief: #2E7D4F, darkened for AA on --well) */
  --fresh-soft: #e2f2e8;
  --caution: #8f5100;      /* parity NONE, T-Bus, warnings (brief: #A85F00, darkened for AA on --well/--bench) */
  --caution-soft: #fbebd3;
  --fault: #b42318;        /* Error readouts, failures */
  --fault-soft: #fbe7e5;

  --readout: #ffffff;      /* readout inset background */
  --inset: inset 0 1px 2px rgb(21 34 46 / 0.08);

  /* Byte anatomy: address, function code, payload, CRC. */
  --byte-addr: #6b46c1;
  --byte-addr-tile: #efeafb;
  --byte-fn: var(--signal);
  --byte-fn-tile: #e3eefa;
  --byte-data: var(--ink);
  --byte-data-tile: #f1f5f9;
  --byte-crc: var(--ink-2);
  --byte-crc-tile: transparent;

  /* Chart series: distinct in hue AND lightness, ≥ 3:1 on --panel. */
  --series-1: #1d5fa8;
  --series-2: #b65f1c;
  --series-3: #8a4fb8;
  --series-4: #0e7c86;
  --series-5: #a23a6e;
  --series-6: #5d6b2a;

  /* Floating layers only (dialog, toasts): one shadow, nowhere else. */
  --float-shadow: 0 12px 32px rgb(21 34 46 / 0.18);
  --scrim: rgb(21 34 46 / 0.45);
}

/* --- dark: system default (no explicit choice stamped) -------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --bench: #0f1a23;
    --panel: #16232e;
    --well: #1b2e40;
    --band: #22405d;
    --ink: #e5eef5;
    --ink-2: #9db0c0;
    --line: #2c4256;
    --line-strong: #5f7a92;

    --signal: #6fb0f5;
    --signal-hover: #8ec2f8;
    --signal-ink: #0f1a23;
    --signal-soft: #1f3b58;

    --fresh: #5cc58a;
    --fresh-soft: #173426;
    --caution: #f0a640;
    --caution-soft: #3a2b13;
    --fault: #f27a6e;
    --fault-soft: #3e2220;

    --readout: #0f1a23;
    --inset: inset 0 1px 2px rgb(0 0 0 / 0.35);

    --byte-addr: #b69cf5;
    --byte-addr-tile: #2a2547;
    --byte-fn-tile: #1c3550;
    --byte-data-tile: #1d2d3b;

    --series-1: #6fb0f5;
    --series-2: #f0a060;
    --series-3: #c39bf0;
    --series-4: #4fc6cf;
    --series-5: #f08fbf;
    --series-6: #b5c46a;

    --float-shadow: 0 12px 32px rgb(0 0 0 / 0.5);
    --scrim: rgb(4 9 14 / 0.66);
  }
}

/* --- dark: explicit toggle (wins over the OS preference) ------------------ */
:root[data-theme='dark'] {
  color-scheme: dark;

  --bench: #0f1a23;
  --panel: #16232e;
  --well: #1b2e40;
  --band: #22405d;
  --ink: #e5eef5;
  --ink-2: #9db0c0;
  --line: #2c4256;
  --line-strong: #5f7a92;

  --signal: #6fb0f5;
  --signal-hover: #8ec2f8;
  --signal-ink: #0f1a23;
  --signal-soft: #1f3b58;

  --fresh: #5cc58a;
  --fresh-soft: #173426;
  --caution: #f0a640;
  --caution-soft: #3a2b13;
  --fault: #f27a6e;
  --fault-soft: #3e2220;

  --readout: #0f1a23;
  --inset: inset 0 1px 2px rgb(0 0 0 / 0.35);

  --byte-addr: #b69cf5;
  --byte-addr-tile: #2a2547;
  --byte-fn-tile: #1c3550;
  --byte-data-tile: #1d2d3b;

  --series-1: #6fb0f5;
  --series-2: #f0a060;
  --series-3: #c39bf0;
  --series-4: #4fc6cf;
  --series-5: #f08fbf;
  --series-6: #b5c46a;

  --float-shadow: 0 12px 32px rgb(0 0 0 / 0.5);
  --scrim: rgb(4 9 14 / 0.66);
}

/* --- touch: full-size targets --------------------------------------------- */
/* Keyed off BOTH a coarse pointer and a narrow viewport: pointer media is not
   always reported (and is not emulated when a desktop browser is merely
   resized), so width is the reliable second signal. */
@media (pointer: coarse), (max-width: 759.98px) {
  :root {
    --control-h: 44px;
    /* "Small" stops meaning smaller under a finger: Read all, Poll, Copy and
       Clear are pressed as often as any register button. */
    --control-h-sm: 44px;
    --readout-h: 46px;
  }
}

@media (max-width: 759.98px) {
  :root {
    --gutter: 16px;
    --band-h: 36px;
  }
}
