/* ═══════════════════════════════════════════════════════════════════
   Jarvis Playground v3 — Design Tokens
   ─────────────────────────────────────────────────────────────────
   The single source of truth for every visual value in the v3 layer.
   No component file in css/v3/ may contain a raw color, size, or
   duration — everything routes through a token defined here.

   Architecture:
     1. STRUCTURAL TOKENS  — theme-invariant (fonts, spacing, radius,
        z-index, motion). Defined once on :root, never overridden.
     2. SEMANTIC COLORS    — theme-variant. Defined on :root with the
        Aurora (cool) defaults; themes/aurora.css and themes/ember.css
        re-map the SAME token names under :root[data-theme="…"].
        Components reference roles (--v3-accent), not hues (--v3-cyan),
        so a theme swap re-skins every component for free.
     3. DERIVED TINTS      — opacity variants computed with
        color-mix() from the semantic tokens. This is the fix for the
        v2 "hardcoded rgba debt" (see css/CSS_ARCHITECTURE.md §4.3):
        a theme remap warms/cools every tint automatically.

   Load order (contract, mirrors v2 §2.3):
     tokens.css → layout.css → components/*.css → themes/<active>.css
   The theme file ALWAYS loads last so its :root[data-theme] remap wins
   at equal specificity by source order. No !important anywhere.

   Usage examples:
     .my-card {
       background: var(--v3-bg-surface);
       border: 1px solid var(--v3-border);
       border-radius: var(--v3-radius-lg);
       padding: var(--v3-space-6);
       box-shadow: var(--v3-shadow-2);
       transition: box-shadow var(--v3-dur-2) var(--v3-ease-out),
                   transform var(--v3-dur-3) var(--v3-ease-spring);
     }
     .my-card:hover { box-shadow: var(--v3-glow-md); }
   ═══════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────
   0. @property registrations
   Typed, animatable custom properties. Engines without @property
   support (old Safari) degrade gracefully: the values still resolve,
   they just can't be transitioned on the property itself.
   ───────────────────────────────────────────────────────────────── */
@property --v3-angle {
  syntax: '<angle>';
  inherits: true;
  initial-value: 0deg;
}
@property --v3-glow-opacity {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.6;
}

/* ═══════════════════════════════════════════════════════════════════
   1. STRUCTURAL TOKENS (theme-invariant)
   ═══════════════════════════════════════════════════════════════════ */
