/*
 * Zag Store — Refraction design tokens
 *
 * Three layers:
 *   1. Primitives  — raw brand + neutral values. Same in both appearances.
 *   2. Semantic    — what templates and components use. Defined per appearance.
 *   3. Component   — named surfaces for specific components, built from semantic tokens.
 *
 * Rule: components never reference primitives or hex values directly.
 * The resolved appearance lives on <html data-theme="light|dark">, set before
 * first paint by the inline boot script in index.html.
 */

/* 1. Primitives ---------------------------------------------------------- */
:root {
  /* Brand spectrum (from the Zag Store Z and the existing landing page) */
  --zag-cyan-300: #5ff0ff;
  --zag-cyan-500: #13d5ed;
  --zag-cyan-700: #0891c9;
  --zag-blue-300: #8ea3ff;
  --zag-blue-500: #4777f8;
  --zag-blue-600: #3a5ce8;
  --zag-blue-700: #2f4fd6;
  --zag-magenta-300: #d36cf2;
  --zag-magenta-500: #bc44e5;
  --zag-magenta-700: #b02fd9;
  --zag-teal-500: #35cba5;
  --zag-teal-700: #0f9a7a;

  /* Pearl (light neutrals) */
  --pearl-0: #ffffff;
  --pearl-50: #f7f9fd;
  --pearl-100: #eef2f9;
  --pearl-200: #e1e7f3;
  --ink-900: #0f1729;
  --ink-700: #4a5670;
  --ink-600: #5d6782;

  /* Midnight (dark neutrals) */
  --midnight-1000: #03040a;
  --midnight-950: #05060c;
  --midnight-900: #0a0c17;
  --midnight-850: #0d1020;
  --midnight-800: #121628;
  --mist-50: #f3f5fb;
  --mist-300: #a9b0c6;
  --mist-500: #7f879f;

  /* Decorative brand gradient — never used for text */
  --spectrum-brand: linear-gradient(90deg, var(--zag-cyan-500), var(--zag-blue-500) 50%, var(--zag-magenta-500));

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --text-display: clamp(3.1rem, 7.6vw, 7.25rem);
  --text-h2: clamp(2.3rem, 5.2vw, 4.6rem);
  --text-h3: clamp(1.15rem, 1.6vw, 1.35rem);
  --text-lede: clamp(1.06rem, 1.35vw, 1.28rem);
  --text-body: 1rem;
  --text-small: 0.875rem;
  --text-eyebrow: 0.75rem;

  /* Shape + space */
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --radius-xl: 40px;
  --radius-pill: 999px;
  --gutter: clamp(16px, 4.5vw, 64px);
  --content-max: 1240px;

  /* Motion */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-refract: cubic-bezier(0.7, 0, 0.2, 1);
  --dur-fast: 180ms;
  --dur-base: 380ms;
  --dur-slow: 700ms;
}

