/* ============================================================================
   theme.css — design tokens, reset, motion, light/dark themes
   ============================================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
input, select, textarea { background: transparent; border: 0; }
::placeholder { color: var(--text-muted); }

:root {
  /* ---------- Typography ---------- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 30px;
  --fs-4xl: 36px;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* ---------- Spacing ---------- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* ---------- Radii ---------- */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* ---------- Motion ---------- */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
  --t-fast: 120ms;
  --t-std: 200ms;
  --t-slow: 320ms;

  /* ---------- Layout ---------- */
  --topbar-h: 64px;
  --subnav-h: 48px;
  --content-max: 1440px;

  /* ---------- Accent (theme-invariant brand) ---------- */
  --accent: #6366f1;          /* indigo-500 */
  --accent-strong: #4f46e5;   /* indigo-600 */
  --accent-soft: #eef2ff;     /* indigo-50 */
  --accent-grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --accent-ring: rgba(99, 102, 241, .35);

  /* ---------- Status ---------- */
  --success: #10b981;
  --success-soft: #d1fae5;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --info: #0ea5e9;
  --info-soft: #e0f2fe;
}

/* ---------- Light theme (default) ---------- */
:root,
[data-theme='light'] {
  color-scheme: light;

  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-soft: #f4f4f5;
  --bg-glass: rgba(255, 255, 255, .72);
  --bg-overlay: rgba(24, 24, 27, .42);

  --surface: #ffffff;
  --surface-hover: #fafafa;
  --surface-pressed: #f4f4f5;

  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-subtle: #f4f4f5;

  --text: #18181b;
  --text-strong: #09090b;
  --text-muted: #71717a;
  --text-subtle: #a1a1aa;
  --text-inverse: #fafafa;

  --accent-soft: #eef2ff;

  --shadow-xs: 0 1px 2px 0 rgba(24, 24, 27, .04);
  --shadow-sm: 0 1px 3px 0 rgba(24, 24, 27, .06), 0 1px 2px -1px rgba(24, 24, 27, .04);
  --shadow-md: 0 4px 6px -1px rgba(24, 24, 27, .07), 0 2px 4px -2px rgba(24, 24, 27, .04);
  --shadow-lg: 0 10px 15px -3px rgba(24, 24, 27, .08), 0 4px 6px -4px rgba(24, 24, 27, .04);
  --shadow-xl: 0 20px 25px -5px rgba(24, 24, 27, .10), 0 8px 10px -6px rgba(24, 24, 27, .04);
  --shadow-glass: 0 1px 0 0 rgba(24, 24, 27, .04), 0 8px 24px -12px rgba(24, 24, 27, .08);

  --skeleton-from: #f4f4f5;
  --skeleton-to: #e4e4e7;

  --tab-grad-from: rgba(99, 102, 241, .08);
  --tab-grad-to: rgba(139, 92, 246, .08);
}

/* ---------- Dark theme ---------- */
[data-theme='dark'] {
  color-scheme: dark;

  --bg: #09090b;
  --bg-elev: #18181b;
  --bg-soft: #18181b;
  --bg-glass: rgba(9, 9, 11, .72);
  --bg-overlay: rgba(0, 0, 0, .56);

  --surface: #18181b;
  --surface-hover: #27272a;
  --surface-pressed: #3f3f46;

  --border: #27272a;
  --border-strong: #3f3f46;
  --border-subtle: #1f1f22;

  --text: #e4e4e7;
  --text-strong: #fafafa;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --text-inverse: #09090b;

  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(99, 102, 241, .14);
  --accent-ring: rgba(129, 140, 248, .42);

  --success-soft: rgba(16, 185, 129, .14);
  --warn-soft: rgba(245, 158, 11, .14);
  --danger-soft: rgba(239, 68, 68, .14);
  --info-soft: rgba(14, 165, 233, .14);

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, .25);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, .35), 0 1px 2px -1px rgba(0, 0, 0, .25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, .45), 0 2px 4px -2px rgba(0, 0, 0, .25);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, .55), 0 4px 6px -4px rgba(0, 0, 0, .35);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, .60), 0 8px 10px -6px rgba(0, 0, 0, .35);
  --shadow-glass: 0 1px 0 0 rgba(255, 255, 255, .04), 0 8px 24px -12px rgba(0, 0, 0, .50);

  --skeleton-from: #27272a;
  --skeleton-to: #3f3f46;

  --tab-grad-from: rgba(129, 140, 248, .14);
  --tab-grad-to: rgba(167, 139, 250, .14);
}

/* ---------- Focus ring ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- Selection ---------- */
::selection {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ---------- Reduced motion ---------- */
@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;
  }
}

/* ---------- Scrollbars (subtle, themed) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-pill); border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: content-box; border: 2px solid transparent; }

/* ---------- Utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
[hidden] { display: none !important; }
.visually-hidden { @extend .sr-only; }

.text-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-strong { color: var(--text-strong); font-weight: var(--fw-semibold); }
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
