/* ============================================================================
 * tokens.css — jayhoonworlds design tokens (v3, "threshold engine")
 *
 * Three layers, in this order, and nothing skips a layer:
 *   1. PRIMITIVE  raw values, no meaning. Only this layer may hold a literal.
 *   2. SEMANTIC   role names that components are allowed to reference.
 *   3. COMPONENT  per-component aliases, only where a component needs its own
 *                 decision that a semantic token would distort.
 *
 * Direction: the page is a place. One cosmos, re-lit by the scene; diegetic
 * instruments instead of website chrome; each world owns its palette.
 * Rule: a component rule references a token, never a raw value — the scene
 *         tokens below are what make that possible across four palettes.
 * ==========================================================================*/

:root {
  /* ── 1. PRIMITIVE ──────────────────────────────────────────────────────── */
  /* The void: the ground of every scene before a world lights it. */
  --c-void-950: oklch(7.5% 0.010 265);
  --c-void-900: oklch(9.5% 0.012 265);
  --c-void-800: oklch(12.5% 0.014 265);
  --c-void-700: oklch(17% 0.016 265);
  --c-void-600: oklch(24% 0.016 265);

  /* Instrument ink: warm off-white, read at 11–18px. */
  --c-paper-100: oklch(96% 0.008 82);
  --c-paper-200: oklch(90% 0.010 82);
  --c-paper-300: oklch(80% 0.012 82);
  --c-paper-400: oklch(68% 0.012 82);
  --c-paper-500: oklch(56% 0.012 82);

  /* The system's own light. Never a world's accent. */
  --c-gold-600: oklch(72% 0.105 82);
  --c-gold-500: oklch(79% 0.100 84);
  --c-gold-200: oklch(92% 0.040 84);

  /* World palettes — sampled from the artwork each one carries. */
  --c-scream-black: oklch(7% 0.004 20);
  --c-scream-bone: oklch(92% 0.012 80);
  --c-scream-blood: oklch(45% 0.17 22);
  --c-scream-smoke: oklch(58% 0.008 60);

  --c-summer-sun: oklch(88% 0.045 80);
  --c-summer-haze: oklch(94% 0.030 84);
  --c-summer-foliage: oklch(52% 0.055 130);
  --c-summer-ink: oklch(22% 0.018 70);
  --c-summer-paper: oklch(94% 0.020 84);

  --c-ooo-sky: oklch(85% 0.055 230);
  --c-ooo-meadow: oklch(80% 0.105 140);
  --c-ooo-sand: oklch(90% 0.070 88);
  --c-ooo-candy: oklch(76% 0.130 0);
  --c-ooo-ink: oklch(29% 0.045 280);

  /* Space: 4px base, declared steps only. */
  --space-unit: 4px;
  --space-1: calc(var(--space-unit) * 1);
  --space-2: calc(var(--space-unit) * 2);
  --space-3: calc(var(--space-unit) * 3);
  --space-4: calc(var(--space-unit) * 4);
  --space-5: calc(var(--space-unit) * 5);
  --space-6: calc(var(--space-unit) * 6);
  --space-8: calc(var(--space-unit) * 8);
  --space-10: calc(var(--space-unit) * 10);
  --space-12: calc(var(--space-unit) * 12);
  --space-16: calc(var(--space-unit) * 16);
  --space-20: calc(var(--space-unit) * 20);
  --space-24: calc(var(--space-unit) * 24);

  /* Type: three voices with one job each, plus the world's own. */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-prose: 'Cormorant Garamond', Georgia, serif;
  --font-toon: 'Bubblegum Sans', 'Comic Sans MS', cursive;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-3xs: 0.625rem;   /* 10 — hairlines of apparatus */
  --text-2xs: 0.6875rem;  /* 11 — instrument labels */
  --text-xs: 0.75rem;     /* 12 — readouts */
  --text-sm: 0.8125rem;   /* 13 — controls */
  --text-base: 1rem;      /* 16 — premise */
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --text-3xl: clamp(2.25rem, 1.4rem + 2.6vw, 3.5rem);
  --text-logo: clamp(3.25rem, 7.4vw, 6.75rem);

  --leading-tight: 1.02;
  --leading-snug: 1.25;
  --leading-normal: 1.55;
  --leading-prose: 1.72;

  --tracking-tight: -0.02em;
  --tracking-caps: 0.18em;
  --tracking-wide: 0.34em;
  --tracking-normal: 0;

  --weight-light: 300;
  --weight-regular: 400;
  --weight-medium: 500;

  /* Shape: rings and apertures. A rectangle is a frame, never a card. */
  --radius-none: 0;
  --radius-hairline: 1px;
  --radius-sticker: 10px;
  --border-w-hairline: 1px;
  --border-w-strong: 2px;

  /* Motion: scene-scale durations, one easing per job. */
  --dur-fast: 140ms;
  --dur-base: 260ms;
  --dur-slow: 520ms;
  --dur-scene: 760ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-scene: cubic-bezier(0.66, 0, 0.2, 1);
  --ease-toon: cubic-bezier(0.2, 1.5, 0.4, 1);

  --page-max: 1440px;
  --page-gutter: clamp(var(--space-4), 3.4vw, var(--space-12));
  --measure-prose: 34rem;
  --bar-height: 40px;
  --colophon-height: 46px;

  --control-sm: 32px;
  --control-md: 44px;
  --control-lg: 48px;

  /* One bitmap grain, layered by every scene. Kept as a token so the recipe
     lives in one place instead of being re-typed per surface. */
  --noise: 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='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");

  /* ── 2. SEMANTIC ───────────────────────────────────────────────────────── */
  --surface-page: var(--c-void-950);
  --surface-raised: var(--c-void-800);
  --surface-sunken: var(--c-void-950);

  --text-primary: var(--c-paper-100);
  --text-secondary: var(--c-paper-300);
  --text-muted: var(--c-paper-400);
  --text-faint: var(--c-paper-500);
  --text-inverse: var(--c-void-950);

  --border-subtle: oklch(100% 0 0 / 0.12);
  --border-default: oklch(100% 0 0 / 0.22);

  --accent: var(--c-gold-600);
  --accent-hover: var(--c-gold-500);
  --accent-tint: var(--c-gold-200);
  --on-accent: var(--c-void-950);

  --focus-ring: var(--c-gold-500);
  --focus-ring-width: 2px;
  --focus-ring-offset: 3px;

  /* Scene roles — remapped by [data-scene]. Components read these, never a
     world palette directly, so a new scene only needs a remap. */
  --scene-bg: var(--c-void-950);
  --scene-glow: oklch(60% 0.08 265 / 0.30);
  --scene-ink: var(--c-paper-100);
  --scene-dim: var(--c-paper-300);
  --scene-faint: var(--c-paper-400);
  --scene-accent: var(--c-gold-600);
  --scene-rule: oklch(100% 0 0 / 0.14);
  --scene-panel: oklch(11% 0.012 265 / 0.72);
  --scene-particle: oklch(88% 0.03 84);
  --scene-title: var(--font-display);

  /* ── 3. COMPONENT ──────────────────────────────────────────────────────── */
  --button-height: var(--control-md);
  --button-pad-x: var(--space-5);
  --instrument-color: var(--scene-faint);
  --ring-size: 58px;
  --portal-ring: 74px;
  --z-stage: 0;
  --z-scene: 10;
  --z-chrome: 60;
  --z-panel: 80;
  --z-veil: 200;
  --z-skip: 400;
}