/* 2. Semantic — Light ("Pearl") ------------------------------------------ */
:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg-canvas: #f7f9fd;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef2f9;

  --surface-glass: rgba(255, 255, 255, 0.62);
  --surface-glass-strong: rgba(255, 255, 255, 0.84);
  --glass-blur: 22px;
  --glass-saturate: 170%;

  --border-subtle: rgba(30, 48, 90, 0.10);
  --border-strong: rgba(30, 48, 90, 0.18);
  --edge-highlight: rgba(255, 255, 255, 0.95);

  --text-primary: #0f1729;
  --text-secondary: #4a5670;
  --text-tertiary: #5d6782;
  --text-on-accent: #ffffff;

  --accent-fill: #3a5ce8;
  --accent-fill-hover: #2f4fd6;
  --accent-text: #2f4fd6;
  --focus-ring: #3a5ce8;
  --status-live: #0f9a7a;

  /* Headline gradient: deeper stops so large text stays above 3:1 on pearl */
  --spectrum-1: #0891c9;
  --spectrum-2: #3a5ce8;
  --spectrum-3: #b02fd9;
  /* Lines + strokes */
  --line-1: #0fb5dd;
  --line-2: #4777f8;
  --line-3: #bc44e5;
  --line-glow: 0;

  /* Elevation = light lifts surfaces with shadow */
  --elevation-1: 0 1px 2px rgba(22, 34, 70, 0.06), 0 4px 14px rgba(22, 34, 70, 0.05);
  --elevation-2: 0 2px 6px rgba(22, 34, 70, 0.05), 0 14px 36px rgba(36, 56, 120, 0.10);
  --elevation-3: 0 6px 14px rgba(22, 34, 70, 0.05), 0 34px 90px rgba(46, 70, 150, 0.16);

  /* Atmosphere */
  --atmo-a: rgba(19, 213, 237, 0.17);
  --atmo-b: rgba(188, 68, 229, 0.13);
  --atmo-c: rgba(71, 119, 248, 0.10);
  --grid-line: rgba(52, 80, 140, 0.055);
  --grain-opacity: 0.035;

  /* Hero Z staging */
  --halo-core: rgba(255, 255, 255, 0.96);
  --halo-a: rgba(80, 210, 255, 0.24);
  --halo-b: rgba(214, 120, 255, 0.20);
  /* Z light: same values as the former drop-shadows (blur = shadow radius / 2) */
  --z-glow-near: rgba(38, 64, 160, 0.10);
  --z-glow-near-blur: 5px;
  --z-glow-near-y: 6px;
  --z-glow-far: rgba(38, 64, 160, 0.16);
  --z-glow-far-blur: 18px;
  --z-glow-far-y: 28px;
  --halo-ring: rgba(102, 136, 184, 0.12);
  --z-contact: rgba(58, 80, 200, 0.24);
  --z-floor: rgba(90, 120, 255, 0);

  --icon-plate: #eef1f7;
  --scrim: rgba(247, 249, 253, 0.72);

  --device-frame: #d9dee8;
  --device-edge: #ffffff;
  --app-bg: #f2f4f9;
  --app-surface: #ffffff;
  --app-text: #0f1729;
  --app-muted: #5d6782;
  --app-accent: #3a5ce8;
  --app-separator: rgba(15, 23, 41, 0.08);

  --btn-primary-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 10px 24px -10px rgba(58, 92, 232, 0.65);
  --btn-primary-shadow-hover: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 16px 34px -10px rgba(58, 92, 232, 0.72);
  --tile-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 8px 18px -8px rgba(22, 34, 70, 0.32);


  /* Cinematic stage (hero + finale) */
  --stage-core: rgba(255, 255, 255, 0.98);
  --stage-beam: rgba(150, 178, 255, 0.20);
  --stage-ring-opacity: 0.42;
  --reflect-opacity: 0.17;
  --horizon-opacity: 0.6;
  --caustic-a: rgba(19, 213, 237, 0.30);
  --caustic-b: rgba(222, 90, 255, 0.24);
  --caustic-c: rgba(58, 92, 232, 0.20);
  --contact-shadow: rgba(40, 60, 140, 0.20);

  /* Premium buttons: the primary inverts against the page */
  --btn-ink-bg: #0b0f1e;
  --btn-ink-text: #ffffff;
  --btn-ink-glow: rgba(255, 255, 255, 0.20);
  --btn-ink-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 1px 2px rgba(11, 15, 30, 0.2), 0 14px 30px -16px rgba(20, 30, 90, 0.6);
  --btn-ink-shadow-hover: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(11, 15, 30, 0.2), 0 22px 44px -18px rgba(40, 60, 200, 0.55);
  --btn-ghost-fill: rgba(255, 255, 255, 0.55);
  --btn-ghost-fill-hover: rgba(255, 255, 255, 0.9);
  --header-scrolled-bg: rgba(247, 249, 253, 0.72);

  --theme-color: #f7f9fd;
}

