/* ==========================================================================
   Design tokens — Semantic + Component layers
   Maps primitives (tokens.css) to meaning, per theme. Components consume
   ONLY the names in this file (or the already-existing --primary/--text-main/
   --border-light/--bg-body/--bg-surface family, which were already semantic
   and are left alone) — never a primitive, never a raw hex.
   ========================================================================== */

:root {
    /* --- Semantic: color --- */
    --bg-body: var(--cream-100);
    --bg-surface: var(--cream-50);
    --primary: var(--ink-900);
    --primary-light: var(--ink-700);
    --text-main: var(--ink-900);
    --text-muted: #6f6155;
    --border-light: var(--clay-200);

    --color-primary: var(--teal-600);
    --color-primary-hover: var(--teal-700);
    --color-primary-text: var(--teal-600);
    /* clears 4.5:1 on its own against bg-body/bg-surface — no separate darkened variant needed */
    --color-highlight: var(--orange-500);
    /* decorative/badge/graphic use only — ~2:1 contrast, never small text */
    --color-positive: var(--moss-600);
    --color-positive-soft: var(--sage-500);
    --color-warning: var(--amber-500);
    --color-danger: var(--red-500);

    /* --- Semantic: border weight --- */
    --border-subtle: var(--clay-200);
    --border-default: #d8cabb;
    --border-strong: #a79885;

    /* --- Semantic: radius --- */
    --radius-xs: 3px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* --- Semantic: elevation --- */
    --shadow-xs: 0 2px 4px rgba(33, 29, 26, 0.05);
    --shadow-sm: 0 4px 12px rgba(33, 29, 26, 0.08);
    --shadow-md: 0 10px 24px rgba(33, 29, 26, 0.1);
    --shadow-lg: 0 20px 40px rgba(33, 29, 26, 0.14);
    --shadow-glass: 0 8px 32px rgba(33, 29, 26, 0.07);

    /* --- Component tokens --- */
    --button-bg: var(--color-primary);
    --button-bg-hover: var(--color-primary-hover);
    --calendar-selected-bg: var(--color-primary);
    --chat-bubble-user-bg: var(--color-primary);
    --chat-bubble-ai-bg: var(--bg-surface);
    --modal-overlay-bg: rgba(33, 29, 26, 0.35);
    --rail-bg: var(--ink-900);
    --rail-icon: var(--sand-500);
    --rail-icon-active: var(--sand-200);
}

[data-theme="dark"] {
    --bg-body: var(--umber-900);
    --bg-surface: var(--umber-800);
    --primary: var(--sand-200);
    --primary-light: #d8cabb;
    --text-main: var(--sand-200);
    --text-muted: var(--sand-500);
    --border-light: var(--charcoal-700);
    background-color: var(--umber-900);

    --color-primary: var(--teal-400);
    --color-primary-hover: #58e0d4;
    --color-primary-text: var(--teal-400);
    --color-highlight: var(--orange-400);
    --color-positive: var(--moss-400);
    --color-positive-soft: #57cf9e;
    --color-warning: var(--amber-500);
    --color-danger: #f87171;

    --border-subtle: var(--charcoal-700);
    --border-default: #4a4038;
    --border-strong: #6f6155;

    --radius-xs: 3px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    --shadow-xs: 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 28px 70px rgba(0, 0, 0, 0.55);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.4);

    --button-bg: var(--color-primary);
    --button-bg-hover: var(--color-primary-hover);
    --calendar-selected-bg: var(--color-primary);
    --chat-bubble-user-bg: var(--color-primary);
    --chat-bubble-ai-bg: var(--bg-surface);
    --modal-overlay-bg: rgba(0, 0, 0, 0.5);
    --rail-bg: #0e0c0a;
    --rail-icon: var(--sand-500);
    --rail-icon-active: var(--sand-200);
}

