/*
  tokens.css
  Design tokens for Said & Done. Source of truth for color, type, space,
  radius, shadow, motion, and layout. Spec and rationale: docs/DESIGN_SYSTEM.md

  Visual language: "Scoreboard". Done is lit. Warm paper and graphite ink by
  day, a near-black board by night. Color only shows up to deliver a verdict:
    green    = done, winning week, on pace, under target  (filled disc + check)
    amber    = partial, close, at risk                     (rising fill + edge + horizon)
    red      = missed, behind, over target                 (hollow disc + small x)
    graphite = everything else: today, future, rest, buttons, tabs, focus, chart lines
  Lightness ladder in both themes: amber is the lightest, green the middle, red the
  darkest, and the order holds under protan and deutan simulation.

  Rules of use
  1. Components read SEMANTIC tokens (--bg, --text-1, --brand, --status-done ...),
     never the primitive scales directly. Primitives exist so the semantics can be tuned.
  2. Green, amber, and red are verdicts. Chrome (buttons, Log, tabs, focus, links,
     chart data lines) wears --brand ink, so green never means "tap here."
  3. Red is for status marks only: an x, a pill, a thin ring, a meter sliver, a
     sparkline end dot. The largest red thing on any screen is a 30px pill.
  4. Text always wears a text token. Domain colors mark identity (icons, chips,
     dots, chart marks), never body text, and never status.
  5. Theme: light by default, dark follows the OS, and a manual override on
     <html data-theme="light|dark"> wins both ways.
  6. Fonts: self-hosted in public/fonts via css/fonts.css (load it first).
*/

