/* Grove UI v2 tokens (UX-003). Loaded first, before src/cozy-tokens.css.
   See docs/ux-loop/DESIGN-DIRECTION.md, "The system: Grove UI v2".

   Three layers, each built only from the one above it:
   1. Primitives  --p-<ramp>-<step>   Raw palette. Steps run light (50/100) to dark (900);
                                       at most 5 steps per ramp. The only place hex lives.
   2. Semantic    --ui-<role>         What a colour/size is FOR: surface, ink, line, accent,
                                       success, warning, danger, coin, focus ring, scrim.
                                       Scales: --ui-fs-*, --ui-s-*, --ui-r*, --ui-font-*,
                                       --ui-dur-*, --ui-ease-*, --ui-elev-*.
   3. Component   --ui-<component>-<part>  button, chip, panel, sheet, card, input, toast,
                                       tooltip, tab: bg, ink, line, radius, pad (+ shadow).

   THE RULE: feature CSS uses semantic and component tokens only. Never a primitive,
   never a hex, px font size, radius or font-family literal (scripts/ux-lint.mjs counts
   them; `npm run ux:lint -- --check` fails if any count rises).

   Legacy: src/cozy-tokens.css keeps its --cz-* names as aliases of these primitives.
   The older --ui-* names that src/cozy-ui.css and src/experience.css declared (--ui-muted,
   --ui-paper, --ui-radius, --ui-shadow) are gone (UX-006 B1); use the tokens below.
   Night: nothing in the DOM marks night yet (world.js only tints the canvas). Night values
   are scoped to :root[data-ui-time="night"], ready for UX-022 to set that attribute. */
