/*
  ZonePulse design tokens — the single source of truth for colour.

  Every surface reads from here:
    - the React app imports it (src/index.css maps Tailwind's theme onto it),
    - the static pages in public/ link it (<link rel="stylesheet" href="/tokens.css">),
    - canvas/chart code resolves it at runtime (public/zp-tokens.js, src/lib/tokens.ts).

  The green and red scales are the logo's own colours, taken from
  brand/zonepulse-brand.html (demand green #57B92F, supply red #F43F5E and
  the gradient stops around them). Steps marked "interp." are interpolated
  between two logo stops to fill the scale. Neutrals are the app's existing
  dark-terminal greys. Amber and blue are data accents the logo doesn't
  carry (EMA line, institutional zones, warnings, info).

  Use the semantic tokens in UI code: they are the only ones that change
  with the theme. Reach for a primitive only for decorative work that should
  look the same in both themes (gradients, glows, the logo sweep).

  Themes: public/zp-theme.js sets <html data-theme="dark|light"> before the
  first paint (from the saved choice, or the device setting when the choice
  is "system"). Dark is the fallback if the script never runs. Every
  semantic token must be defined in BOTH theme blocks below.

  Light-theme contrast: the logo green (#6BDB3A) is about 2:1 on white, so
  on light grounds text-bearing tokens (brand, demand, links, warning, info)
  move to the darker steps of the same scale; filled buttons keep the
  bright gradient with dark ink on top.
*/
:root {

  /* ---------- Primitives: green (the logo's demand half) ---------- */
  --zp-green-100: #D4FF9E; /* bright edge highlight */
  --zp-green-200: #C6FF8A; /* gradient tip */
  --zp-green-300: #9CF56A; /* "Zone" lettering, top */
  --zp-green-400: #6BDB3A; /* main fill */
  --zp-green-500: #57B92F; /* "Zone" lettering, base — demand */
  --zp-green-600: #3FAE22; /* gradient root */
  --zp-green-700: #2B7E19; /* interp.; light-theme text green, 4.6:1 on every light surface */
  --zp-green-800: #1E5A14; /* deep fold */
  --zp-green-900: #12300D; /* interp. */
  --zp-green-950: #04140A; /* shadow ink — text on green */

  /* ---------- Primitives: red (the logo's supply half) ---------- */
  --zp-red-200: #FFB3BE; /* interp. — light red text on dark */
  --zp-red-300: #FF8096; /* interp. */
  --zp-red-400: #FF4D6D; /* gradient tip */
  --zp-red-500: #F43F5E; /* supply */
  --zp-red-600: #D91E4E;
  --zp-red-650: #D41D4C; /* interp.; light-theme text red, 4.6:1 on every light surface */
  --zp-red-700: #A1173C;
  --zp-red-800: #5A1020;
  --zp-red-900: #2E0911; /* interp. */
  --zp-red-950: #1A0408; /* interp. — text on red */

  /* ---------- Primitives: navy ("Pulse" lettering on light grounds) ---------- */
  --zp-navy-900: #0B1220;

  /* ---------- Primitives: neutral ---------- */
  /* Neutrals lean slightly blue ("ink navy"), so dark grounds read deep and
     calm rather than flat grey. */
  --zp-white: #FFFFFF;
  --zp-gray-25: #F4F6F8;   /* light theme page */
  --zp-gray-50: #F7F8FA;   /* light theme raised surface */
  --zp-gray-75: #EDF0F3;   /* light theme strong surface (selected, hover) */
  --zp-gray-100: #EDF1F5;  /* dark theme text */
  --zp-gray-150: #E2E6EB;  /* light theme hairline */
  --zp-gray-200: #D5DBE2;  /* dark theme body text */
  --zp-gray-250: #C9D0D9;  /* light theme strong border */
  --zp-gray-300: #B9C2CD;
  --zp-gray-400: #A9B3C0;  /* dark theme muted text */
  --zp-gray-500: #96A0AE;
  --zp-gray-550: #8792A1;  /* dark-theme subtle text, 5.7:1 on every dark surface */
  --zp-gray-600: #6A7585;
  --zp-gray-625: #5B6676;  /* light-theme subtle text, 5.4:1 on every light surface */
  --zp-gray-650: #465264;  /* light theme muted text */
  --zp-gray-700: #2C3A4C;
  --zp-gray-750: #243142;
  --zp-gray-800: #1C2734;
  --zp-gray-850: #16202D;  /* dark theme strong surface (selected, hover) */
  --zp-gray-900: #101822;  /* dark theme raised surface */
  --zp-gray-925: #0B1119;  /* dark theme surface */
  --zp-gray-950: #080C13;
  --zp-gray-975: #05080D;  /* dark theme page */

  /* ---------- Primitives: porcelain (light theme) ----------
     A cool, blue-tinted "porcelain" ladder for the light theme. It sits
     between white (glare) and mid-grey (dull): the page is a soft periwinkle
     mist, cards lift a clear step lighter, inputs a step darker than cards.
     Ink is a deep slate rather than black. */
  --zp-porcelain-50: #ECF0F6; /* dialogs, popovers */
  --zp-porcelain-100: #E9EEF5; /* cards, panels */
  --zp-porcelain-150: #E0E6EF; /* inputs, nested panels */
  --zp-porcelain-200: #D8DFEA; /* page */
  --zp-porcelain-250: #CDD6E3; /* selected rows, segmented thumbs */
  --zp-porcelain-300: #C0CADA; /* borders */
  --zp-porcelain-400: #A8B5C8; /* strong borders */
  --zp-slate-650: #3A465A; /* muted text */
  --zp-slate-600: #465366; /* subtle text */
  --zp-slate-800: #243042; /* body text */
  --zp-slate-900: #121A28; /* headings */
  --zp-wash-blue: #A6BCF0; /* page wash, top left */
  --zp-wash-mint: #ADE2C3; /* page wash, top right */
  --zp-green-750: #1D5C10; /* light-theme text green */
  --zp-red-675: #9C1236; /* light-theme text red */
  --zp-amber-750: #6A4300; /* light-theme warning text */
  --zp-blue-650: #134C95; /* light-theme info text */

  /* ---------- Primitives: data accents ---------- */
  --zp-green-350: #8AE85B; /* top of the action-button gradient */
  --zp-green-450: #7BD957; /* demand text on dark */
  --zp-red-350: #FF7189;   /* supply text on dark */
  --zp-amber-200: #FFD58A;
  --zp-amber-300: #FFCF5C;
  --zp-amber-350: #F2B544; /* warning on dark */
  --zp-amber-400: #FFB84D;
  --zp-amber-600: #B8801F;
  --zp-amber-700: #8A5800; /* warning text on light */
  --zp-amber-900: #3A2A0A;
  --zp-teal-400: #2BC4A9;  /* second Ghost Fibers colour on dark */
  --zp-teal-700: #11806F;  /* second Ghost Fibers colour on light */
  --zp-blue-300: #7AB8FF;  /* info on dark */
  --zp-blue-400: #60A5FA;
  --zp-blue-600: #1A64C4;  /* info text on light */
}

