/* ══════════════════════════════════════════════════════════════════════
   SelfBalance Lab — utility workspace design tokens
   Single source of truth for color, type, space, radius, elevation, motion,
   and z-index. Neutral application chrome keeps attention on the 3D bench and
   assistant; blue is reserved for actions, selection and live information.
   All text pairings target WCAG AA (≥4.5:1 body, ≥3:1 large) in BOTH themes.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Neutral ramp (blue-slate) — Radix-style 12 steps ───────────────── */
  --gray-1:  #111315;
  --gray-2:  #17191c;
  --gray-3:  #1d2024;
  --gray-4:  #24282d;
  --gray-5:  #2c3137;
  --gray-6:  #383e46;
  --gray-7:  #484f59;
  --gray-8:  #5d6672;
  --gray-9:  #747e8c;
  --gray-10: #9099a5;
  --gray-11: #b6bdc6;
  --gray-12: #f1f3f5;

  /* ── Surfaces (aliases → ramp; legacy names preserved) ──────────────── */
  --bg: var(--gray-1);
  --panel: var(--gray-2);
  --panel-2: var(--gray-3);
  --panel-3: var(--gray-4);
  --panel-4: var(--gray-5);              /* 4th elevation: popovers/menus */
  --overlay: rgba(9, 12, 17, 0.78);
  --overlay-strong: rgba(14, 18, 26, 0.93);

  /* ── Lines & text ───────────────────────────────────────────────────── */
  --border: var(--gray-6);
  --border-2: var(--gray-7);
  --border-focus: var(--gray-8);         /* interactive borders brighten on hover/focus */
  --text: var(--gray-12);
  --text-dim: var(--gray-11);            /* muted but ≥4.5:1 on surfaces 1–4 */
  --text-faint: var(--gray-10);          /* 3:1 — large text / placeholders / captions only */

  /* ── Accent · inventive indigo ──────────────────────────────────────── */
  --amber-1:  #17120a;
  --amber-2:  #1f1808;
  --amber-3:  #2e2207;
  --amber-4:  #3d2d06;
  --amber-5:  #4d3808;
  --amber-6:  #63490a;
  --amber-7:  #7d5d0c;
  --amber-8:  #a67a0e;
  --amber-9:  #ffb000;   /* SOLID accent */
  --amber-10: #ffbe2e;   /* accent hover */
  --amber-11: #ffc94d;   /* amber text/links on dark (AA ~9:1) */
  --amber-12: #ffe4a8;
  --accent: #6ea8fe;
  --accent-hover: #8bb9ff;
  --accent-text: #9ec5fe;
  --accent-dim: #29466e;
  --accent-glow: rgba(110, 168, 254, 0.22);
  --accent-soft: rgba(110, 168, 254, 0.10);

  /* ── Secondary · IRIDIUM CYAN (instrument / live-signal) ────────────── */
  --cyan-3:  #06232a;
  --cyan-5:  #0a3a44;
  --cyan-7:  #0f5563;
  --cyan-9:  #22d3ee;   /* SOLID secondary */
  --cyan-10: #3ddcf2;   /* secondary hover */
  --cyan-11: #6fe6f6;   /* cyan text on dark (AA) */
  --secondary: #35d7c7;
  --secondary-hover: #5ce2d5;
  --secondary-text: #8ceee5;
  --secondary-dim: #176a68;
  --secondary-glow: rgba(53, 215, 199, 0.30);
  --secondary-soft: rgba(53, 215, 199, 0.10);

  /* ── Semantic (success / warn / error) ──────────────────────────────── */
  --green: #46e08f;
  --yellow: #ffd166;
  --red: #ff6b6b;
  --success: var(--green);
  --warn: var(--yellow);
  --error: var(--red);
  --ok-bg: rgba(70, 224, 143, 0.14);
  --warn-bg: rgba(255, 209, 102, 0.14);
  --bad-bg: rgba(255, 107, 107, 0.16);
  --ok-border: rgba(70, 224, 143, 0.35);
  --warn-border: rgba(255, 209, 102, 0.35);
  --bad-border: rgba(255, 107, 107, 0.38);
  --ok-text: #7bf0b0;
  --warn-text: #ffde8a;
  --bad-text: #ff9a9a;

  /* ── Oscilloscope trace palette (phosphor: cyan/amber/magenta/green) ─── */
  --trace-tilt: #46e08f;
  --trace-p: #4fd6e0;
  --trace-i: #ffd166;
  --trace-d: #e06bd0;
  --trace-grid: #2a3446;
  --trace-fault: #ff5d5d;

  /* ── Button surfaces (tokenized — no bespoke gradients in component CSS) ── */
  --btn-accent-grad: linear-gradient(180deg, #2a1e05, #1b1303);
  --btn-accent-grad-hover: linear-gradient(180deg, #3a2a08, #241a05);
  --btn-go-grad: linear-gradient(180deg, #16482f, #0f3624);
  --btn-go-grad-hover: linear-gradient(180deg, #1c5c3b, #14472e);

  /* ── Glass / instrument panel system ────────────────────────────────── */
  --glass-bg: linear-gradient(180deg, rgba(255,255,255,0.028), rgba(255,255,255,0.006));
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: saturate(140%) blur(14px);
  /* the inset top highlight is what reads as a lit glass-panel edge */
  --edge-hi: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --edge-lo: inset 0 -1px 0 rgba(0, 0, 0, 0.35);

  /* ── Typography ─────────────────────────────────────────────────────── */
  /* families */
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  --display: "Clash Display", "Space Grotesk", "Inter", system-ui, sans-serif; /* product frame / headers */
  --heading: "Space Grotesk", "Inter", system-ui, sans-serif;                  /* section titles */

  /* modular scale (~1.22 ratio, 13px base) — legacy names retuned + extended */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --fs-2xl: 27px;
  --fs-3xl: 36px;
  --fs-4xl: 46px;

  /* line-heights */
  --lh-tight: 1.15;
  --lh-snug: 1.3;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;

  /* weights */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* tracking */
  --ls-tight: -0.01em;
  --ls-normal: 0;
  --ls-wide: 0.04em;
  --ls-wider: 0.08em;
  --ls-caps: 0.14em;   /* uppercase eyebrows / instrument labels */

  /* composed roles (font shorthand: weight size/line-height family) */
  --type-display: var(--fw-bold) var(--fs-3xl)/var(--lh-tight) var(--display);
  --type-heading: var(--fw-semibold) var(--fs-xl)/var(--lh-snug) var(--heading);
  --type-title:   var(--fw-semibold) var(--fs-lg)/var(--lh-snug) var(--heading);
  --type-body:    var(--fw-regular) var(--fs-md)/var(--lh-normal) var(--ui);
  --type-mono:    var(--fw-medium) var(--fs-sm)/var(--lh-normal) var(--mono);
  --type-caption: var(--fw-medium) var(--fs-xs)/var(--lh-snug) var(--ui);

  /* ── Spacing (4px grid) ─────────────────────────────────────────────── */
  --sp-0: 2px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 56px;
  --sp-10: 72px;

  /* ── Radius ─────────────────────────────────────────────────────────── */
  --r-xs: 3px;
  --r-sm: 4px;
  --r: 6px;
  --r-lg: 8px;
  --r-xl: 12px;
  --r-pill: 999px;

  /* ── Elevation / shadow ─────────────────────────────────────────────── */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px var(--accent-glow);          /* accent bloom halo */
  --shadow-glow-cy: 0 0 24px var(--secondary-glow);    /* instrument glow */

  /* ── Focus ring / hairlines ─────────────────────────────────────────── */
  --ring: 0 0 0 1px var(--border);              /* resting hairline */
  --ring-accent: 0 0 0 2px var(--accent-glow);  /* focus glow */
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-glow); /* offset keyboard ring */

  /* ── Motion — durations are perceptual tiers, eases named by intent ──── */
  --t-instant: 0.09s;   /* press feedback, taps */
  --t-fast: 0.15s;      /* hover, small state */
  --t-med: 0.25s;       /* panels, toasts */
  --t-slow: 0.4s;       /* hero / phase change */
  --t-slower: 0.6s;     /* upload→drive reveal */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);          /* decelerate — entrances */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);      /* symmetric — moves/reflows */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);   /* slight overshoot — pops */
  --ease-spring-lg: cubic-bezier(0.22, 1.4, 0.36, 1); /* bigger overshoot — celebratory */
  --ease-snap: cubic-bezier(0.5, 0, 0.1, 1);          /* quick in, firm settle — buttons */

  /* ── z-index scale (single source of truth for stacking) ────────────── */
  --z-base: 0;
  --z-decor: 1;        /* scene overlays, coach marks */
  --z-panel: 10;       /* docked inspector / rails */
  --z-sticky: 20;      /* topbar, sticky headers */
  --z-overlay: 100;    /* scrims / dimmers */
  --z-popover: 200;    /* menus, robot picker, tooltips-of-panels */
  --z-toast: 300;      /* transient notifications */
  --z-modal: 400;      /* dialogs, account/classroom */
  --z-tooltip: 500;    /* hover tooltips — always on top */
  --z-max: 9999;       /* fatal fallback */

  color-scheme: dark;
}

