/* ==========================================================================
   tokens.css — DietPlanWithAI design tokens
   Single source of truth. Nothing else in the codebase hard-codes a colour.

   60 / 30 / 10 rule
     60%  dominant  : --bg, --bg-raised            (page + card surfaces)
     30%  secondary : --ink, --ink-soft, --surface-dark, --line
     10%  accent    : --accent, --accent-hot       (CTAs, active state, progress fills)

   Theming: [data-theme="dark"] on <html> flips the SAME variable names.
   Any element can carry data-theme to re-theme its own subtree (used by the
   side-by-side preview in styleguide.html), and .surface-dark re-maps the
   tokens inside a dark band so components keep working on dark sections.
   ========================================================================== */

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

  /* 60% — dominant */
  --bg: #F8F5EF;            /* warm ivory, never pure white */
  --bg-raised: #FFFFFF;     /* cards */

  /* 30% — secondary */
  --ink: #10231C;           /* primary text */
  --ink-soft: #3C564C;      /* secondary text */
  --surface-dark: #0B1A15;  /* dark band sections */
  --line: #E3DDD1;          /* decorative borders */

  /* 10% — accent */
  --accent: #C9A227;
  --accent-hot: #E0B63C;

  /* Functional — tiny amounts only */
  --success: #2E7D5B;
  --warn: #D98324;
  --danger: #C0453B;

  /* Fixed-value helpers (do NOT flip with the theme).
     These exist because text on gold / on a dark band must stay the same
     in both themes. They reuse the palette above — no new hues. */
  --on-accent: #10231C;     /* text on gold fills */
  --on-dark: #F3EEE3;       /* text on --surface-dark */
  --on-dark-soft: #A9BDB3;  /* secondary text on --surface-dark */
  --on-danger: #FFFFFF;     /* text on solid destructive buttons */

  /* Gold used AS TEXT.
     #C9A227 on ivory is only ~2.2:1, which fails AA even for large text.
     Gold stays a FILL colour; where a key number must be gold-toned on a
     light surface we use this deeper step of the same hue (≈5.5:1). */
  --accent-text: #7A5F08;

  --focus-ring: #10231C;

  --shadow-sm: 0 1px 2px rgba(16, 35, 28, .06);
  --shadow-md: 0 8px 24px -8px rgba(16, 35, 28, .12);
  --shadow-lg: 0 24px 60px -20px rgba(16, 35, 28, .22);
}

/* ---------- Colour: dark ---------- */
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0B1A15;
  --bg-raised: #12261E;

  --ink: #F3EEE3;
  --ink-soft: #B4C5BC;
  --surface-dark: #06100C;
  --line: #23382E;

  --accent: #C9A227;        /* gold already has strong contrast on forest */
  --accent-hot: #E0B63C;

  --success: #4DB68A;
  --warn: #E8A24D;
  --danger: #E5776D;

  --on-accent: #10231C;
  --on-dark: #F3EEE3;
  --on-dark-soft: #A9BDB3;
  --on-danger: #10231C;

  --accent-text: #E0B63C;
  --focus-ring: #E0B63C;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .65);
}

/* Re-theme any element that declares data-theme (not just <html>). */
[data-theme]:not(html) {
  background: var(--bg);
  color: var(--ink);
}

/* ---------- Dark band (works inside either theme) ---------- */
.surface-dark {
  --bg: var(--surface-dark);
  --bg-raised: color-mix(in srgb, var(--on-dark) 7%, var(--surface-dark));
  --ink: var(--on-dark);
  --ink-soft: var(--on-dark-soft);
  --line: color-mix(in srgb, var(--on-dark) 16%, var(--surface-dark));
  --accent-text: var(--accent-hot);
  --focus-ring: var(--accent-hot);
  --success: #4DB68A;
  --warn: #E8A24D;
  --danger: #E5776D;
  --on-danger: #10231C;
  background: var(--surface-dark);
  color: var(--on-dark);
}

/* ---------- Derived colours ----------
   Declared on every themed element (not just :root) so they are recomputed
   from THAT element's --ink / --bg-raised. Declaring them only on :root would
   freeze them at the light-theme values for nested data-theme / .surface-dark. */
:root,
[data-theme],
.surface-dark {
  --border-strong: color-mix(in srgb, var(--ink) 52%, var(--bg-raised)); /* ≥3:1 for form-control edges */
  --track: color-mix(in srgb, var(--ink) 12%, var(--bg-raised));         /* unfilled progress / slider track */
  --tint: color-mix(in srgb, var(--ink) 5%, var(--bg-raised));           /* subtle fills, placeholders */
  --accent-press: color-mix(in srgb, var(--accent) 86%, #000);
}

/* ---------- Everything that is theme-independent ---------- */
:root {
  /* Typography */
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "Inter Fallback", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --fs-h1: clamp(2.5rem, 6vw, 5.5rem);
  --fs-h2: clamp(2rem, 4vw, 3.5rem);
  --fs-h3: clamp(1.375rem, 2.5vw, 2rem);
  --fs-body: clamp(1rem, 1.1vw, 1.125rem);
  --fs-sm: .875rem;
  --fs-xs: .75rem;

  --lh-heading: 1.05;
  --lh-body: 1.65;
  --ls-heading: -0.02em;
  --measure: 68ch;

  /* Spacing — 8px base */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --sp-9: 96px;
  --sp-10: 128px;
  --sp-11: 160px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 24px;
  --r-pill: 999px;

  /* Layout */
  --container: min(1200px, 100% - 2.5rem);
  --header-h: 72px;

  /* Motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-1: 150ms;
  --dur-2: 260ms;

  /* Stacking */
  --z-header: 50;
  --z-tabbar: 60;
  --z-toast: 200;

  /* Breakpoints (media queries cannot read custom properties — documented here):
     480 / 768 / 1024 / 1440 px, all min-width, mobile-first. */
}