/* ------------------------------------------------------------------ */
/* 1. Primitives (theme independent)                                   */
/* ------------------------------------------------------------------ */
:root {
  /* Green: the done scale (OKLCH hue 156). 500 = light done, 400 = dark done. */
  --green-50:  #E6FCF0;
  --green-100: #CDF9E1;
  --green-200: #95ECBB;
  --green-300: #72E2A1;
  --green-400: #2FD084;
  --green-500: #039359;
  --green-600: #007A4D;
  --green-700: #006341;
  --green-800: #024E34;
  --green-900: #003B28;
  --green-950: #002619;

  /* Amber: partial, close, at risk (OKLCH hue 68 to 90, a true yellow-amber).
     400 = light fill, 600 = light edge. 200 = dark fill, 400 = dark edge. */
  --amber-50:  #FFF7E0;
  --amber-100: #FFEDC4;
  --amber-200: #FFDD95;
  --amber-300: #FFC558;
  --amber-400: #F9AD0A;
  --amber-500: #DE9508;
  --amber-600: #B06D02;
  --amber-700: #895601;
  --amber-800: #6D4100;
  --amber-900: #552F01;
  --amber-950: #391C01;

  /* Red: missed, behind, over. A clear crimson (hue 25). 600 = light, 500 = dark.
     Status marks only, never a large area. */
  --red-50:  #FEF1F1;
  --red-100: #FEE0E0;
  --red-200: #FFC0BD;
  --red-300: #FF9692;
  --red-400: #F2605E;
  --red-500: #E24947;
  --red-600: #A50014;
  --red-700: #870012;
  --red-800: #71000D;
  --red-900: #55060B;
  --red-950: #380C0B;

  /* Graphite: warm paper at the light end (OKLCH hue 95 to 110, chroma under 0.011),
     green-black ink at the dark end (hue 165, chroma under 0.012). */
  --graphite-0:   #FFFEFB;
  --graphite-50:  #FBF9F5;
  --graphite-100: #F4F3ED;
  --graphite-150: #EBE9E3;
  --graphite-200: #DDDCD5;
  --graphite-300: #C3C3BD;
  --graphite-400: #99A09D;
  --graphite-450: #7A827E;
  --graphite-500: #6D7571;
  --graphite-600: #555D59;
  --graphite-700: #3E4441;
  --graphite-800: #272D2A;
  --graphite-850: #1D221F;
  --graphite-900: #141816;
  --graphite-925: #0E1110;
  --graphite-950: #080B0A;

  /* Domain hues (identity only). All live between OKLCH hue 237 and 340, so none
     reads as a status (green, amber, or red). Light-surface steps, then dark-surface steps. */
  --cornflower-l: #5C88DA;  /* fitness */
  --lagoon-l:     #016795;  /* food */
  --orchid-l:     #B66E9F;  /* heart (emotional wellbeing: joy, self-love) */
  --plum-l:       #743471;  /* people (relationships: trust, loyalty) */
  --indigo-l:     #3F33B9;  /* work */
  --violet-l:     #904ED5;  /* money */

  --cornflower-d: #7CAAFF;
  --lagoon-d:     #3488B8;
  --orchid-d:     #DA8FC1;
  --plum-d:       #955492;
  --indigo-d:     #5B59E1;
  --violet-d:     #B172FC;

  /* Celebration sparks (winning week only). Greens and white, never amber. */
  --spark-1: var(--green-300);
  --spark-2: var(--green-200);
  --spark-3: #FFFFFF;

  /* ---------------- Type ---------------- */
  --font-ui:    "Bricolage Grotesque", "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-num:   "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-voice: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  /* Sizes (px, mobile first; iPhone 390 to 430 wide) */
  --fs-num-xl:   64px;  /* hero stat: weekly score, today's weight */
  --fs-num-l:    48px;  /* numeric entry sheet readout */
  --fs-num-m:    34px;  /* stat tile value */
  --fs-num-s:    24px;  /* inline stat, week fraction */
  --fs-title-xl: 32px;  /* screen title */
  --fs-title-l:  24px;  /* sheet title, section hero */
  --fs-title-m:  19px;  /* goal card name */
  --fs-title-s:  16px;  /* row titles, button labels */
  --fs-body-l:   17px;  /* journal text, long reading */
  --fs-body:     15px;  /* default UI text */
  --fs-body-s:   13px;  /* meta, captions */
  --fs-eyebrow:  12px;  /* uppercase section labels */
  --fs-micro:    11px;  /* day letters, axis ticks */
  --fs-voice:    18px;  /* identity statements */
  --fs-voice-l:  22px;  /* journal prompts, weekly insight lead */
  --fs-input:    17px;  /* never below 16px or iOS zooms the page */

  --lh-tight: 1.0;
  --lh-snug:  1.2;
  --lh-ui:    1.35;
  --lh-body:  1.5;
  --lh-voice: 1.4;

  --fw-body:     420;
  --fw-medium:   520;
  --fw-semibold: 620;
  --fw-bold:     720;
  --fw-heavy:    790;
  --fw-num:      580;

  --track-tight:   -0.022em;
  --track-snug:    -0.012em;
  --track-normal:  0;
  --track-eyebrow: 0.08em;

  /* Fraunces character. SOFT 100 rounds the serifs into warm, friendly numerals. */
  --num-variation:   "SOFT" 100, "WONK" 0;
  --voice-variation: "SOFT" 50;

  /* ---------------- Space (4px base) ---------------- */
  --space-0: 0;
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 20px;
  --space-7: 24px;
  --space-8: 32px;
  --space-9: 40px;
  --space-10: 48px;
  --space-11: 64px;
  --space-12: 80px;

  /* ---------------- Radii ---------------- */
  --radius-xs:   6px;   /* tags, small chips inside cards */
  --radius-sm:   10px;  /* inputs, icon tiles */
  --radius-md:   14px;  /* buttons, photo thumbs */
  --radius-lg:   20px;  /* cards */
  --radius-xl:   28px;  /* bottom sheets (top corners) */
  --radius-pill: 999px; /* reaction chips, segmented controls */
  --radius-round: 50%;

  /* ---------------- Layout ---------------- */
  --gutter:       16px;
  --content-max:  480px;
  --tap:          44px;  /* minimum touch target */
  --check-size:   34px;  /* check circle visual diameter */
  --check-size-sm: 22px; /* partner card and compact rows */
  --check-stroke: 1.75px;
  --tabbar-h:     60px;
  --topbar-h:     52px;
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-left:    env(safe-area-inset-left, 0px);
  --safe-right:   env(safe-area-inset-right, 0px);
  --icon-stroke:  1.75px;
  --icon-size:    24px;
  --icon-size-sm: 20px;

  /* ---------------- Z ---------------- */
  --z-sticky:    20;
  --z-tabbar:    50;
  --z-backdrop:  70;
  --z-sheet:     80;
  --z-toast:     90;
  --z-celebrate: 100;

  /* ---------------- Motion ---------------- */
  --dur-instant:   80ms;
  --dur-fast:      140ms;
  --dur-base:      220ms;
  --dur-slow:      360ms;
  --dur-slower:    520ms;
  --dur-celebrate: 1200ms;
  --dur-fade:      160ms;   /* the one duration reduced motion keeps */

  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in:     cubic-bezier(0.55, 0, 1, 0.45);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);      /* fallback */
  --ease-spring-soft: cubic-bezier(0.3, 1.25, 0.6, 1);   /* fallback */
}

/* Real spring curves where linear() is supported (Safari 17.2+, Chrome 113+). */
@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --ease-spring: linear(0, 0.103 3.6%, 0.331 7.1%, 0.589 10.7%, 0.815 14.3%, 0.98 17.9%, 1.079 21.4%, 1.122 25%, 1.123 28.6%, 1.101 32.1%, 1.069 35.7%, 1.038 39.3%, 1.012 42.9%, 0.996 46.4%, 0.987 50%, 0.984 53.6%, 0.986 57.1%, 0.993 64.3%, 1 71.4%, 1.002 80%, 1);
    --ease-spring-soft: linear(0, 0.098 4.5%, 0.303 9.1%, 0.524 13.6%, 0.715 18.2%, 0.858 22.7%, 0.952 27.3%, 1.006 31.8%, 1.032 36.4%, 1.038 40.9%, 1.027 50%, 1.011 59.1%, 1.002 68.2%, 0.999 80%, 1);
  }
}