/* ================= Foundations (same in both themes) =================
   Type, spacing, radius, motion and layering. Nothing here is a colour, so
   these live outside the theme blocks. Font-size tokens are --zp-fs-* (not
   --zp-text-*, which are the text colours). */
:root {
  /* Type: Inter for UI, JetBrains Mono for prices and codes (both loaded
     from Google Fonts; the fallbacks are close system fonts). */
  --zp-font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --zp-font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Headings and big numbers in hero areas: Sora gives ZonePulse its own voice. */
  --zp-font-display: "Sora", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  --zp-fs-2xs: 11px;  /* table heads, pills */
  --zp-fs-xs: 12px;   /* captions, hints */
  --zp-fs-sm: 13px;   /* dense UI, tables */
  --zp-fs-base: 14px; /* app body */
  --zp-fs-md: 16px;   /* marketing body, inputs on touch */
  --zp-fs-lg: 18px;   /* card titles */
  --zp-fs-xl: 22px;   /* page titles */
  --zp-fs-2xl: 28px;  /* stat values, section titles */
  --zp-fs-3xl: 36px;
  --zp-fs-4xl: clamp(36px, 5vw, 52px); /* hero */

  --zp-lh-tight: 1.2;
  --zp-lh-snug: 1.35;
  --zp-lh-normal: 1.55;
  --zp-tracking-tight: -0.015em; /* headings */
  --zp-tracking-display: -0.025em; /* Sora headings */
  --zp-tracking-caps: 0.05em;    /* uppercase labels */

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

  /* Radius */
  --zp-radius-xs: 6px;
  --zp-radius-sm: 9px;   /* chips, segmented thumbs */
  --zp-radius-md: 12px;  /* buttons, inputs */
  --zp-radius-lg: 18px;  /* cards */
  --zp-radius-xl: 22px;  /* dialogs, hero panels */
  --zp-radius-2xl: 26px; /* phone bottom sheets */
  --zp-radius-full: 999px;

  /* Control heights */
  --zp-control-sm: 32px;
  --zp-control-md: 40px;
  --zp-control-lg: 48px;

  /* Glass: blur strength (the tint is a theme token, --zp-glass) */
  --zp-glass-blur: 20px;

  /* Motion: one curve everywhere - a quick start and a long, soft landing.
     Only opacity and transform animate; reduced-motion turns it all off. */
  --zp-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --zp-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --zp-dur-fast: 160ms;   /* colour changes */
  --zp-dur-base: 250ms;   /* hover, press */
  --zp-dur-slow: 450ms;   /* dialogs, menus, sliding thumbs */
  --zp-dur-slower: 550ms; /* drawers and sheets */

  /* Theme previews (Settings → Appearance): fixed in both themes */
  --zp-preview-dark-bg: var(--zp-gray-975);
  --zp-preview-dark-surface: var(--zp-gray-850);
  --zp-preview-light-bg: var(--zp-porcelain-200);
  --zp-preview-light-surface: var(--zp-porcelain-300);

  /* Layering */
  --zp-z-sticky: 20;
  --zp-z-nav: 40;
  --zp-z-drawer: 45;
  --zp-z-modal: 50;
  --zp-z-toast: 60;
}