:root {

  /* ── Typography: font families ────────────────────────────────
     --v3-font-sans     body copy, UI text, buttons
     --v3-font-mono     code chips, stats, terminal bits, kbd
     --v3-font-display  hero titles, big numbers, brand moments
     --v3-font-serif    long-form editorial prose (article pages)
     Swap the stack here to re-skin the whole site's type. */
  --v3-font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --v3-font-mono: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', 'Courier New', Courier, monospace;
  --v3-font-display: 'Space Grotesk', 'Orbitron', var(--v3-font-sans);
  --v3-font-serif: 'Newsreader', 'Source Serif 4', Georgia, 'Times New Roman', serif;

  /* ── Typography: fluid scale ─────────────────────────────────
     clamp(min, preferred, max) — the preferred value is a vw-based
     ramp so text scales continuously from 320px → 1920px viewports
     (mobile-first: the min is the phone size, the max caps desktop).
     1rem = 16px assumed.

     Usage:  h1 { font-size: var(--v3-text-5xl); }
             .kicker { font-size: var(--v3-text-xs); } */
  --v3-text-xs:   clamp(0.6875rem, 0.66rem + 0.13vw, 0.75rem);   /* 11 → 12px   */
  --v3-text-sm:   clamp(0.8125rem, 0.77rem + 0.22vw, 0.875rem);  /* 13 → 14px   */
  --v3-text-base: clamp(0.9375rem, 0.88rem + 0.29vw, 1.0625rem); /* 15 → 17px   */
  --v3-text-lg:   clamp(1.0625rem, 0.98rem + 0.42vw, 1.25rem);   /* 17 → 20px   */
  --v3-text-xl:   clamp(1.25rem, 1.12rem + 0.65vw, 1.5rem);      /* 20 → 24px   */
  --v3-text-2xl:  clamp(1.5rem, 1.28rem + 1.10vw, 2rem);         /* 24 → 32px   */
  --v3-text-3xl:  clamp(1.875rem, 1.55rem + 1.63vw, 2.625rem);   /* 30 → 42px   */
  --v3-text-4xl:  clamp(2.375rem, 1.85rem + 2.63vw, 3.5rem);     /* 38 → 56px   */
  --v3-text-5xl:  clamp(3rem, 2.15rem + 4.25vw, 5rem);           /* 48 → 80px   */

  /* ── Typography: weights & rhythm ──────────────────────────── */
  --v3-weight-regular: 400;
  --v3-weight-medium:  500;
  --v3-weight-semibold: 600;
  --v3-weight-bold:    700;
  --v3-weight-black:   800;

  --v3-leading-tight: 1.1;   /* display headings */
  --v3-leading-snug:  1.25;  /* headings */
  --v3-leading-base:  1.6;   /* body copy */
  --v3-leading-loose: 1.8;   /* long-form */

  --v3-tracking-wide:  0.02em;  /* small caps labels */
  --v3-tracking-wider: 0.08em;  /* kickers, badges */

  /* ── Spacing: 8px base unit ──────────────────────────────────
     Multiplier keys: --v3-space-N = N × 4px (half-unit steps for
     tight UI) up to the full 8px grid. 4px is the atomic unit.

     Usage:  .card { padding: var(--v3-space-6); }  /* 24px */
             .stack > * + * { margin-top: var(--v3-space-4); } */
  --v3-space-0: 0;
  --v3-space-1: 4px;    /* 0.25 × 8 */
  --v3-space-2: 8px;    /* 0.5  × 8 */
  --v3-space-3: 12px;   /* 0.75 × 8 */
  --v3-space-4: 16px;   /* 1    × 8 */
  --v3-space-5: 20px;   /* 1.25 × 8 */
  --v3-space-6: 24px;   /* 1.5  × 8 */
  --v3-space-8: 32px;   /* 2    × 8 */
  --v3-space-10: 40px;  /* 2.5  × 8 */
  --v3-space-12: 48px;  /* 3    × 8 */
  --v3-space-16: 64px;  /* 4    × 8 */
  --v3-space-20: 80px;  /* 5    × 8 */
  --v3-space-24: 96px;  /* 6    × 8 */

  /* ── Layout: page gutters & content width ─────────────────────
     Fluid gutter: 16px on phones → 32px on desktop.
     --v3-content-max: the widest a centered column may get. */
  --v3-gutter: clamp(16px, 4vw, 32px);
  --v3-content-max: 1280px;
  --v3-content-wide: 1536px;

  /* ── Breakpoints (documented reference) ──────────────────────
     CSS media queries can't consume var(), so these document the
     canonical scale used throughout layout.css:
       sm  640px   md  1024px   lg  1280px   xl  1536px
     Mobile-first: base styles = < 640px, then min-width queries. */

  /* ── Radius ──────────────────────────────────────────────────
     --v3-radius-sm   chips, badges, small buttons
     --v3-radius      inputs, default controls
     --v3-radius-md   cards
     --v3-radius-lg   large cards, modals
     --v3-radius-full pills, avatars */
  --v3-radius-sm: 6px;
  --v3-radius: 10px;
  --v3-radius-md: 14px;
  --v3-radius-lg: 20px;
  --v3-radius-xl: 28px;
  --v3-radius-full: 9999px;

  /* ── Elevation: 5 shadow levels ──────────────────────────────
     L0 none · L1 resting surface · L2 raised (hover) · L3 modal
     · L4 floating chrome (nav, drawer) · L5 hero/spotlight.
     Shadows use --v3-shadow-color so themes can warm them.

     Usage:  .card { box-shadow: var(--v3-shadow-2); }
             .card:hover { box-shadow: var(--v3-shadow-3); } */
  --v3-shadow-color: rgba(0, 0, 0, 0.55);
  --v3-shadow-1: 0 1px 2px 0 var(--v3-shadow-color),
                 0 1px 6px -1px var(--v3-shadow-color);
  --v3-shadow-2: 0 2px 4px -1px var(--v3-shadow-color),
                 0 8px 20px -4px var(--v3-shadow-color);
  --v3-shadow-3: 0 4px 8px -2px var(--v3-shadow-color),
                 0 16px 40px -8px var(--v3-shadow-color);
  --v3-shadow-4: 0 8px 16px -4px var(--v3-shadow-color),
                 0 28px 64px -12px var(--v3-shadow-color);
  --v3-shadow-5: 0 16px 32px -8px var(--v3-shadow-color),
                 0 48px 96px -16px var(--v3-shadow-color);

  /* ── Glow: neon signature effects ────────────────────────────
     Three intensity steps, built from the accent token via
     color-mix() so they follow the active theme automatically.
     --v3-glow-accent  = the "on" color (cyan in Aurora, amber in Ember)
     --v3-glow-accent-2 = the secondary hue for layered glows

     Usage:  .btn-primary { box-shadow: var(--v3-glow-sm); }
             .hero-orb    { box-shadow: var(--v3-glow-lg); } */
  --v3-glow-sm: 0 0 12px 0 color-mix(in srgb, var(--v3-accent) 35%, transparent),
                0 0 2px 0 color-mix(in srgb, var(--v3-accent) 55%, transparent);
  --v3-glow-md: 0 0 24px 0 color-mix(in srgb, var(--v3-accent) 30%, transparent),
                0 0 60px -12px color-mix(in srgb, var(--v3-accent-2) 35%, transparent);
  --v3-glow-lg: 0 0 48px -4px color-mix(in srgb, var(--v3-accent) 40%, transparent),
                0 0 120px -24px color-mix(in srgb, var(--v3-accent-2) 45%, transparent);
  --v3-glow-ring: inset 0 0 0 1px color-mix(in srgb, var(--v3-accent) 55%, transparent),
                  inset 0 0 18px color-mix(in srgb, var(--v3-accent) 18%, transparent);

  /* ── Motion: durations ───────────────────────────────────────
     --v3-dur-1 100ms  micro feedback (hover tint, press)
     --v3-dur-2 200ms  standard transitions (borders, colors)
     --v3-dur-3 300ms  layout-ish moves (cards lifting, drawers)
     --v3-dur-4 450ms  page-level reveals
     --v3-dur-5 600ms  hero / ambient entrances

     Usage:  transition: transform var(--v3-dur-3) var(--v3-ease-out); */
  --v3-dur-1: 100ms;
  --v3-dur-2: 200ms;
  --v3-dur-3: 300ms;
  --v3-dur-4: 450ms;
  --v3-dur-5: 600ms;

  /* ── Motion: easing curves ───────────────────────────────────
     --v3-ease-out     default for entrances & hovers (fast start,
                       soft landing)
     --v3-ease-in      exits only
     --v3-ease-in-out  ambient loops, oscillation
     --v3-ease-spring  overshoot pop (cubic-bezier > 1 on y2) —
                       toggles, like buttons, small card lifts
     --v3-ease-linear  progress bars, marquees (constant speed) */
  --v3-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --v3-ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --v3-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --v3-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --v3-ease-linear: linear;

  /* ── Motion: spring physics (for JS/WAAPI consumers) ─────────
     Documented values for use in code:
       const SPRING = { stiffness: 170, damping: 12, mass: 1 };
     CSS approximation is --v3-ease-spring above. */
  --v3-spring-stiffness: 170;
  --v3-spring-damping: 12;
  --v3-spring-mass: 1;

  /* ── Z-index scale ───────────────────────────────────────────
     v2 defined a scale nothing used (audit §3.2.6). v3 adopts it:
     every positioned layer picks a named rung, never a literal.
     Ambient background layers live BELOW content (negative).

     Usage:  .nav { z-index: var(--v3-z-nav); } */
  --v3-z-ambient: -1;        /* aurora orbs, particles, grid      */
  --v3-z-content: 0;         /* document flow                     */
  --v3-z-raised: 10;         /* in-page sticky elements           */
  --v3-z-dropdown: 100;      /* menus, popovers                   */
  --v3-z-sticky: 200;        /* sticky headers within pages       */
  --v3-z-fixed: 300;         /* fixed chrome (nav bar)            */
  --v3-z-nav: 1000;          /* global nav                        */
  --v3-z-drawer: 1001;       /* mobile drawer                     */
  --v3-z-backdrop: 1002;     /* modal/backdrop scrim              */
  --v3-z-modal: 1003;        /* modals                            */
  --v3-z-toast: 1004;        /* toasts / notifications            */
  --v3-z-tooltip: 1005;      /* tooltips                          */

  /* ── Interactive sizing ──────────────────────────────────────
     Touch targets ≥ 44px (WCAG 2.5.5). --v3-hit is the minimum
     clickable area; visual size may be smaller. */
  --v3-hit: 44px;
  --v3-border-w: 1px;
  --v3-border-w-thick: 2px;
}