/* ------------------------------------------------------------------ */
/* 2. Semantic tokens, LIGHT ("Day game": warm paper, graphite ink)    */
/* ------------------------------------------------------------------ */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg:        var(--graphite-100);  /* #F4F3ED page */
  --surface:   var(--graphite-0);    /* #FFFEFB cards, check circle interiors */
  --surface-2: var(--graphite-150);  /* #EBE9E3 sunken: inputs, tracks, chips */
  --surface-3: var(--graphite-200);  /* #DDDCD5 pressed chips, skeletons. Never under a done fill */
  --raised:    var(--graphite-0);    /* bottom sheets, popovers */
  --overlay:   rgb(8 11 10 / 0.44);
  --tabbar-bg: rgb(251 249 245 / 0.86);

  /* Lines */
  --line:        rgb(28 30 26 / 0.11);  /* hairlines, card borders */
  --line-strong: rgb(28 30 26 / 0.21);  /* dividers that must read, future rings */
  --control:     var(--graphite-450);   /* #7A827E empty check ring, input border. 3:1+ on every light surface */
  --switch-knob: var(--graphite-0);     /* an off switch's knob: light on the track in both themes */

  /* Text */
  --text-1: var(--graphite-925);  /* #0E1110 primary */
  --text-2: var(--graphite-700);  /* #3E4441 secondary */
  --text-3: var(--graphite-600);  /* #555D59 muted, still AA */
  --text-disabled: var(--graphite-400); /* decorative or disabled only, not for meaning */
  --link:   var(--text-1);        /* text links: ink, weight 620, underlined */

  /* Brand = ink. Every non-verdict job: primary button, Log button, active tab,
     unread dot, focus, today ring, chart data lines. */
  --brand:         var(--graphite-925);  /* #0E1110 */
  --brand-hover:   var(--graphite-800);
  --brand-press:   var(--graphite-950);
  --on-brand:      #FFFFFF;
  --brand-tint:    #E4E3DC;              /* selected chips, active tab icon fill, my reaction */
  --focus:         var(--graphite-925);  /* 2px ink ring with a 2px surface gap */
  --focus-gap:     var(--surface);

  /* Accent = the verdict green (kept under its old name so fills, rings, meters,
     and heat cells need no edits). Not for buttons or navigation. */
  --accent:         var(--green-500);  /* #039359 done fills, win arcs, meters */
  --accent-hover:   var(--green-400);
  --accent-press:   var(--green-400);
  --on-accent:      #04140C;           /* TEXT on a green fill (rare): 4.79:1 */
  --accent-text:    var(--green-700);  /* green words: "ahead", "on pace", "patient" */
  --accent-tint:    var(--green-50);
  --accent-tint-2:  var(--green-100);
  --on-accent-tint: var(--green-800);
  --accent-deep:    var(--green-700);  /* verdict button: white on deep green, 7:1 */
  --on-accent-deep: #FFFFFF;
  --horizon:        var(--amber-600);  /* partial-fill top edge (= --status-partial-edge) */

  /* Personal accents: avatar gradients (initials in white) and quiet warm fills */
  --warm:      var(--graphite-600);
  --warm-deep: var(--graphite-800);
  --warm-tint: var(--graphite-50);
  --on-warm:   #FFFFFF;               /* initials on the avatar gradient */

  /* Status. Every one ships with its non-color cue (glyph, shape, or words). */
  --status-done:         var(--green-500);  /* filled disc (middle rung) */
  --on-status-done:      #FFFFFF;           /* check GLYPH on the done fill: 3.9:1 (graphic) */
  --status-done-text:    var(--green-700);
  --status-done-tint:    var(--green-50);   /* covered disc, "on pace" pill */

  --status-partial:      var(--amber-400);  /* rising fill (lightest rung) */
  --status-partial-edge: var(--amber-600);  /* 2px edge ring + horizon line, the 3:1 carrier */
  --on-status-partial:   var(--graphite-925); /* any text or glyph on the amber fill */
  --status-partial-text: var(--amber-700);
  --status-partial-tint: var(--amber-50);

  --status-missed:       var(--red-600);    /* the small x (darkest rung) */
  --status-missed-ring:  var(--red-200);    /* soft hollow ring, decorative; the x carries the state */
  --status-missed-text:  var(--red-600);
  --status-missed-tint:  var(--red-50);

  --status-today:        var(--text-1);     /* 2px ink ring: open, not judged */
  --status-open:         var(--control);    /* open day with nothing owed yet */
  --status-future:       var(--line-strong);/* hairline ring, no fill */
  --status-rest:         var(--text-3);     /* moon glyph on a hairline ring */
  --status-auto:         var(--brand);      /* auto-done dot: the app filled this in */

  /* Legacy status names, mapped onto the same scales */
  --success:      var(--status-done);
  --success-text: var(--status-done-text);
  --success-tint: var(--status-done-tint);
  --warn:         var(--status-partial);
  --warn-text:    var(--status-partial-text);
  --warn-tint:    var(--status-partial-tint);
  --danger:       var(--red-600);            /* destructive actions and real errors */
  --danger-text:  var(--red-600);
  --danger-tint:  var(--red-50);

  /* Winning-week banner: the one place green gets a big field */
  --win-bg:      var(--green-800);
  --win-bg-2:    var(--green-950);
  --on-win:      #FFFFFF;
  --on-win-2:    var(--green-100);
  --win-accent:  var(--green-300);          /* the lit score and the ring arc */
  --win-track:   rgb(255 255 255 / 0.16);
  --win-texture: radial-gradient(circle, rgb(255 255 255 / 0.07) 0 1px, transparent 1.6px);

  /* Goal domains: mark color (icons, chips, dots, chart marks) */
  --dom-fitness: var(--cornflower-l);
  --dom-food:    var(--lagoon-l);
  --dom-heart:   var(--orchid-l);
  --dom-people:  var(--plum-l);
  --dom-work:    var(--indigo-l);
  --dom-money:   var(--violet-l);
  --dom-tint-mix: 12%;               /* icon tile background strength */

  /* Charts. Ink draws the data; color delivers the verdict. */
  --chart-grid:   rgb(28 30 26 / 0.09);
  --chart-axis:   var(--text-3);
  --chart-line:   var(--text-1);             /* 7-day average, the hero line */
  --chart-band:   rgb(14 17 16 / 0.08);      /* trailing 7-day range */
  --chart-pace:   var(--graphite-500);       /* dashed pace line */
  --chart-dot:    var(--graphite-400);       /* daily weigh-ins */
  --chart-ahead:  rgb(3 147 89 / 0.14);      /* wash between average and pace when ahead */
  --chart-behind: rgb(85 93 89 / 0.10);      /* behind stays graphite: red never fills an area */
  --chart-win:    var(--green-500);          /* score bars at 80%+ */
  --chart-close:  var(--amber-400);          /* 60 to 79% */
  --chart-below:  var(--graphite-300);       /* under 60%, labeled, never red */
  /* Food macros (docs/changes/food-macros.md): ink and graphite only. A macro is never a verdict
     color except protein at or past its target, which uses --status-done. */
  --chart-col:     var(--graphite-450);      /* a finished day's column on the macros trend */
  --macro-fill:    var(--graphite-450);      /* a macro bar's fill (3:1 on the --surface-2 track) */
  --macro-protein: var(--graphite-925);      /* calorie split: protein (ink) */
  --macro-carbs:   var(--graphite-450);      /* calorie split: carbs */
  --macro-fat:     var(--graphite-300);      /* calorie split: fat (the text legend carries it) */
  --heat-0: var(--graphite-150);
  --heat-1: var(--green-100);
  --heat-2: var(--green-200);
  --heat-3: var(--green-300);
  --heat-4: var(--green-400);
  --heat-5: var(--green-500);

  /* Elevation (neutral shadows with a hint of green-black) */
  --shadow-1: 0 1px 1px rgb(8 24 16 / 0.04), 0 2px 6px rgb(8 24 16 / 0.05);
  --shadow-2: 0 2px 4px rgb(8 24 16 / 0.05), 0 10px 28px rgb(8 24 16 / 0.09);
  --shadow-3: 0 -10px 44px rgb(8 24 16 / 0.16), 0 -1px 0 rgb(8 24 16 / 0.04);
  --shadow-brand:  0 6px 18px rgb(8 11 10 / 0.24), 0 2px 4px rgb(8 11 10 / 0.14);
  --shadow-accent: 0 6px 18px rgb(3 147 89 / 0.28), 0 2px 4px rgb(3 147 89 / 0.16);
  --inner-highlight: inset 0 1px 0 rgb(255 255 255 / 0.8);
  --glow-accent: 0 0 0 6px rgb(3 147 89 / 0.16);
  --pulse-color: rgb(3 147 89 / 0.45);       /* done-pulse and ring-flare */

  /* Atmosphere: a white floodlight at the top of Today and Reflect.
     It tints green only while the week is winning. */
  --floodlight:     radial-gradient(120% 70% at 50% -18%, rgb(255 255 255 / 0.95) 0%, rgb(255 255 255 / 0.40) 38%, transparent 68%);
  --floodlight-win: radial-gradient(120% 70% at 50% -18%, rgb(149 236 187 / 0.36) 0%, rgb(205 249 225 / 0.18) 38%, transparent 68%);
  --grain-opacity: 0.025;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.12  0 0 0 0 0.12  0 0 0 0 0.10  0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --shimmer: linear-gradient(100deg, transparent 20%, rgb(255 255 255 / 0.55) 45%, rgb(255 255 255 / 0.25) 55%, transparent 80%);

  --theme-color: #F4F3ED; /* mirror in <meta name="theme-color"> */
}