/* ================= Semantic tokens: dark (default) ================= */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces */
  --zp-bg: var(--zp-gray-975);
  --zp-bg-wash: none; /* soft colour glow painted over the page (light theme only) */
  --zp-surface: var(--zp-gray-925);         /* cards, panels, drawers */
  --zp-surface-raised: var(--zp-gray-900);  /* inputs, nested panels */
  --zp-surface-strong: var(--zp-gray-850);  /* selected rows, segmented thumbs */
  --zp-surface-overlay: var(--zp-gray-925); /* dialogs, popovers */
  --zp-border: var(--zp-gray-800);
  --zp-border-strong: var(--zp-gray-700);

  /* Translucent layers: hairlines and fills that sit on any surface */
  --zp-hairline: color-mix(in srgb, var(--zp-white) 7%, transparent);
  --zp-hairline-strong: color-mix(in srgb, var(--zp-white) 13%, transparent);
  --zp-fill-subtle: color-mix(in srgb, var(--zp-white) 3%, transparent);  /* hover rows */
  --zp-fill-muted: color-mix(in srgb, var(--zp-white) 6%, transparent);   /* neutral pills, hover */
  --zp-scrim: color-mix(in srgb, var(--zp-gray-975) 55%, transparent);    /* dialog backdrop */
  --zp-glass: color-mix(in srgb, var(--zp-gray-925) 74%, transparent);    /* frosted bars, dialogs, toasts */
  --zp-highlight: inset 0 1px 0 color-mix(in srgb, var(--zp-white) 4%, transparent); /* top edge light on cards */

  /* Elevation */
  --zp-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --zp-shadow-md: 0 12px 28px -12px rgba(0, 0, 0, 0.6);
  --zp-shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, 0.75);
  --zp-shadow-glow: 0 0 0 1px color-mix(in srgb, var(--zp-green-400) 30%, transparent), 0 6px 24px color-mix(in srgb, var(--zp-green-400) 18%, transparent);

  /* Text */
  --zp-text: var(--zp-gray-100);
  --zp-text-body: var(--zp-gray-200);
  --zp-text-muted: var(--zp-gray-400);
  --zp-text-subtle: var(--zp-gray-550);
  --zp-link: var(--zp-green-300);

  /* Brand */
  --zp-brand: var(--zp-green-400);
  --zp-brand-strong: var(--zp-green-500);
  --zp-brand-soft: var(--zp-green-300);     /* links, accents */
  --zp-on-brand: var(--zp-green-950);
  --zp-gradient-brand: linear-gradient(135deg, var(--zp-green-500), var(--zp-green-300));
  /* Primary action buttons: a vertical green gradient with a soft glow */
  --zp-gradient-action: linear-gradient(180deg, var(--zp-green-350), var(--zp-green-500));
  --zp-on-action: var(--zp-green-950);
  --zp-action-sheen: color-mix(in srgb, var(--zp-green-100) 60%, transparent); /* light sweep across action buttons */
  --zp-shadow-action: 0 0 0 1px color-mix(in srgb, var(--zp-green-400) 35%, transparent), 0 10px 28px -10px color-mix(in srgb, var(--zp-green-400) 60%, transparent);
  --zp-shadow-action-hover: 0 0 0 1px color-mix(in srgb, var(--zp-green-400) 55%, transparent), 0 14px 32px -8px color-mix(in srgb, var(--zp-green-400) 65%, transparent);
  /* The logo's signature red-to-green sweep */
  --zp-gradient-pulse: linear-gradient(90deg, var(--zp-red-400), var(--zp-red-500) 42%, var(--zp-red-600) 55%, var(--zp-green-600) 65%, var(--zp-green-400));
  --zp-focus-ring: color-mix(in srgb, var(--zp-green-400) 60%, transparent);

  /* Market meaning */
  --zp-demand: var(--zp-green-450);
  --zp-supply: var(--zp-red-350);

  /* Status */
  --zp-success: var(--zp-green-400);
  --zp-danger: var(--zp-red-350);
  --zp-on-danger: var(--zp-red-950);
  --zp-warning: var(--zp-amber-350);
  --zp-info: var(--zp-blue-300);

  /* Animated backgrounds (canvas / WebGL) */
  --zp-decor-up: var(--zp-green-400);
  --zp-decor-down: var(--zp-red-500);
  --zp-decor-ink: var(--zp-gray-50);
  --zp-decor-grid: var(--zp-gray-500);
  --zp-fiber-a: var(--zp-green-400);
  --zp-fiber-b: var(--zp-teal-400);

  /* Tinted backgrounds for pills and badges */
  --zp-brand-tint: color-mix(in srgb, var(--zp-brand) 12%, transparent);
  --zp-demand-tint: color-mix(in srgb, var(--zp-green-500) 14%, transparent);
  --zp-supply-tint: color-mix(in srgb, var(--zp-red-500) 14%, transparent);
  --zp-warning-tint: color-mix(in srgb, var(--zp-warning) 14%, transparent);
  --zp-info-tint: color-mix(in srgb, var(--zp-info) 12%, transparent);
  --zp-neutral-tint: color-mix(in srgb, var(--zp-gray-300) 12%, transparent);
}