/* ══════════════════════════════════════════════════════════════════════
   LIGHT shell (the 3D canvas keeps its own scene lighting)
   ═══════════════════════════════════════════════════════════════════════ */
:root[data-theme="light"] {
  /* Neutral, low-glare desktop surfaces with AA text contrast. */
  --gray-1: #e9eaec;  --gray-2: #f7f7f5;  --gray-3: #ffffff;  --gray-4: #f0f1f2;
  --gray-5: #e5e7e9;  --gray-6: #d4d7da;  --gray-7: #bfc4c9;  --gray-8: #9fa6ae;
  --gray-9: #7f8791;  --gray-10: #68717c; --gray-11: #4e5660; --gray-12: #1b1e22;

  --bg: var(--gray-1);
  --panel: var(--gray-2);
  --panel-2: var(--gray-3);
  --panel-3: var(--gray-4);
  --panel-4: var(--gray-5);
  --overlay: rgba(20, 33, 61, 0.72);
  --overlay-strong: rgba(255, 255, 255, 0.97);
  --border: var(--gray-6);
  --border-2: var(--gray-7);
  --border-focus: var(--gray-8);
  --text: var(--gray-12);
  --text-dim: var(--gray-11);
  --text-faint: #667594;

  /* amber: bright hue kept for solid fills / 3D, burnt amber for text/icons (AA on white) */
  --accent: #245ea9;
  --accent-hover: #1d4f91;
  --accent-text: #1e559d;
  --amber-9: #ffc857;
  --accent-dim: #b8cbe4;
  --accent-glow: rgba(36, 94, 169, 0.20);
  --accent-soft: rgba(36, 94, 169, 0.08);

  /* secondary cyan: deepened so it stays legible on light surfaces */
  --secondary: #087e7b;
  --secondary-hover: #066b69;
  --secondary-text: #08706d;
  --secondary-dim: #b7ece7;
  --secondary-glow: rgba(8, 126, 123, 0.20);
  --secondary-soft: rgba(8, 126, 123, 0.09);

  --edge-hi: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  --edge-lo: inset 0 -1px 0 rgba(20, 33, 61, 0.08);
  --glass-bg: linear-gradient(180deg, rgba(255,255,255,0.90), rgba(246,248,255,0.76));
  --glass-border: rgba(91, 85, 231, 0.14);
  --glass-blur: saturate(120%) blur(12px);

  --btn-accent-grad: #245ea9;
  --btn-accent-grad-hover: #1d4f91;
  --btn-go-grad: #26734d;
  --btn-go-grad-hover: #1f6442;

  /* semantic: darker for AA on light */
  --green: #14803c;
  --yellow: #9a6700;
  --red: #cf222e;
  --success: var(--green);
  --warn: var(--yellow);
  --error: var(--red);
  --ok-bg: rgba(20, 128, 60, 0.12);
  --warn-bg: rgba(154, 103, 0, 0.12);
  --bad-bg: rgba(207, 34, 46, 0.12);
  --ok-border: rgba(20, 128, 60, 0.30);
  --warn-border: rgba(154, 103, 0, 0.30);
  --bad-border: rgba(207, 34, 46, 0.30);
  --ok-text: #0f6b31;
  --warn-text: #855a00;
  --bad-text: #b41b26;

  --shadow-1: 0 2px 5px rgba(42, 55, 98, 0.07);
  --shadow-2: 0 8px 22px rgba(42, 55, 98, 0.10);
  --shadow: 0 14px 34px rgba(42, 55, 98, 0.14);
  --shadow-lg: 0 30px 80px rgba(42, 55, 98, 0.22);
  --shadow-glow: 0 0 20px var(--accent-glow);
  --shadow-glow-cy: 0 0 20px var(--secondary-glow);
  --focus-ring: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent-glow);

  /* darker trace hues so the scope stays legible on the light HUD surface */
  --trace-tilt: #14803c;
  --trace-p: #0a7d8a;
  --trace-i: #9a6700;
  --trace-d: #a5359a;
  --trace-grid: #c2cad9;
  --trace-fault: #cf222e;

  color-scheme: light;
}

/* ══════════════════════════════════════════════════════════════════════
   Motion sensitivity: kill vestibular motion, keep safe opacity crossfades
   ═══════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* opacity fades are non-vestibular and still communicate state */
  .toast, #overlay, #tooltip { transition-duration: var(--t-fast) !important; }
}
