/* Rearview Design System Tokens & Base Reset
 * Single-source, WCAG 2.1 AA/AAA verified token layer with sRGB hex fallbacks
 * and mathematically matched OKLCH color definitions. Zero legacy v2 dark tokens.
 */

@layer reset, tokens, layout, components, cards, motion;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    overflow-x: clip;
  }

  html {
    color-scheme: light;
    background: var(--pg);
    scroll-padding-top: 136px;
    -webkit-text-size-adjust: 100%;
  }

  body {
    margin: 0;
    background: var(--pg);
    color: var(--pg-ink);
    font: 400 1rem / 1.55 var(--body);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  [hidden] {
    display: none !important;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  img,
  svg {
    max-width: 100%;
  }

  h1,
  h2,
  h3,
  h4 {
    font-family: var(--body);
    font-weight: 800;
    line-height: 1.08;
    text-wrap: balance;
    margin: 0;
    font-style: normal;
  }

  a {
    color: var(--pg-ink);
    text-underline-offset: 3px;
  }

  p {
    margin: 0;
  }
}

@layer tokens {
  :root {
    /* Core editorial paper & ink palette (sRGB hex fallbacks) */
    --pg: #F7F5EF;
    --pg-2: #FFFFFF;
    --pg-3: #ECE9E0;
    --pg-ink: #111318;
    --pg-soft: #4A4842;
    --pg-muted: #5E5B53;
    --pg-rule: #D5D1C7;
    --pg-axis: #B7B2A6;

    /* Cab yellow brand accent */
    --taxi: #F5C83B;
    --taxi-soft: #3B310B;

    /* High-contrast accessible focus ring (4.21:1 on yellow, 6.15:1 on paper) */
    --focus: #1D4ED8;
    --focus-halo: #FFFFFF;

    /* Semantic delta colors (AA verified on paper & tinted pills) */
    --up: #116B45;
    --up-bg: #E7F4EE;
    --down: #B42318;
    --down-bg: #FDECEC;

    /* Monotonic 5-step sequential heatmap ramp */
    --heat-0: #ECEAE3;
    --heat-0-border: #DFDCD3;
    --heat-1: #F7E29B;
    --heat-2: #F0BC34;
    --heat-3: #C47214;
    --heat-4: #26221B;

    /* WCAG-verified physical card material tokens */
    --card-chalk: #F0EEE9;
    --card-ink: #111318;
    --card-paper: #FAF8F2;
    --card-manila: #E3CAA2;
    --card-ledger: #F3EDE0;
    --card-mint-sec: #E3EFEA;
    --card-tape-bg: #E4E6EB;
    --card-sign: #0E6B46;
    --card-blueprint: #1D4B8F;
    --card-stamp-red: #B0221C;
    --card-pass-sub: #525866;
    --card-pass-route: #B84312;
    --card-punch-empty: #746755;
    --card-mirror-etch: #A6B0C2;
    --card-flip-dim: #9DA5B4;
    --card-plate-blue: #223B73;
    --card-amber: #F0B429;
    --card-amber-off: #2D261B;
    --card-needle: #F26B27;

    /* Story player overlay badges (AAA 12.81:1) */
    --player-paused-fg: #F0EEE9;
    --player-paused-bg: rgba(17, 19, 24, 0.88);
    --pbar-bg: rgba(17, 19, 24, 0.42);
    --pbar-track: rgba(240, 238, 233, 0.34);
    --pbar-fill: #FFFFFF;

    /* Self-hosted font stacks with Arabic fallback */
    --body: "Overpass", "IBM Plex Sans Arabic", "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "Overpass Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --cond: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
    --hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;

    /* Fluid typography scale */
    --text-hero: clamp(2.5rem, 5.8vw, 5.1rem);
    --text-h2: clamp(1.85rem, 3.6vw, 2.75rem);
    --text-h3: clamp(1.0625rem, 1.4vw, 1.125rem);
    --text-kpi-lg: clamp(2.25rem, 4.5vw, 3.6rem);
    --text-kpi-md: clamp(1.5rem, 3vw, 2.5rem);

    /* Layout & elevation tokens (8px spatial grid) */
    --hdr: 64px;
    --wrap-max: 1180px;
    --radius-card: 18px;
    --radius-panel: 16px;
    --radius-btn: 10px;
    --radius-pill: 999px;
    --radius-sm: 4px;

    /* Tactile Swiss transit press physics */
    --shadow-btn: 2px 2px 0 var(--pg-ink);
    --shadow-btn-hover: 3px 3px 0 var(--pg-ink);
    --shadow-btn-active: 1px 1px 0 var(--pg-ink);
    --ease-tactile: cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  @supports (color: oklch(0% 0 0)) {
    :root {
      --pg: oklch(97.00% 0.0082 91.5);
      --pg-2: oklch(100.00% 0.0000 89.9);
      --pg-3: oklch(93.39% 0.0124 91.5);
      --pg-ink: oklch(18.69% 0.0107 268.1);
      --pg-soft: oklch(40.16% 0.0102 91.6);
      --pg-muted: oklch(47.14% 0.0132 89.8);
      --pg-rule: oklch(86.11% 0.0143 88.7);
      --pg-axis: oklch(76.43% 0.0177 88.0);
      --taxi: oklch(84.93% 0.1566 90.1);
      --taxi-soft: oklch(31.57% 0.0555 94.0);
      --focus: oklch(48.82% 0.2172 264.4);
      --up: oklch(46.80% 0.1013 159.1);
      --up-bg: oklch(95.58% 0.0159 166.7);
      --down: oklch(50.03% 0.1821 29.5);
      --down-bg: oklch(95.66% 0.0185 17.5);
      --heat-0: oklch(93.67% 0.0096 93.6);
      --heat-1: oklch(91.38% 0.0924 93.6);
      --heat-2: oklch(82.05% 0.1536 86.2);
      --heat-3: oklch(62.96% 0.1399 61.4);
      --heat-4: oklch(25.40% 0.0140 81.6);
      --card-sign: oklch(46.78% 0.1011 160.0);
      --card-blueprint: oklch(42.06% 0.1233 258.5);
      --card-stamp-red: oklch(49.25% 0.1785 28.4);
      --card-pass-sub: oklch(46.03% 0.0240 267.0);
      --card-pass-route: oklch(53.95% 0.1613 39.6);
      --card-punch-empty: oklch(52.09% 0.0318 75.9);
      --card-mirror-etch: oklch(75.51% 0.0282 262.3);
      --card-flip-dim: oklch(72.03% 0.0236 263.2);
    }
  }
}