/* ------------------------------------------------------------------ */
/* 3. Semantic tokens, DARK ("Night game": a near-black board)         */
/*    Declared twice: OS preference (unless forced light) and manual.  */
/*    Keep both copies identical; check-contrast.mjs fails on drift.   */
/* ------------------------------------------------------------------ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        var(--graphite-950);
    --surface:   #131715;
    --surface-2: #1C211F;
    --surface-3: #272D2A;
    --raised:    #181D1B;
    --overlay:   rgb(0 0 0 / 0.60);
    --tabbar-bg: rgb(12 15 14 / 0.86);
    --line:        rgb(236 242 236 / 0.08);
    --line-strong: rgb(236 242 236 / 0.16);
    --control:     var(--graphite-500);
    --switch-knob: var(--graphite-300);
    --text-1: var(--graphite-100);
    --text-2: var(--graphite-300);
    --text-3: var(--graphite-400);
    --text-disabled: var(--graphite-600);
    --link:   var(--text-1);
    --brand:         var(--graphite-100);
    --brand-hover:   #FFFFFF;
    --brand-press:   var(--graphite-200);
    --on-brand:      var(--graphite-925);
    --brand-tint:    #2A302D;
    --focus:         var(--graphite-100);
    --focus-gap:     var(--surface);
    --accent:         var(--green-400);
    --accent-hover:   var(--green-300);
    --accent-press:   var(--green-300);
    --on-accent:      #04140C;
    --accent-text:    var(--green-300);
    --accent-tint:    #0E2E20;
    --accent-tint-2:  #114A31;
    --on-accent-tint: var(--green-200);
    --accent-deep:    var(--green-700);
    --on-accent-deep: #FFFFFF;
    --horizon:        var(--amber-400);
    --warm:      var(--graphite-500);
    --warm-deep: var(--graphite-700);
    --warm-tint: #1A1F1C;
    --on-warm:   #FFFFFF;
    --status-done:         var(--green-400);
    --on-status-done:      #04140C;
    --status-done-text:    var(--green-300);
    --status-done-tint:    #0E2E20;
    --status-partial:      var(--amber-200);
    --status-partial-edge: var(--amber-400);
    --on-status-partial:   var(--graphite-925);
    --status-partial-text: var(--amber-300);
    --status-partial-tint: #2E2408;
    --status-missed:       var(--red-500);
    --status-missed-ring:  #5A2123;
    --status-missed-text:  var(--red-300);
    --status-missed-tint:  #34110F;
    --status-today:        var(--text-1);
    --status-open:         var(--control);
    --status-future:       var(--line-strong);
    --status-rest:         var(--text-3);
    --status-auto:         var(--brand);
    --success:      var(--status-done);
    --success-text: var(--status-done-text);
    --success-tint: var(--status-done-tint);
    --warn:         var(--status-partial);
    --warn-text:    var(--status-partial-text);
    --warn-tint:    var(--status-partial-tint);
    --danger:       var(--red-500);
    --danger-text:  var(--red-300);
    --danger-tint:  #34110F;
    --win-bg:      #063A26;
    --win-bg-2:    #03140D;
    --on-win:      #FFFFFF;
    --on-win-2:    var(--green-100);
    --win-accent:  var(--green-300);
    --win-track:   rgb(255 255 255 / 0.14);
    --win-texture: radial-gradient(circle, rgb(255 255 255 / 0.06) 0 1px, transparent 1.6px);
    --dom-fitness: var(--cornflower-d);
    --dom-food:    var(--lagoon-d);
    --dom-heart:   var(--orchid-d);
    --dom-people:  var(--plum-d);
    --dom-work:    var(--indigo-d);
    --dom-money:   var(--violet-d);
    --dom-tint-mix: 20%;
    --chart-grid:   rgb(236 242 236 / 0.08);
    --chart-axis:   var(--text-3);
    --chart-line:   var(--text-1);
    --chart-band:   rgb(244 243 237 / 0.09);
    --chart-pace:   var(--graphite-400);
    --chart-dot:    var(--graphite-500);
    --chart-ahead:  rgb(47 208 132 / 0.16);
    --chart-behind: rgb(153 160 157 / 0.10);
    --chart-win:    var(--green-400);
    --chart-close:  var(--amber-200);
    --chart-below:  var(--graphite-700);
    --chart-col:     var(--graphite-500);
    --macro-fill:    var(--graphite-500);
    --macro-protein: var(--graphite-100);
    --macro-carbs:   var(--graphite-450);
    --macro-fat:     var(--graphite-700);
    --heat-0: #1C211F;
    --heat-1: #0E2E20;
    --heat-2: #114A31;
    --heat-3: var(--green-600);
    --heat-4: var(--green-500);
    --heat-5: var(--green-400);
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.45), 0 4px 12px rgb(0 0 0 / 0.30);
    --shadow-2: 0 2px 6px rgb(0 0 0 / 0.50), 0 14px 36px rgb(0 0 0 / 0.42);
    --shadow-3: 0 -12px 48px rgb(0 0 0 / 0.65);
    --shadow-brand:  0 6px 22px rgb(0 0 0 / 0.50), 0 0 0 1px rgb(255 255 255 / 0.06);
    --shadow-accent: 0 6px 22px rgb(47 208 132 / 0.30), 0 0 0 1px rgb(114 226 161 / 0.25);
    --inner-highlight: inset 0 1px 0 rgb(236 242 236 / 0.05);
    --glow-accent: 0 0 0 6px rgb(47 208 132 / 0.22);
    --pulse-color: rgb(47 208 132 / 0.50);
    --floodlight:     radial-gradient(120% 70% at 50% -20%, rgb(244 243 237 / 0.07) 0%, rgb(244 243 237 / 0.03) 40%, transparent 70%);
    --floodlight-win: radial-gradient(120% 70% at 50% -20%, rgb(47 208 132 / 0.16) 0%, rgb(0 99 65 / 0.07) 40%, transparent 70%);
    --grain-opacity: 0;
    --shimmer: linear-gradient(100deg, transparent 20%, rgb(244 243 237 / 0.16) 45%, rgb(244 243 237 / 0.08) 55%, transparent 80%);
    --theme-color: #080B0A;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        var(--graphite-950);
  --surface:   #131715;
  --surface-2: #1C211F;
  --surface-3: #272D2A;
  --raised:    #181D1B;
  --overlay:   rgb(0 0 0 / 0.60);
  --tabbar-bg: rgb(12 15 14 / 0.86);
  --line:        rgb(236 242 236 / 0.08);
  --line-strong: rgb(236 242 236 / 0.16);
  --control:     var(--graphite-500);
  --switch-knob: var(--graphite-300);
  --text-1: var(--graphite-100);
  --text-2: var(--graphite-300);
  --text-3: var(--graphite-400);
  --text-disabled: var(--graphite-600);
  --link:   var(--text-1);
  --brand:         var(--graphite-100);
  --brand-hover:   #FFFFFF;
  --brand-press:   var(--graphite-200);
  --on-brand:      var(--graphite-925);
  --brand-tint:    #2A302D;
  --focus:         var(--graphite-100);
  --focus-gap:     var(--surface);
  --accent:         var(--green-400);
  --accent-hover:   var(--green-300);
  --accent-press:   var(--green-300);
  --on-accent:      #04140C;
  --accent-text:    var(--green-300);
  --accent-tint:    #0E2E20;
  --accent-tint-2:  #114A31;
  --on-accent-tint: var(--green-200);
  --accent-deep:    var(--green-700);
  --on-accent-deep: #FFFFFF;
  --horizon:        var(--amber-400);
  --warm:      var(--graphite-500);
  --warm-deep: var(--graphite-700);
  --warm-tint: #1A1F1C;
  --on-warm:   #FFFFFF;
  --status-done:         var(--green-400);
  --on-status-done:      #04140C;
  --status-done-text:    var(--green-300);
  --status-done-tint:    #0E2E20;
  --status-partial:      var(--amber-200);
  --status-partial-edge: var(--amber-400);
  --on-status-partial:   var(--graphite-925);
  --status-partial-text: var(--amber-300);
  --status-partial-tint: #2E2408;
  --status-missed:       var(--red-500);
  --status-missed-ring:  #5A2123;
  --status-missed-text:  var(--red-300);
  --status-missed-tint:  #34110F;
  --status-today:        var(--text-1);
  --status-open:         var(--control);
  --status-future:       var(--line-strong);
  --status-rest:         var(--text-3);
  --status-auto:         var(--brand);
  --success:      var(--status-done);
  --success-text: var(--status-done-text);
  --success-tint: var(--status-done-tint);
  --warn:         var(--status-partial);
  --warn-text:    var(--status-partial-text);
  --warn-tint:    var(--status-partial-tint);
  --danger:       var(--red-500);
  --danger-text:  var(--red-300);
  --danger-tint:  #34110F;
  --win-bg:      #063A26;
  --win-bg-2:    #03140D;
  --on-win:      #FFFFFF;
  --on-win-2:    var(--green-100);
  --win-accent:  var(--green-300);
  --win-track:   rgb(255 255 255 / 0.14);
  --win-texture: radial-gradient(circle, rgb(255 255 255 / 0.06) 0 1px, transparent 1.6px);
  --dom-fitness: var(--cornflower-d);
  --dom-food:    var(--lagoon-d);
  --dom-heart:   var(--orchid-d);
  --dom-people:  var(--plum-d);
  --dom-work:    var(--indigo-d);
  --dom-money:   var(--violet-d);
  --dom-tint-mix: 20%;
  --chart-grid:   rgb(236 242 236 / 0.08);
  --chart-axis:   var(--text-3);
  --chart-line:   var(--text-1);
  --chart-band:   rgb(244 243 237 / 0.09);
  --chart-pace:   var(--graphite-400);
  --chart-dot:    var(--graphite-500);
  --chart-ahead:  rgb(47 208 132 / 0.16);
  --chart-behind: rgb(153 160 157 / 0.10);
  --chart-win:    var(--green-400);
  --chart-close:  var(--amber-200);
  --chart-below:  var(--graphite-700);
  --chart-col:     var(--graphite-500);
  --macro-fill:    var(--graphite-500);
  --macro-protein: var(--graphite-100);
  --macro-carbs:   var(--graphite-450);
  --macro-fat:     var(--graphite-700);
  --heat-0: #1C211F;
  --heat-1: #0E2E20;
  --heat-2: #114A31;
  --heat-3: var(--green-600);
  --heat-4: var(--green-500);
  --heat-5: var(--green-400);
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.45), 0 4px 12px rgb(0 0 0 / 0.30);
  --shadow-2: 0 2px 6px rgb(0 0 0 / 0.50), 0 14px 36px rgb(0 0 0 / 0.42);
  --shadow-3: 0 -12px 48px rgb(0 0 0 / 0.65);
  --shadow-brand:  0 6px 22px rgb(0 0 0 / 0.50), 0 0 0 1px rgb(255 255 255 / 0.06);
  --shadow-accent: 0 6px 22px rgb(47 208 132 / 0.30), 0 0 0 1px rgb(114 226 161 / 0.25);
  --inner-highlight: inset 0 1px 0 rgb(236 242 236 / 0.05);
  --glow-accent: 0 0 0 6px rgb(47 208 132 / 0.22);
  --pulse-color: rgb(47 208 132 / 0.50);
  --floodlight:     radial-gradient(120% 70% at 50% -20%, rgb(244 243 237 / 0.07) 0%, rgb(244 243 237 / 0.03) 40%, transparent 70%);
  --floodlight-win: radial-gradient(120% 70% at 50% -20%, rgb(47 208 132 / 0.16) 0%, rgb(0 99 65 / 0.07) 40%, transparent 70%);
  --grain-opacity: 0;
  --shimmer: linear-gradient(100deg, transparent 20%, rgb(244 243 237 / 0.16) 45%, rgb(244 243 237 / 0.08) 55%, transparent 80%);
  --theme-color: #080B0A;
}

/* ------------------------------------------------------------------ */
/* 4. Domain helpers. Set --dom on any element, children read these.   */
/*    <div class="goal-card" style="--dom: var(--dom-food)">           */
/* ------------------------------------------------------------------ */
:root { --dom: var(--text-2); }  /* no domain: quiet ink, never the verdict green */
:where([data-domain="fitness"]) { --dom: var(--dom-fitness); }
:where([data-domain="food"])    { --dom: var(--dom-food); }
:where([data-domain="heart"])   { --dom: var(--dom-heart); }
:where([data-domain="people"])  { --dom: var(--dom-people); }
:where([data-domain="work"])    { --dom: var(--dom-work); }
:where([data-domain="money"])   { --dom: var(--dom-money); }
:where([data-domain]) { --dom-tint: color-mix(in oklab, var(--dom) var(--dom-tint-mix), var(--surface)); }