:root{
  /* ---------- 1. primitives (existing cozy hexes kept as ramp steps) ---------- */
  --p-cocoa-400:#6b4f45;   /* cz-cocoa-soft: muted ink, AA on meadow/cream/paper */
  --p-cocoa-500:#5a4038;   /* cz-cocoa: ink, borders */
  --p-cocoa-700:#3c2822;   /* cz-cocoa-deep: shadows, footer */
  --p-paper-50:#fffaee;    /* cz-paper: cards, dialogs, inputs */
  --p-paper-100:#f7f1dc;   /* cz-cream: alternate section */
  --p-paper-200:#f1e6c8;   /* cz-paper-deep: pressed / secondary */
  --p-paper-300:#e8dcc0;   /* evening paper (UX-022): night surface, dimmer than paper-50 */
  --p-paper-400:#d9cba8;   /* evening paper, sunk */
  --p-meadow-100:#dbe59f;  /* cz-meadow: page */
  --p-meadow-200:#c9d88a;  /* cz-meadow-deep */
  --p-meadow-400:#7ea85c;  /* cz-moss */
  --p-meadow-600:#5c8743;  /* cz-moss-deep */
  --p-meadow-800:#3c6955;  /* the leaf mark's green (public/favicon.svg) */
  --p-peach-400:#f3a97b;   /* cz-peach */
  --p-peach-600:#d9825a;   /* cz-peach-deep: focus outline, warn dot */
  --p-sky-300:#9fcfe3;     /* cz-sky: water, info */
  --p-gold-400:#efc766;    /* cz-gold: coins */
  --p-gold-600:#c79a3a;    /* cz-gold-deep */
  --p-rose-400:#e99aa6;    /* cz-rose: hearts, bond */
  --p-rose-700:#b83b3b;    /* error text (shell.css .entry-gate-status.is-error) */
  --p-night-300:#8a96b8;
  --p-night-500:#465679;   /* world.js night sky */
  --p-night-700:#2c3550;
  --p-night-900:#1c2236;
  /* GROVE-9.6: deeper steps of existing ramps for the Study Corner's subject colours */
  --p-peach-700:#b35a33;
  --p-gold-700:#8f6a1c;
  --p-sky-700:#2f7391;
  --p-rose-600:#b4466e;

  /* ---------- 2. semantic ---------- */
  --ui-page:var(--p-meadow-100);
  --ui-surface:var(--p-paper-50);
  --ui-surface-sunk:var(--p-paper-200);
  --ui-ink:var(--p-cocoa-500);          /* = cozy-ui.css --ui-ink */
  --ui-ink-muted:var(--p-cocoa-400);
  --ui-line:var(--p-cocoa-500);         /* = cozy-ui.css --ui-line */
  --ui-accent:var(--p-meadow-600);      /* = cozy-ui.css --ui-accent */
  --ui-success:var(--p-meadow-400);
  --ui-success-ink:var(--p-meadow-800); /* success as text (coins earned): 6.0:1 on paper-50, 5.0:1 on paper-200 */
  --ui-warning:var(--p-peach-600);
  /* Subject colours (GROVE-9.6, docs/STUDY-CORNER.md §6.6): only the 8 px dot, a deck's band and
     a week bar's segment use them, always beside the subject's name. All >= 4:1 on paper-50 and
     >= 3.3:1 on paper-200 (the rail), so they read as graphics on both. */
  --ui-subject-1:var(--p-meadow-600);
  --ui-subject-2:var(--p-sky-700);
  --ui-subject-3:var(--p-peach-700);
  --ui-subject-4:var(--p-rose-600);
  --ui-subject-5:var(--p-gold-700);
  --ui-subject-6:var(--p-meadow-800);
  --ui-subject-7:var(--p-rose-700);
  --ui-subject-8:var(--p-night-500);
  --ui-danger:var(--p-rose-700);
  --ui-info:var(--p-sky-300);
  --ui-coin:var(--p-gold-400);
  --ui-coin-deep:var(--p-gold-600);
  --ui-brand:var(--p-meadow-800);       /* the leaf mark tile behind public/favicon.svg */
  /* Focus = 2px cocoa ring (AA: cocoa-700 is >= 3:1 on paper and meadow); an optional
     peach halo may sit outside it. Peach alone fails 3:1, so never use it as the ring. */
  --ui-focus-ring:var(--p-cocoa-700);
  --ui-focus-ring-w:2px;
  --ui-focus-ring-halo:var(--p-peach-600);
  --ui-scrim:color-mix(in srgb,var(--p-cocoa-700) 35%,transparent);
  --ui-scrim-deep:color-mix(in srgb,var(--p-night-900) 85%,transparent); /* behind the dungeon: the world steps back */
  --ui-stage-bg:var(--p-night-900);       /* the dungeon's dark stage (battle canvas, room, monster art) */
  --ui-border-w:3px;
  /* UI v2 additions (UX-002, docs/ux-loop/UI-V2.md). All derived from primitives. */
  --ui-surface-hi:color-mix(in srgb,var(--p-paper-50) 40%,white); /* 1-UI-px bevel highlight on paper */
  --ui-surface-shade:var(--p-paper-300);  /* 1-UI-px bevel shade on paper */
  --ui-line-deep:var(--p-cocoa-700);      /* pixel drop shadow under frames */
  --ui-ink-strong:var(--p-cocoa-700);     /* ink on peach/gold/rose fills (AA: 7.1:1 on peach-400) */
  --ui-ink-on-dark:var(--p-paper-50);     /* text on cocoa fills, toasts (9.1:1 on cocoa-500) */
  --ui-selected:var(--p-peach-400);       /* the ONE active/selected fill: dock item, tab, chip */
  --ui-primary-hover:var(--p-cocoa-400);  /* primary fill on hover (paper text 7.1:1) */
  --ui-secondary-hover:var(--p-paper-100);
  --ui-disabled-bg:var(--p-paper-200);
  --ui-disabled-ink:var(--p-cocoa-400);   /* 6.0:1 on paper-200; disabled still reads */
  --ui-disabled-line:var(--p-paper-400);
  --ui-dim:.45;                           /* art on a level-locked tile (UX-156); never text */
  /* One UI pixel. Pixel frames are drawn in whole multiples of it, independent of the
     world zoom (the world may render at 2x-4x; the chrome stays at a fixed 2x). */
  --ui-px:2px;
  --ui-target:44px;                       /* minimum touch target */

  /* Type. Three families only: Pixelify Sans (--ui-font-display) for display text and
     labels; Outfit (--ui-font-body) for reading; VT323 (--ui-font-num) only for big
     numbers (timer, coins) at >= 24px. Pixel fonts sit at sizes where their pixels land
     on whole device pixels. TYPE RULE (BACKLOG): pixel fonts never for small counts,
     prices or key hints under 20px; those use --ui-font-body with
     font-variant-numeric: tabular-nums. Scale: 12 14 16 20 24 32 40. */
  --ui-font-display:"Pixelify Sans",VT323,"Courier New",monospace;
  --ui-font-body:Outfit,system-ui,sans-serif;
  --ui-font-num:VT323,"Pixelify Sans",monospace;
  --ui-fs-12:12px;
  --ui-fs-14:14px;
  --ui-fs-16:16px;
  --ui-fs-20:20px;
  --ui-fs-24:24px;
  --ui-fs-32:32px;
  --ui-fs-40:40px;
  /* The one big number a sheet may carry (the Focus countdown): VT323 only, 64 = 16 x 4,
     so its pixels land on whole device pixels. Not part of the reading scale. */
  --ui-fs-num-hero:64px;
  /* The type scale as roles (GROVE-1.9): font shorthands every sheet uses. */
  --ui-type-sheet-title:600 var(--ui-fs-20)/1.2 var(--ui-font-display);
  --ui-type-section-title:600 var(--ui-fs-16)/1.25 var(--ui-font-display);
  --ui-type-row-label:500 var(--ui-fs-16)/1.25 var(--ui-font-body);
  --ui-type-field-label:600 var(--ui-fs-14)/1.25 var(--ui-font-body);
  --ui-type-hint:400 var(--ui-fs-14)/1.5 var(--ui-font-body);

  /* Space: 4px grid. */
  --ui-s-1:4px;
  --ui-s-2:8px;
  --ui-s-3:12px;
  --ui-s-4:16px;
  --ui-s-5:24px;
  --ui-s-6:32px;
  --ui-s-7:48px;

  /* Shape: three radii. Pixel frames (UX-002) use none. */
  --ui-r-sm:6px;
  --ui-r:12px;
  --ui-r-pill:999px;

  /* Elevation: two pixel drop shadows, no blur. */
  --ui-elev-rest:3px 3px 0 var(--p-cocoa-500);
  --ui-elev-raised:4px 4px 0 var(--p-cocoa-500);

  /* Motion: press/hover, chips/toasts, sheets/cards. Enter ease-out with travel
     and fade; exit ease-in, faster than enter. */
  --ui-dur-fast:120ms;
  --ui-dur:200ms;
  --ui-dur-slow:320ms;
  --ui-ease-out:cubic-bezier(.22,1,.36,1);
  --ui-ease-in:cubic-bezier(.55,0,.75,.2);
  --ui-travel:8px;
  --ui-press:2px;

  /* ---------- 3. component ---------- */
  --ui-button-bg:var(--ui-surface);
  --ui-button-ink:var(--ui-ink);
  --ui-button-line:var(--ui-line);
  --ui-button-radius:var(--ui-r);
  --ui-button-pad:var(--ui-s-2) var(--ui-s-4);
  --ui-button-shadow:var(--ui-elev-rest);
  --ui-button-primary-bg:var(--ui-ink);       /* cocoa + paper text, ~9:1 (paper on moss-600 is 4.03:1) */
  --ui-button-primary-ink:var(--p-paper-50);

  --ui-chip-bg:var(--ui-surface-sunk);
  --ui-chip-ink:var(--ui-ink);
  --ui-chip-line:var(--ui-line);
  --ui-chip-radius:var(--ui-r-pill);
  --ui-chip-pad:var(--ui-s-1) var(--ui-s-3);

  --ui-panel-bg:var(--ui-surface);
  --ui-panel-ink:var(--ui-ink);
  --ui-panel-line:var(--ui-line);
  --ui-panel-radius:var(--ui-r);
  --ui-panel-pad:var(--ui-s-4);
  --ui-panel-shadow:var(--ui-elev-rest);

  --ui-sheet-bg:var(--ui-surface);
  --ui-sheet-ink:var(--ui-ink);
  --ui-sheet-line:var(--ui-line);
  --ui-sheet-radius:var(--ui-r);
  --ui-sheet-pad:var(--ui-s-5);
  --ui-sheet-shadow:var(--ui-elev-raised);
  --ui-sheet-scrim:var(--ui-scrim);

  --ui-card-bg:var(--ui-surface);
  --ui-card-ink:var(--ui-ink);
  --ui-card-line:var(--ui-line);
  --ui-card-radius:var(--ui-r);
  --ui-card-pad:var(--ui-s-3);
  /* The welcome tour's short card (its focus step on a phone held sideways, shell.css). */
  --ui-tour-short-w:300px;

  --ui-input-bg:var(--ui-surface);
  --ui-input-ink:var(--ui-ink);
  --ui-input-line:var(--ui-line);
  --ui-input-radius:var(--ui-r-sm);
  --ui-input-pad:var(--ui-s-2) var(--ui-s-3);

  --ui-toast-bg:var(--ui-ink);
  --ui-toast-ink:var(--ui-surface);
  --ui-toast-line:var(--ui-line);
  --ui-toast-radius:var(--ui-r);
  --ui-toast-pad:var(--ui-s-2) var(--ui-s-4);

  --ui-tooltip-bg:var(--ui-surface);
  --ui-tooltip-ink:var(--ui-ink);
  --ui-tooltip-line:var(--ui-line);
  --ui-tooltip-radius:var(--ui-r-sm);
  --ui-tooltip-pad:var(--ui-s-1) var(--ui-s-2);
  --ui-tooltip-shadow:var(--ui-elev-raised);

  --ui-tab-bg:transparent;
  --ui-tab-bg-active:var(--ui-surface);
  --ui-tab-ink:var(--ui-ink-muted);
  --ui-tab-ink-active:var(--ui-ink);
  --ui-tab-line:var(--ui-line);
  --ui-tab-radius:var(--ui-r-sm);
  --ui-tab-pad:var(--ui-s-2) var(--ui-s-3);

  /* Pixel frame (UX-002): the in-game panel language. A 9-slice drawn with box-shadows
     in UI pixels: paper fill, 1-px cocoa outline with notched corners, 1-px highlight
     (top/left) and shade (bottom/right) bevel, and a straight-down pixel drop that is
     1 px at rest and 2 px raised. No radius, no blur. Use as box-shadow on an element
     with border:0 and border-radius:0; components with their own fill (primary button,
     toast) build the same stack with their own bevel colours (see the mock CSS). */
  --ui-frame-fill:var(--ui-surface);
  --ui-frame-line:var(--ui-line);
  --ui-frame-hi:var(--ui-surface-hi);
  --ui-frame-shade:var(--ui-surface-shade);
  --ui-frame-drop:var(--ui-line-deep);
  --ui-frame-edge:0 calc(var(--ui-px) * -1) 0 0 var(--ui-frame-line),0 var(--ui-px) 0 0 var(--ui-frame-line),calc(var(--ui-px) * -1) 0 0 0 var(--ui-frame-line),var(--ui-px) 0 0 0 var(--ui-frame-line);
  --ui-frame-bevel:inset var(--ui-px) var(--ui-px) 0 0 var(--ui-frame-hi),inset calc(var(--ui-px) * -1) calc(var(--ui-px) * -1) 0 0 var(--ui-frame-shade);
  --ui-frame-rest:var(--ui-frame-bevel),var(--ui-frame-edge),0 calc(var(--ui-px) * 2) 0 0 var(--ui-frame-drop);
  --ui-frame-raised:var(--ui-frame-bevel),var(--ui-frame-edge),0 calc(var(--ui-px) * 3) 0 0 var(--ui-frame-drop);
  --ui-frame-flat:var(--ui-frame-bevel),var(--ui-frame-edge);

  --ui-dock-bg:var(--ui-frame-fill);
  --ui-dock-item-ink:var(--ui-ink);
  --ui-dock-item-hover:var(--ui-surface-sunk);
  --ui-dock-item-active:var(--ui-selected);
  --ui-dock-item-active-ink:var(--ui-ink-strong);
  --ui-dock-item-size:var(--ui-s-7);     /* 48px square hit area on phones, 64x56 on desktop */

  /* Focus timer: the 24-block pixel meter's width; on short screens the running clock block is
     as wide as it (ui-components.css). */
  --ui-timer-bar-w:284px;

  --ui-badge-bg:var(--ui-coin);
  --ui-badge-ink:var(--ui-ink-strong);

  /* Sticker (landing, sign-in): same tokens, rounded and chunky instead of pixel. */
  --ui-sticker-bg:var(--ui-surface);
  --ui-sticker-line:var(--ui-line);
  --ui-sticker-line-w:var(--ui-border-w);
  --ui-sticker-radius:var(--ui-r);
  --ui-sticker-shadow:var(--ui-elev-raised);
  --ui-sticker-pad:var(--ui-s-6);

  /* GROVE-3 (docs/WARDROBE.md): the Wardrobe gives each meaning its own colour. Forest bar and
     Wearing (paper text 6.0:1 on meadow-800), gold price pills (cocoa-700 text 8.5:1), a light
     stage. Selection stays the one peach (--ui-selected), as a ring. */
  --ui-wardrobe-page:var(--p-paper-100);
  --ui-wardrobe-bar:var(--p-meadow-800);
  --ui-wardrobe-bar-ink:var(--p-paper-50);
  --ui-wardrobe-stage:linear-gradient(180deg,var(--p-meadow-100) 0%,var(--p-paper-100) 78%);
  --ui-equipped:var(--p-meadow-800);
  --ui-equipped-ink:var(--p-paper-50);
  --ui-owned-ink:var(--p-meadow-800);
  --ui-price-bg:var(--p-gold-400);
  --ui-price-ink:var(--p-cocoa-700);
  --ui-price-short-bg:var(--p-paper-200);
}

/* Night (UX-022 "evening paper"): dimmer paper so long sessions don't glare.
   Defined only; applied once something sets <html data-ui-time="night">. */
:root[data-ui-time="night"]{
  --ui-surface:var(--p-paper-300);
  --ui-surface-sunk:var(--p-paper-400);
  --ui-surface-hi:var(--p-paper-100);
  --ui-surface-shade:var(--p-paper-400);
  --ui-success-ink:color-mix(in srgb,var(--p-meadow-800) 70%,var(--p-night-900)); /* 5.2:1 on paper-400 */
  --ui-scrim:color-mix(in srgb,var(--p-night-900) 50%,transparent);
}

/* Reduced motion: fades only. No travel, no press offset, no long slides. */
@media (prefers-reduced-motion: reduce){
  :root{
    --ui-travel:0px;
    --ui-press:0px;
    --ui-dur-slow:var(--ui-dur);
  }
}