/* ================= Semantic tokens: light ================= */
:root[data-theme="light"] {
  color-scheme: light;

  /* Porcelain: misty page, cards one step lighter, nothing pure white. */
  --zp-bg: var(--zp-porcelain-200);
  --zp-bg-wash:
    radial-gradient(900px 520px at 0% -10%, color-mix(in srgb, var(--zp-wash-blue) 75%, transparent), transparent 70%),
    radial-gradient(800px 480px at 100% -10%, color-mix(in srgb, var(--zp-wash-mint) 65%, transparent), transparent 70%);
  --zp-surface: var(--zp-porcelain-100);
  --zp-surface-raised: var(--zp-porcelain-150);
  --zp-surface-strong: var(--zp-porcelain-250);
  --zp-surface-overlay: var(--zp-porcelain-50);
  --zp-border: var(--zp-porcelain-300);
  --zp-border-strong: var(--zp-porcelain-400);

  --zp-hairline: color-mix(in srgb, var(--zp-slate-900) 9%, transparent);
  --zp-hairline-strong: color-mix(in srgb, var(--zp-slate-900) 16%, transparent);
  --zp-fill-subtle: color-mix(in srgb, var(--zp-slate-900) 3.5%, transparent);
  --zp-fill-muted: color-mix(in srgb, var(--zp-slate-900) 6%, transparent);
  --zp-scrim: color-mix(in srgb, var(--zp-slate-900) 30%, transparent);
  --zp-glass: color-mix(in srgb, var(--zp-porcelain-100) 76%, transparent);
  --zp-highlight: inset 0 1px 0 color-mix(in srgb, var(--zp-white) 55%, transparent);

  /* Soft, cool-tinted shadows give cards depth instead of bright edges. */
  --zp-shadow-sm: 0 1px 2px rgba(19, 27, 42, 0.07);
  --zp-shadow-md: 0 14px 30px -16px rgba(30, 45, 80, 0.22), 0 1px 2px rgba(19, 27, 42, 0.05);
  --zp-shadow-lg: 0 32px 64px -24px rgba(30, 45, 80, 0.32), 0 1px 2px rgba(19, 27, 42, 0.05);
  --zp-shadow-glow: 0 0 0 1px color-mix(in srgb, var(--zp-green-700) 35%, transparent), 0 6px 20px color-mix(in srgb, var(--zp-green-700) 16%, transparent);

  --zp-text: var(--zp-slate-900);
  --zp-text-body: var(--zp-slate-800);
  --zp-text-muted: var(--zp-slate-650);
  --zp-text-subtle: var(--zp-slate-600);
  --zp-link: var(--zp-green-750);

  --zp-brand: var(--zp-green-750);
  --zp-brand-strong: var(--zp-green-800);
  --zp-brand-soft: var(--zp-green-750);
  --zp-on-brand: var(--zp-white);
  --zp-gradient-brand: linear-gradient(135deg, var(--zp-green-700), var(--zp-green-500));
  /* Deep emerald buttons with white ink: rich, and calm on a light page. */
  --zp-gradient-action: linear-gradient(180deg, var(--zp-green-700), var(--zp-green-800));
  --zp-on-action: var(--zp-white);
  --zp-action-sheen: color-mix(in srgb, var(--zp-white) 28%, transparent); /* light sweep across action buttons */
  --zp-shadow-action: 0 0 0 1px color-mix(in srgb, var(--zp-green-800) 45%, transparent), 0 10px 24px -12px color-mix(in srgb, var(--zp-green-800) 60%, transparent);
  --zp-shadow-action-hover: 0 0 0 1px color-mix(in srgb, var(--zp-green-800) 60%, transparent), 0 14px 28px -10px color-mix(in srgb, var(--zp-green-800) 65%, transparent);
  --zp-gradient-pulse: linear-gradient(90deg, var(--zp-red-400), var(--zp-red-500) 42%, var(--zp-red-600) 55%, var(--zp-green-600) 65%, var(--zp-green-400));
  --zp-focus-ring: color-mix(in srgb, var(--zp-green-700) 50%, transparent);

  --zp-demand: var(--zp-green-750);
  --zp-supply: var(--zp-red-675);

  --zp-success: var(--zp-green-750);
  --zp-danger: var(--zp-red-675);
  --zp-on-danger: var(--zp-white);
  --zp-warning: var(--zp-amber-750);
  --zp-info: var(--zp-blue-650);

  --zp-decor-up: var(--zp-green-600);
  --zp-decor-down: var(--zp-red-500);
  --zp-decor-ink: var(--zp-slate-900);
  --zp-decor-grid: var(--zp-gray-600);
  --zp-fiber-a: var(--zp-green-600);
  --zp-fiber-b: var(--zp-teal-700);

  --zp-brand-tint: color-mix(in srgb, var(--zp-brand) 10%, transparent);
  --zp-demand-tint: color-mix(in srgb, var(--zp-demand) 10%, transparent);
  --zp-supply-tint: color-mix(in srgb, var(--zp-supply) 8%, transparent);
  --zp-warning-tint: color-mix(in srgb, var(--zp-amber-400) 20%, transparent);
  --zp-info-tint: color-mix(in srgb, var(--zp-info) 9%, transparent);
  --zp-neutral-tint: color-mix(in srgb, var(--zp-slate-650) 10%, transparent);
}

/*
  Theme-specific images, e.g. the wordmark, whose "Pulse" lettering is white
  on dark and navy on light. Put both <img>s in the markup:
    <img class="zp-only-dark" src="zonepulse-wordmark.png">
    <img class="zp-only-light" src="zonepulse-wordmark-light.png">
*/
:root[data-theme="light"] .zp-only-dark,
:root:not([data-theme="light"]) .zp-only-light {
  display: none !important;
}