/* ------------------------------------------------------------------ */
/* 5. Type roles. Zero-specificity so component CSS can override.      */
/* ------------------------------------------------------------------ */
:where(.num-xl, .num-l, .num-m, .num-s) {
  font-family: var(--font-num);
  font-weight: var(--fw-num);
  font-variation-settings: var(--num-variation);
  font-optical-sizing: auto;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  font-variant-numeric: lining-nums;
}
:where(.num-xl) { font-size: var(--fs-num-xl); letter-spacing: -0.035em; }
:where(.num-l)  { font-size: var(--fs-num-l);  letter-spacing: -0.03em; }
:where(.num-m)  { font-size: var(--fs-num-m); }
:where(.num-s)  { font-size: var(--fs-num-s); }

:where(.title-xl, .title-l, .title-m, .title-s) {
  font-family: var(--font-ui);
  font-optical-sizing: auto;
  color: var(--text-1);
}
:where(.title-xl) { font-size: var(--fs-title-xl); font-weight: var(--fw-heavy); font-stretch: 92%; line-height: 1.05; letter-spacing: var(--track-tight); }
:where(.title-l)  { font-size: var(--fs-title-l);  font-weight: var(--fw-bold);  font-stretch: 94%; line-height: 1.12; letter-spacing: var(--track-tight); }
:where(.title-m)  { font-size: var(--fs-title-m);  font-weight: var(--fw-bold);  font-stretch: 96%; line-height: 1.22; letter-spacing: var(--track-snug); }
:where(.title-s)  { font-size: var(--fs-title-s);  font-weight: var(--fw-semibold); line-height: 1.3; letter-spacing: -0.005em; }