[data-theme^="stardew"] {
    --bg-body: var(--wheat-100);
    --bg-surface: var(--wheat-50);
    --primary: var(--soil-900);
    --primary-light: var(--soil-700);
    --text-main: var(--soil-900);
    --text-muted: var(--wheat-600);
    --border-light: var(--wheat-border);
    background-color: var(--wheat-100);

    --color-primary: var(--fern-600);
    --color-primary-hover: var(--fern-700);
    --color-primary-text: var(--fern-600);
    --color-highlight: var(--gold-500);
    --color-positive: var(--fern-600);
    --color-positive-soft: #8fbf6b;
    --color-warning: var(--gold-500);
    --color-danger: var(--rust-600);

    --border-subtle: var(--wheat-border);
    --border-default: #c4a366;
    --border-strong: var(--wheat-600);

    --radius-xs: 2px;
    --radius-sm: 3px;
    --radius-md: 3px;
    --radius-lg: 4px;
    --radius-xl: 6px;
    --radius-pill: 999px;

    /* Pixel art has zero blur — every shadow below is a hard, zero-blur offset
       instead of the soft/diffuse shadows used elsewhere, so anything that
       consumes --shadow-* automatically gets the chunky game-UI look. */
    --shadow-xs: 2px 2px 0 rgba(77, 51, 25, 0.35);
    --shadow-sm: 3px 3px 0 rgba(77, 51, 25, 0.35);
    --shadow-md: 4px 4px 0 rgba(77, 51, 25, 0.35);
    --shadow-lg: 6px 6px 0 rgba(77, 51, 25, 0.35);
    --shadow-glass: 4px 4px 0 rgba(77, 51, 25, 0.25);

    /* Beveled wood-frame panel primitive — a two-ring, zero-blur box-shadow
       stack (lighter bevel ring, then the dark wood ring) reused everywhere
       a "framed panel" is needed: modals, drawers, buddy stat box, bubbles. */
    --panel-frame: 0 0 0 2px var(--wheat-bevel), 0 0 0 5px var(--soil-900);
    --portrait-backdrop: #bfe3f0;

    --button-bg: var(--color-primary);
    --button-bg-hover: var(--color-primary-hover);
    --calendar-selected-bg: var(--color-primary);
    --chat-bubble-user-bg: var(--color-primary);
    --chat-bubble-ai-bg: var(--bg-surface);
    --modal-overlay-bg: rgba(77, 51, 25, 0.35);
    --rail-bg: var(--soil-900);
    --rail-icon: var(--wheat-600);
    --rail-icon-active: var(--wheat-100);

    --cursor-clickable: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' shape-rendering='crispEdges'%3E%3Cpolygon points='2,2 2,15 5,12 8,18 11,16 8,10 14,10' fill='%23e8b84b' stroke='%232b1b0e' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E") 2 2, pointer;
}

/* ==========================================================================
   Stardew — LATE NIGHT ("深夜")
   A night variant of the Stardew theme. Because every structural rule is now
   scoped [data-theme^="stardew"], this value inherits all the pixel/wood
   structure automatically — this block only re-points the COLOR tokens to a
   moonlit palette (deep indigo night-sky surfaces, moonlit-parchment text,
   dim lantern-amber wood frames, glowing gold/green accents). Radius, cursor,
   and other non-color tokens are inherited unchanged from the shared block
   above. Hardcoded-hex component rules that don't read these tokens are
   flipped in the night override section at the end of components.css.
   ========================================================================== */
[data-theme="stardew-night"] {
    --bg-body: #1b2138;
    --bg-surface: #2b3048;
    --primary: #ece0c4;
    --primary-light: #d8cba8;
    --text-main: #ece0c4;
    --text-muted: #a99e86;
    --border-light: #6b5a3a;
    background-color: #1b2138;

    /* Accents lifted a step brighter so they glow against the dark ground. */
    --color-primary: #6b9e46;
    --color-primary-hover: #7cae54;
    --color-primary-text: #8bbf63;
    --color-highlight: #f5c95a;
    --color-positive: #6b9e46;
    --color-positive-soft: #4f7a3f;
    --color-warning: #f5c95a;
    --color-danger: #e0654a;

    --border-subtle: #453f31;
    --border-default: #6b5a3a;
    --border-strong: #8a7550;

    /* Zero-blur hard shadows kept, tint moved from warm brown to near-black
       so panels still read as raised against the night ground. */
    --shadow-xs: 2px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-sm: 3px 3px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 4px 4px 0 rgba(0, 0, 0, 0.5);
    --shadow-lg: 6px 6px 0 rgba(0, 0, 0, 0.5);
    --shadow-glass: 4px 4px 0 rgba(0, 0, 0, 0.4);

    /* Wood frame at night: a dim amber bevel over a very dark outer ring. */
    --panel-frame: 0 0 0 2px #4a3d28, 0 0 0 5px #10131f;
    --portrait-backdrop: #24304f;

    --modal-overlay-bg: rgba(6, 9, 20, 0.6);
    --rail-bg: #12101a;
    --rail-icon: #a99e86;
    --rail-icon-active: #f0e4c8;

    /* Re-point the Stardew PRIMITIVE ramp for night. Many component rules read
       these primitives directly via var(); flipping them here flips all those
       usages at once. Only the *non-overloaded* primitives are redefined —
       --soil-900 is deliberately left at its day value because it's used both
       as text (which the night override block recolors per-selector) AND as
       hard drop-shadows / frame edges, which *should* stay dark at night. */
    --wheat-50: #2b3048;   /* raised panel surface */
    --wheat-100: #20263f;  /* recessed slot (xp track, pips, avatar box) */
    --wheat-600: #a99e86;  /* muted parchment text */
    --wheat-border: #6b5a3a; /* dim lantern-amber frame line */
    --wheat-bevel: #4a3d28;
    --gold-500: #f5c95a;   /* lantern gold */
    --fern-600: #6b9e46;   /* night fern green */
    --fern-700: #7cae54;
    --rust-600: #e0654a;
}