/* Scene remaps. Each world lights the same engine with its own palette. */
[data-scene='scream'] {
  --scene-bg: var(--c-scream-black);
  --scene-ink: var(--c-scream-bone);
  --scene-dim: oklch(80% 0.008 70);
  --scene-faint: var(--c-scream-smoke);
  --scene-accent: var(--c-scream-blood);
  --scene-rule: oklch(92% 0.012 80 / 0.16);
  --scene-glow: oklch(45% 0.17 22 / 0.22);
  --scene-particle: oklch(70% 0.01 60);
  --scene-panel: oklch(7% 0.004 20 / 0.82);
}

[data-scene='summer'] {
  --scene-bg: var(--c-summer-haze);
  --scene-ink: var(--c-summer-ink);
  --scene-dim: oklch(38% 0.020 70);
  --scene-faint: oklch(46% 0.020 70);
  --scene-accent: oklch(42% 0.075 55);
  --scene-rule: oklch(22% 0.018 70 / 0.22);
  --scene-glow: oklch(88% 0.045 80 / 0.55);
  --scene-particle: oklch(98% 0.02 90);
  --scene-panel: oklch(94% 0.020 84 / 0.86);
}

[data-scene='adventure'] {
  --scene-bg: var(--c-ooo-sky);
  --scene-ink: var(--c-ooo-ink);
  --scene-dim: oklch(42% 0.045 280);
  --scene-faint: oklch(50% 0.040 280);
  --scene-accent: var(--c-ooo-candy);
  --scene-rule: oklch(29% 0.045 280 / 0.25);
  --scene-glow: oklch(90% 0.070 88 / 0.65);
  --scene-particle: oklch(100% 0 0);
  --scene-panel: oklch(96% 0.020 90 / 0.92);
  --scene-title: var(--font-toon);
}

[data-scene='arcade'] {
  --scene-bg: oklch(8% 0.012 300);
  --scene-glow: oklch(50% 0.12 320 / 0.25);
  --scene-accent: var(--c-gold-500);
  --scene-panel: oklch(10% 0.012 300 / 0.82);
}

[data-scene='map'] {
  --scene-bg: oklch(8% 0.014 275);
  --scene-glow: oklch(56% 0.09 275 / 0.32);
}

/* Lights up: the void lifts, the instrument ink warms. A world's palette is
   never touched — the lights belong to the engine, not to the realities. */
html[data-shell='day'] {
  --scene-bg: oklch(17.5% 0.016 265);
  --c-void-950: oklch(17.5% 0.016 265);
  --scene-glow: oklch(74% 0.055 84 / 0.26);
  --scene-rule: oklch(100% 0 0 / 0.18);
  --scene-panel: oklch(20% 0.014 265 / 0.78);
}
html[data-shell='day'] .stage__vignette { opacity: 0.5; }
html[data-shell='day'] .stage__grain { opacity: 0.06; }

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--scene-bg);
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--scene-bg);
  color: var(--scene-ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-scene) var(--ease-out), color var(--dur-scene) var(--ease-out);
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

:where(a, button, input, select, textarea) { font: inherit; color: inherit; }
img { display: block; max-width: 100%; height: auto; }
button { background: none; border: 0; padding: 0; }
a { color: inherit; text-underline-offset: 0.22em; }
h1, h2, h3, p, ul, ol, figure, blockquote { margin: 0; }

@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;
  }
}