:where(.body-l) { font: var(--fw-body) var(--fs-body-l)/var(--lh-body) var(--font-ui); }
:where(.body)   { font: var(--fw-body) var(--fs-body)/var(--lh-body) var(--font-ui); }
:where(.body-s) { font: var(--fw-body) var(--fs-body-s)/1.45 var(--font-ui); color: var(--text-2); }
:where(.eyebrow) {
  font: var(--fw-semibold) var(--fs-eyebrow)/1.2 var(--font-ui);
  letter-spacing: var(--track-eyebrow);
  text-transform: uppercase;
  color: var(--text-3);
}
:where(.micro) { font: var(--fw-semibold) var(--fs-micro)/1.1 var(--font-ui); letter-spacing: 0.02em; color: var(--text-3); }
:where(.tabular) { font-variant-numeric: tabular-nums lining-nums; }
:where(.voice, .voice-l) {
  font-family: var(--font-voice);
  font-style: italic;
  font-weight: 400;
  font-variation-settings: var(--voice-variation);
  font-optical-sizing: auto;
  line-height: var(--lh-voice);
  color: var(--text-2);
}
:where(.voice)   { font-size: var(--fs-voice); }
:where(.voice-l) { font-size: var(--fs-voice-l); letter-spacing: -0.01em; color: var(--text-1); }