/* ═══════════════════════════════════════════════════════════════════
   2. SEMANTIC COLOR TOKENS — Aurora (cool) defaults
   ─────────────────────────────────────────────────────────────────
   These are the ROLE tokens. Components only ever use names from
   this section (plus §3 derived tints). themes/aurora.css restates
   them explicitly (self-documenting); themes/ember.css re-maps them.

   Naming convention:
     --v3-bg-*      page & surface backgrounds (darkest → lightest)
     --v3-text-*    foreground text by importance
     --v3-accent*   brand hues by role (accent = primary)
     --v3-*        semantic state colors (success/warning/error/info)
     --v3-border*   line work
   ═══════════════════════════════════════════════════════════════════ */
:root {
  /* ── Backgrounds: cool near-blacks, blue-violet undertone ──── */
  --v3-bg: #050507;            /* page base — deepest            */
  --v3-bg-raised: #0a0b10;     /* nav, sidebars, sticky headers  */
  --v3-bg-surface: #0d0f16;    /* cards, panels                  */
  --v3-bg-elevated: #12151f;   /* hover state, popovers          */
  --v3-bg-overlay: rgba(5, 5, 7, 0.92); /* modal scrims */

  /* ── Text: cool white, blue-grey dimming ───────────────────── */
  --v3-text: #f4f7fb;
  --v3-text-secondary: rgba(244, 247, 251, 0.72);
  --v3-text-muted: rgba(244, 247, 251, 0.55);  /* 0.45→0.55: WCAG AA (≥4.5:1) */
  --v3-text-inverse: #050507;  /* text on accent fills           */

  /* ── Brand hues (raw palette) ─────────────────────────────────
     Primary:  cyan → purple → magenta (the v3 signature ramp)
     Secondary: emerald, amber, rose */
  --v3-cyan: #00f2ff;
  --v3-purple: #7000ff;
  --v3-magenta: #ff006e;
  --v3-emerald: #00e5a0;
  --v3-amber: #ffb347;
  --v3-rose: #ff5c7a;

  /* ── Brand roles ──────────────────────────────────────────────
     --v3-accent     primary interactive color (links, focus,
                     primary buttons, glow source)
     --v3-accent-2   secondary brand hue (gradient partner)
     --v3-accent-3   tertiary hot hue (gradient tail, highlights)

     Usage:  a { color: var(--v3-accent); }
             .hero-title { background: var(--v3-grad-brand); } */
  --v3-accent: var(--v3-cyan);
  --v3-accent-2: var(--v3-purple);
  --v3-accent-3: var(--v3-magenta);
  --v3-accent-2-text: #a78bfa;  /* AA-safe small purple text (7.48:1 on --v3-bg);
                                   --v3-accent-2 itself is decorative-only */

  /* ── Gradients ────────────────────────────────────────────────
     --v3-grad-brand   the signature 3-stop brand ramp
     --v3-grad-brand-soft  faint wash for surfaces/banners
     --v3-grad-text        animated-ready text gradient (220% size)
     --v3-grad-surface     subtle top-light for cards
     --v3-grad-angle       shared angle token (animatable via
                           @property above) — rotate it to animate
                           the whole gradient family at once */
  --v3-grad-angle: 135deg;
  --v3-grad-brand: linear-gradient(var(--v3-grad-angle),
      var(--v3-accent) 0%, var(--v3-accent-2) 55%, var(--v3-accent-3) 110%);
  --v3-grad-brand-soft: linear-gradient(var(--v3-grad-angle),
      color-mix(in srgb, var(--v3-accent) 14%, transparent),
      color-mix(in srgb, var(--v3-accent-2) 16%, transparent));
  --v3-grad-text: linear-gradient(var(--v3-grad-angle),
      var(--v3-accent) 0%, var(--v3-accent-2) 45%, var(--v3-accent-3) 90%);
  --v3-grad-surface: linear-gradient(165deg,
      rgba(255, 255, 255, 0.055) 0%, rgba(255, 255, 255, 0.015) 100%);

  /* ── Semantic state colors ────────────────────────────────────
     success / warning / error / info — used by badges, toasts,
     status dots, form validation. Roles are fixed; the hues are
     theme-variant (ember warms them).

     Usage:  .badge-ok { color: var(--v3-success);
                         background: var(--v3-success-16); } */
  --v3-success: var(--v3-emerald);
  --v3-warning: var(--v3-amber);
  --v3-error: var(--v3-rose);
  --v3-info: var(--v3-cyan);

  /* ── Borders ──────────────────────────────────────────────────
     --v3-border       resting line (10% white, cool)
     --v3-border-hover hover line (accent-tinted)
     --v3-border-focus focus ring color */
  --v3-border: rgba(255, 255, 255, 0.09);
  --v3-border-strong: rgba(255, 255, 255, 0.18);
  --v3-border-hover: color-mix(in srgb, var(--v3-accent) 40%, transparent);
  --v3-border-focus: var(--v3-accent);
}

