/* Signal v2 design tokens. The contract is docs/DESIGN-SYSTEM.md; change values there first.
   Loaded before site.css. This file declares the cascade-layer order for the whole site. */

@layer reset, tokens, base, layout, components, utilities;

/* Fonts: Geist and Geist Mono (SIL OFL 1.1, docs/licenses/geist.txt), self-hosted and unsubsetted.
   The fallback faces are metric-matched (measured in Chrome against Geist 1.7.2: average advance of an
   English sample, hhea ascent 1005 / descent 295 per 1000 units) so the swap does not shift layout. */
@font-face {
  font-family: "Geist";
  src: url("../assets/fonts/geist-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Mono";
  src: url("../assets/fonts/geist-mono-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Fallback";
  src: local("Arial"), local("ArialMT"), local("Liberation Sans");
  size-adjust: 102.16%;
  ascent-override: 98.37%;
  descent-override: 28.88%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Geist Mono Fallback";
  src: local("Courier New"), local("CourierNewPSMT"), local("Liberation Mono");
  size-adjust: 100%;
  ascent-override: 100.52%;
  descent-override: 29.51%;
  line-gap-override: 0%;
}

@layer tokens {
  :root {
    color-scheme: light;

    /* ---- Primitives: the palette (fixed in both themes) ---- */
    --paper: #f3f5f1;
    --white: #ffffff;
    --ink-950: #132b32;
    --rust-500: #cd3e1b;
    --rust-600: #b23417;
    --rust-300: #fa754b;
    --coral: #ff8e72;
    --petrol-500: #2f6f7a;
    --petrol-200: #7fc4cf;
    --mint: #74d3c4;
    --mint-600: #5fb8aa;       /* revenue bars in the pipeline scene, with --on-mint text (5.1:1 at 700) */
    --mint-700: #4a9c90;
    --on-mint: #06231f;
    --rust-200: #ff9874;       /* small rust text on dark and night surfaces */
    --amber: #e9c46a;

    /* Medallion layers in the warehouse figure (fixed in both themes; text on them is fixed too). */
    --bronze: #b8763a;
    --silver: #8d9aa0;
    --gold: #c99b2b;

    /* Night scenes (hero, proof, contact) look the same in both themes. */
    --night: #09171c;
    --night-2: #0f242b;
    --night-3: #163139;
    --n-ink: #eef4ef;
    --n-muted: #a3b9b8;
    --n-tertiary: #7d9496;
    --n-hair: rgba(255, 255, 255, 0.08);
    --n-hair-strong: rgba(255, 255, 255, 0.16);
    --rust-d: var(--rust-300);
    --petrol-d: var(--petrol-200);
    /* Gradient type, once per night scene ("trustworthy.", "numbers agree."); reads as mint throughout. */
    --grad-mint: linear-gradient(100deg, #e4fff8 0%, #8fe3d5 22%, #4fbfb0 48%, #9ae7da 74%, #effffb 100%);

    /* ---- Semantic colours: light theme (default) ---- */
    --bg: var(--paper);
    --card: var(--white);
    --surface: #e8ede6;
    --ink: var(--ink-950);
    --ink-700: #2e4850;
    --ink-500: #4f6168;        /* muted body and labels, 5.9:1 on bg */
    --ink-400: #68797f;        /* large text only (>= 18px) */
    --ink-300: #8a9ca0;        /* borders, placeholders, decoration; never text */
    --line: #cdd6d0;
    --line-strong: var(--ink-300);
    --rust: var(--rust-500);   /* CTA fill, large text, chart series */
    --rust-text: var(--rust-600); /* links and small rust text, 5.6:1 */
    --on-rust: var(--white);
    --petrol: var(--petrol-500);
    --petrol-soft: #d3e3e0;    /* the "not counted" cells of waffle charts */
    --logo-bg: var(--white);
    --logo-ring: #dce2df;
    --figure-bg: var(--white);  /* report screenshots keep a white ground in both themes */
    --code-bg: var(--night-3);
    --code-ink: var(--n-ink);
    --press-shade: rgba(0, 0, 0, 0.094);
    --focus-ring: var(--rust-text);

    /* Chart palette, shared by UI and figures. Semantics are fixed:
       petrol = clean / kept, rust = rejected / churned, amber = held / duplicate,
       mint = highlight on night, clay = secondary, slate = raw / unknown. */
    --series-1: var(--petrol-500);
    --series-2: var(--rust-500);
    --series-3: var(--amber);
    --series-4: var(--mint);
    --series-5: #b8763a;
    --series-6: #8d9aa0;

    /* Elevation. Light: lit top edge plus layered ambient shadow. Dark: hairline only. */
    --hi: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    --shadow-card:
      0 1px 2px rgba(19, 43, 50, 0.05),
      0 10px 28px -14px rgba(19, 43, 50, 0.22),
      0 44px 90px -52px rgba(19, 43, 50, 0.38);

    /* Film grain for night scenes only: opacity .08, mix-blend-mode overlay (DESIGN-SYSTEM §2). */
    --texture-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

    /* ---- Type ---- */
    --font-sans: "Geist", "Geist Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", "Geist Mono Fallback", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;

    --text-hero: clamp(3rem, 1.6rem + 7vw, 8.5rem);
    --text-h2: clamp(2rem, 1.3rem + 3vw, 4rem);
    --text-h3: clamp(1.5rem, 1.2rem + 1.2vw, 2.1rem);
    --text-metric: clamp(3rem, 2rem + 4.5vw, 6rem);
    --text-tile: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem);
    --text-lead: clamp(1rem, 0.95rem + 0.4vw, 1.15rem);
    --text-body: 1rem;
    --text-small: 0.875rem;
    --text-label: 0.75rem;
    --text-caption: 0.75rem;
    --text-button: 0.9375rem;

    --leading-tight: 0.92;
    --leading-heading: 1.08;
    --leading-body: 1.6;

    --tracking-hero: -0.045em;
    --tracking-h2: -0.03em;
    --tracking-h3: -0.025em;
    --tracking-label: 0.1em;

    /* Measures in em, not ch: Geist's zero is wide (0.663em), so 62ch would be ~89 characters. */
    --measure: 32em;        /* ~69 characters of Geist body text */
    --measure-pitch: 27em;  /* ~58 characters */

    /* ---- Space: 4px base ---- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;  /* heading to content */
    --space-12: 48px;
    --space-16: 64px;
    --space-24: 96px;
    --space-32: 128px;
    --space-40: 160px;
    --section-pad: clamp(72px, 10vw, 128px);

    /* ---- Layout ---- */
    --container: 1280px;
    --header-space: 84px;   /* the fixed nav pill (12 px offset + 60 px) and a 12 px gap below it */
    --gutter: max(16px, env(safe-area-inset-left, 0px));
    /* Breakpoints (for reference; custom properties cannot be used in media queries):
       560px phone, 760px small tablet, 980px tablet, 1180px desktop. */

    /* ---- Radii ---- */
    --radius-chip: 6px;
    --radius-tile: 12px;
    --radius-card: 20px;
    --radius-panel: 28px;
    --radius-pill: 999px;

    /* ---- Motion ---- */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-in: cubic-bezier(0.4, 0, 1, 1);
    --duration-fast: 150ms;
    --duration-base: 250ms;
    --duration-slow: 600ms;

    /* ---- Layers ---- */
    --z-header: 20;
    --z-skip: 100;
  }

  /* Dark theme, following the OS unless the visitor chose light. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --bg: #0f2026;
      --card: #17303a;
      --surface: #14292f;
      --ink: #f0f5ed;
      --ink-700: #d3dfdc;
      --ink-500: #b3c6c9;
      --ink-400: #8ea3a6;
      --ink-300: #5f777b;
      --line: rgba(255, 255, 255, 0.1);
      --line-strong: rgba(255, 255, 255, 0.18);
      --rust: var(--rust-300);
      --rust-text: var(--rust-200);
      --on-rust: var(--night);
      --petrol: var(--petrol-200);
      --petrol-soft: #24474f;
      --logo-bg: #f1f5f1;
      --logo-ring: rgba(255, 255, 255, 0.18);
      --code-bg: #0b1a1f;
      --press-shade: rgba(0, 0, 0, 0.16);
      --series-1: var(--petrol-200);
      --series-2: var(--rust-300);
      --series-5: #d49a5c;
      --series-6: #9aa8ac;
      --hi: inset 0 1px 0 rgba(255, 255, 255, 0.06);
      --shadow-card: 0 0 0 1px var(--line);
    }
  }

  /* Dark theme chosen with the toggle: the same values, so the choice wins both ways. */
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f2026;
    --card: #17303a;
    --surface: #14292f;
    --ink: #f0f5ed;
    --ink-700: #d3dfdc;
    --ink-500: #b3c6c9;
    --ink-400: #8ea3a6;
    --ink-300: #5f777b;
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.18);
    --rust: var(--rust-300);
    --rust-text: var(--rust-200);
    --on-rust: var(--night);
    --petrol: var(--petrol-200);
    --petrol-soft: #24474f;
    --logo-bg: #f1f5f1;
    --logo-ring: rgba(255, 255, 255, 0.18);
    --code-bg: #0b1a1f;
    --press-shade: rgba(0, 0, 0, 0.16);
    --series-1: var(--petrol-200);
    --series-2: var(--rust-300);
    --series-5: #d49a5c;
    --series-6: #9aa8ac;
    --hi: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    --shadow-card: 0 0 0 1px var(--line);
  }

  /* Body text steps to 17px on wide screens (DESIGN-SYSTEM §3.1). Measures are in em, so lines keep
     their character count. */
  @media (min-width: 1200px) {
    :root {
      --text-body: 1.0625rem;
    }
  }
}