/* ------------------------------------------------------------------ */
/* 6. Base (zero specificity, safe to override)                        */
/* ------------------------------------------------------------------ */
:where(html) {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
:where(body) {
  margin: 0;
  background-color: var(--bg);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-weight: var(--fw-body);
  line-height: var(--lh-body);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
:where(input, textarea, select, button) { font: inherit; color: inherit; }
:where(input, textarea, select) { font-size: max(16px, var(--fs-input)); }
:where(:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
/* On a filled control (a done disc, the Log button) draw the gap too, so the ink ring
   never touches a status fill:  box-shadow: 0 0 0 2px var(--focus-gap), 0 0 0 4px var(--focus); */
:where(::selection) { background: var(--brand-tint); color: var(--text-1); }

/* Paper grain. Add class="grain" to <body>. Purely decorative (light theme only; 0 in dark). */
:where(.grain)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1; /* paints above the page background, below all content */
  pointer-events: none;
  background-image: var(--grain);
  background-size: 160px 160px;
  opacity: var(--grain-opacity);
}

/* ------------------------------------------------------------------ */
/* 7. Motion keyframes (shared by components)                          */
/* ------------------------------------------------------------------ */

/* Check circle: the done fill rises from the bottom and the cell lights up. */
@keyframes fill-rise {
  from { transform: translateY(100%); }
  to   { transform: translateY(calc((1 - var(--fill, 1)) * 100%)); }
}
/* The wave on the fill's top edge slides sideways while it rises. */
@keyframes wave-slosh {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
/* Undo: the fill drains back down. */
@keyframes fill-drain {
  from { transform: translateY(0); }
  to   { transform: translateY(100%); }
}
/* Check mark draws itself. Set stroke-dasharray and --check-len on the path. */
@keyframes check-draw {
  from { stroke-dashoffset: var(--check-len, 20); }
  to   { stroke-dashoffset: 0; }
}
/* One soft green ring after a check. */
@keyframes done-pulse {
  0%   { box-shadow: 0 0 0 0 var(--pulse-color); }
  100% { box-shadow: 0 0 0 12px transparent; }
}
/* Tap feedback with a springy settle (pair with --ease-spring). */
@keyframes pop {
  0%   { transform: scale(0.86); }
  100% { transform: scale(1); }
}
/* Weekly win: green and white sparks rise and fade. Each spark sets --dx --dy --rot --delay. */
@keyframes spark-rise {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.5) rotate(0deg); }
  14%  { opacity: 1; transform: translate(calc(var(--dx, 0px) * 0.18), calc(var(--dy, -120px) * 0.18)) scale(1.15) rotate(calc(var(--rot, 90deg) * 0.18)); }
  65%  { opacity: 0.95; }
  100% { opacity: 0; transform: translate(var(--dx, 0px), var(--dy, -120px)) scale(0.4) rotate(var(--rot, 90deg)); }
}
/* Winning-week ring flare. */
@keyframes ring-flare {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  40%  { filter: drop-shadow(0 0 14px var(--pulse-color)); }
  100% { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--pulse-color) 40%, transparent)); }
}
/* Reactions. */
@keyframes reaction-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.32); }
  100% { transform: scale(1); }
}
@keyframes float-up {
  0%   { opacity: 0; transform: translateY(4px); }
  25%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-22px); }
}
/* Sheets and page entrances. */
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* AI estimating a food photo: a soft band of white light sweeps across (--shimmer). */
@keyframes ai-shimmer {
  from { background-position: -160% 0; }
  to   { background-position: 260% 0; }
}
:root {
  /* Wave crest for the check fill's top edge. Use as a mask, 17px x 6px tile. */
  --wave: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='17' height='6'><path d='M0 6V3.2C2.1 3.2 2.1 0.8 4.25 0.8S6.4 3.2 8.5 3.2 10.6 0.8 12.75 0.8 14.9 3.2 17 3.2V6Z'/></svg>");
}

/* ------------------------------------------------------------------ */
/* 8. Reduced motion. Movement goes away, meaning stays.               */
/*    Fills and state changes become quick opacity crossfades.         */
/* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-instant:   0ms;
    --dur-fast:      0ms;
    --dur-base:      0ms;
    --dur-slow:      0ms;
    --dur-slower:    0ms;
    --dur-celebrate: 0ms;
    --dur-fade:      160ms;
    --ease-spring: ease-out;
    --ease-spring-soft: ease-out;
  }
  :where(.spark, .confetti, .float-up) { display: none !important; }
  :where(*, *::before, *::after) {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