/* ═══════════════════════════════════════════════════════════════════
   3. DERIVED TINTS — computed from semantic tokens
   ─────────────────────────────────────────────────────────────────
   Opacity variants of the brand & state colors. Defined with
   color-mix() so they inherit whatever the active theme set the
   base token to. (color-mix: baseline support 2023+ — all target
   browsers for a 2026 site. Fallback note: if a value must work in
   a pre-2023 engine, the theme files define static equivalents.)

   Scale: -08 (hairline wash) · -16 (subtle fill) · -32 (visible
   fill) · -64 (strong fill) · -solid (the token itself).

   Usage:  .chip { background: var(--v3-accent-16);
                   border-color: var(--v3-accent-32); }
           .status-dot::after { background: var(--v3-success-64); }
   ═══════════════════════════════════════════════════════════════════ */
:root {
  /* accent family */
  --v3-accent-08: color-mix(in srgb, var(--v3-accent) 8%, transparent);
  --v3-accent-16: color-mix(in srgb, var(--v3-accent) 16%, transparent);
  --v3-accent-32: color-mix(in srgb, var(--v3-accent) 32%, transparent);
  --v3-accent-64: color-mix(in srgb, var(--v3-accent) 64%, transparent);

  --v3-accent-2-08: color-mix(in srgb, var(--v3-accent-2) 8%, transparent);
  --v3-accent-2-16: color-mix(in srgb, var(--v3-accent-2) 16%, transparent);
  --v3-accent-2-32: color-mix(in srgb, var(--v3-accent-2) 32%, transparent);

  /* state family */
  --v3-success-08: color-mix(in srgb, var(--v3-success) 8%, transparent);
  --v3-success-16: color-mix(in srgb, var(--v3-success) 16%, transparent);
  --v3-success-32: color-mix(in srgb, var(--v3-success) 32%, transparent);
  --v3-success-64: color-mix(in srgb, var(--v3-success) 64%, transparent);

  --v3-warning-08: color-mix(in srgb, var(--v3-warning) 8%, transparent);
  --v3-warning-16: color-mix(in srgb, var(--v3-warning) 16%, transparent);
  --v3-warning-32: color-mix(in srgb, var(--v3-warning) 32%, transparent);
  --v3-warning-64: color-mix(in srgb, var(--v3-warning) 64%, transparent);

  --v3-error-08: color-mix(in srgb, var(--v3-error) 8%, transparent);
  --v3-error-16: color-mix(in srgb, var(--v3-error) 16%, transparent);
  --v3-error-32: color-mix(in srgb, var(--v3-error) 32%, transparent);
  --v3-error-64: color-mix(in srgb, var(--v3-error) 64%, transparent);

  --v3-info-08: color-mix(in srgb, var(--v3-info) 8%, transparent);
  --v3-info-16: color-mix(in srgb, var(--v3-info) 16%, transparent);
  --v3-info-32: color-mix(in srgb, var(--v3-info) 32%, transparent);
  --v3-info-64: color-mix(in srgb, var(--v3-info) 64%, transparent);

  /* neutral tints (from --v3-text, so they warm/cool with theme) */
  --v3-text-08: color-mix(in srgb, var(--v3-text) 8%, transparent);
  --v3-text-16: color-mix(in srgb, var(--v3-text) 16%, transparent);
  --v3-text-32: color-mix(in srgb, var(--v3-text) 32%, transparent);
}

/* ─────────────────────────────────────────────────────────────────
   4. REDUCED MOTION — global kill switch
   ─────────────────────────────────────────────────────────────────
   When the user opts out of motion, collapse every duration to 1ms
   and disable smooth scrolling. Individual keyframe animations add
   their own `animation: none` overrides where a 1ms run would still
   flash (see components/* and themes/*). This single block is the
   safety net that guarantees no file can ship a runaway animation. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --v3-dur-1: 1ms;
    --v3-dur-2: 1ms;
    --v3-dur-3: 1ms;
    --v3-dur-4: 1ms;
    --v3-dur-5: 1ms;
    --v3-ease-spring: var(--v3-ease-out);
  }
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