/* 2. Semantic — Dark ("Midnight") ---------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg-canvas: #05060c;
  --bg-elevated: #0d1020;
  --bg-sunken: #03040a;

  --surface-glass: rgba(18, 22, 40, 0.56);
  --surface-glass-strong: rgba(16, 19, 36, 0.82);
  --glass-blur: 24px;
  --glass-saturate: 150%;

  --border-subtle: rgba(160, 180, 255, 0.10);
  --border-strong: rgba(160, 180, 255, 0.20);
  --edge-highlight: rgba(255, 255, 255, 0.10);

  --text-primary: #f3f5fb;
  --text-secondary: #a9b0c6;
  --text-tertiary: #8a92aa;
  --text-on-accent: #ffffff;

  --accent-fill: #3a5ce8;
  --accent-fill-hover: #3352e0;
  --accent-text: #8ea3ff;
  --focus-ring: #8ea3ff;
  --status-live: #35cba5;

  --spectrum-1: #3fe0f5;
  --spectrum-2: #7b96ff;
  --spectrum-3: #d36cf2;
  --line-1: #3fe0f5;
  --line-2: #6f8dff;
  --line-3: #d36cf2;
  --line-glow: 1;

  /* Elevation = dark lifts surfaces with light, not shadow */
  --elevation-1: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(150, 170, 255, 0.07);
  --elevation-2: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px rgba(150, 170, 255, 0.09), 0 18px 50px rgba(0, 0, 0, 0.5);
  --elevation-3: inset 0 1px 0 rgba(255, 255, 255, 0.10), 0 0 0 1px rgba(150, 170, 255, 0.11), 0 30px 90px rgba(0, 0, 0, 0.6), 0 0 90px rgba(80, 110, 255, 0.12);

  --atmo-a: rgba(19, 213, 237, 0.11);
  --atmo-b: rgba(188, 68, 229, 0.14);
  --atmo-c: rgba(40, 60, 255, 0.17);
  --grid-line: rgba(140, 160, 255, 0.035);
  --grain-opacity: 0.07;

  --halo-core: rgba(60, 100, 255, 0.15);
  --halo-a: rgba(19, 213, 237, 0.22);
  --halo-b: rgba(214, 80, 255, 0.22);
  --z-glow-near: rgba(64, 110, 255, 0.30);
  --z-glow-near-blur: 17px;
  --z-glow-near-y: 0px;
  --z-glow-far: rgba(200, 70, 255, 0.14);
  --z-glow-far-blur: 40px;
  --z-glow-far-y: 0px;
  --halo-ring: rgba(150, 170, 255, 0.05);
  --z-contact: rgba(58, 80, 200, 0);
  --z-floor: rgba(90, 120, 255, 0.42);

  --icon-plate: #1a1e30;
  --scrim: rgba(5, 6, 12, 0.72);

  --device-frame: #1b1f2c;
  --device-edge: #3a4052;
  --app-bg: #000000;
  --app-surface: #15161c;
  --app-text: #f3f5fb;
  --app-muted: #8d93a6;
  --app-accent: #8ea3ff;
  --app-separator: rgba(255, 255, 255, 0.08);

  --btn-primary-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 0 0 1px rgba(142, 163, 255, 0.25), 0 10px 34px -8px rgba(70, 100, 255, 0.65);
  --btn-primary-shadow-hover: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 0 0 1px rgba(142, 163, 255, 0.5), 0 14px 46px -6px rgba(80, 110, 255, 0.9);
  --tile-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.06), 0 12px 30px -10px rgba(0, 0, 0, 0.75);


  --stage-core: rgba(64, 96, 255, 0.22);
  --stage-beam: rgba(120, 140, 255, 0.14);
  --stage-ring-opacity: 0.55;
  --reflect-opacity: 0.24;
  --horizon-opacity: 0.85;
  --caustic-a: rgba(19, 213, 237, 0.34);
  --caustic-b: rgba(214, 80, 255, 0.32);
  --caustic-c: rgba(58, 92, 255, 0.30);
  --contact-shadow: rgba(0, 0, 0, 0);

  --btn-ink-bg: #f3f5fc;
  --btn-ink-text: #070912;
  --btn-ink-glow: rgba(120, 150, 255, 0.30);
  --btn-ink-shadow: inset 0 -1px 0 rgba(10, 14, 40, 0.10), 0 0 0 1px rgba(255, 255, 255, 0.06), 0 14px 40px -18px rgba(120, 140, 255, 0.55);
  --btn-ink-shadow-hover: inset 0 -1px 0 rgba(10, 14, 40, 0.10), 0 0 0 1px rgba(255, 255, 255, 0.1), 0 20px 56px -18px rgba(130, 150, 255, 0.75);
  --btn-ghost-fill: rgba(255, 255, 255, 0.03);
  --btn-ghost-fill-hover: rgba(255, 255, 255, 0.08);
  --header-scrolled-bg: rgba(5, 6, 12, 0.66);

  --theme-color: #05060c;
}

/* Derived semantic tokens (resolve against whichever appearance is active) */
:root {
  --spectrum-text: linear-gradient(100deg, var(--spectrum-1) 0%, var(--spectrum-2) 52%, var(--spectrum-3) 100%);
}

/* 3. Component tokens ---------------------------------------------------- */
:root {
  --header-bg: var(--surface-glass);
  --header-border: var(--border-subtle);
  --card-bg: var(--bg-elevated);
  --card-border: var(--border-subtle);
  --card-shadow: var(--elevation-1);
  --panel-bg: var(--surface-glass-strong);
  --panel-shadow: var(--elevation-3);
  --btn-primary-bg: var(--accent-fill);
  --btn-primary-bg-hover: var(--accent-fill-hover);
  --btn-primary-text: var(--text-on-accent);
  --btn-ghost-bg: var(--surface-glass);
  --btn-ghost-border: var(--border-strong);
  --btn-ghost-text: var(--text-primary);
  --selector-track: var(--surface-glass);
  --selector-thumb: var(--bg-elevated);
  --chip-bg: var(--surface-glass);
}

/* Scoped appearances: lets one component show a fixed appearance (the Light
   and Dark phones in "Make it yours"), whatever the page appearance is. */
[data-force-theme="light"] {
  --device-frame: #d9dee8;
  --device-edge: #ffffff;
  --app-bg: #f2f4f9;
  --app-surface: #ffffff;
  --app-text: #0f1729;
  --app-muted: #5d6782;
  --app-accent: #3a5ce8;
  --app-separator: rgba(15, 23, 41, 0.08);
  --elevation-1: 0 1px 2px rgba(22, 34, 70, 0.06), 0 4px 14px rgba(22, 34, 70, 0.05);
  --device-shadow: 0 6px 14px rgba(22, 34, 70, 0.06), 0 40px 90px -20px rgba(46, 70, 150, 0.32);
}
[data-force-theme="dark"] {
  --device-frame: #1b1f2c;
  --device-edge: #3a4052;
  --app-bg: #000000;
  --app-surface: #15161c;
  --app-text: #f3f5fb;
  --app-muted: #8d93a6;
  --app-accent: #8ea3ff;
  --app-separator: rgba(255, 255, 255, 0.08);
  --elevation-1: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(150, 170, 255, 0.07);
  --device-shadow: 0 0 0 1px rgba(150, 170, 255, 0.08), 0 40px 90px -20px rgba(0, 0, 0, 0.7), 0 0 80px -10px rgba(80, 110, 255, 0.22);
}
