/* 小津助手 v2.1 — design tokens (single source of truth). Direction: B「温暖质感」+ A's section accents
   (docs/DESIGN-v21.md §1). Every colour/size in app CSS comes from here; one-off illustrations (the weather
   scene, playing cards) may hard-code pigments.
   Compatibility (WeChat iOS 15 / Chromium 100): plain custom properties only. No color-mix(), no nesting,
   no var() fallbacks that contain dvh. */

:root {
  color-scheme: light;

  /* ---- Surfaces: ivory paper, warm white cards ---- */
  --bg: #FBF5EC;              /* app background */
  --bg-elev: #FFFAF3;         /* tab bar, scrolled top bar */
  --surface: #FFFDFA;         /* cards, groups, sheets, composer */
  --surface-2: #F6EDE2;       /* inset fills: inputs, chips, pressed rows */
  --surface-3: #EEE2D3;       /* segmented track, pressed chips, switch off */
  --scrim: rgba(43, 30, 23, 0.42);
  --bg-fade: rgba(251, 245, 236, 0);   /* --bg at 0 alpha, for gradients into the page */

  /* ---- Lines ---- */
  --line: #EDE2D4;
  --line-strong: #DECDBA;

  /* ---- Text (warm ink) ---- */
  --text: #2B1E17;            /* 14.9:1 on bg */
  --text-2: #5F4B3E;          /* 7.6:1 */
  --text-3: #786457;          /* 5.2:1 on bg, 4.8:1 on surface-2 */
  --text-disabled: #B8A797;
  --text-inverse: #FFF8F1;    /* text on ink (toast) */

  /* ---- Primary: terracotta (actions, send, user bubble, focus) ---- */
  --primary: #C2522E;         /* white text 4.6:1 */
  --primary-hover: #B44A28;
  --primary-press: #A9441F;
  --primary-soft: #FCE6DA;
  --primary-soft-press: #F7D4C2;
  --primary-text: #A8401F;    /* 5.7:1 on bg */
  --on-primary: #FFFFFF;

  /* ---- Secondary: deep teal (switches on, done checks, success) ---- */
  --teal: #1F5E5A;            /* white text 7.5:1 */
  --teal-press: #184C49;
  --teal-soft: #DDEEEA;
  --teal-text: #1F5E5A;
  --on-teal: #FFFFFF;

  /* ---- Supporting warm hues (tiles, categories, illustrations only) ---- */
  --amber: #E3A53B;
  --amber-soft: #FBEBC9;
  --amber-text: #8A5A10;
  --rose: #D0697A;
  --rose-soft: #F9E1E4;
  --rose-text: #9E3D50;

  /* ---- Section accents (icon tiles, small highlights, section headers; never big fills).
         -ink: glyph colour (>= 3:1 on surface and on -soft); -text: AA text; -soft: tile background ---- */
  --chat-ink: #C2522E;     --chat-text: #A8401F;     --chat-soft: #FCE6DA;
  --life-ink: #3E8E4F;     --life-text: #2F7340;     --life-soft: #E3F1DF;
  --workshop-ink: #D9730D; --workshop-text: #A65408; --workshop-soft: #FDEBD3;
  --ddz-ink: #C8333A;      --ddz-text: #A82530;      --ddz-soft: #FADDDF;
  --me-ink: #2A8077;       --me-text: #1F5E5A;       --me-soft: #DDEEEA;
  --paint-ink: #8A5CC2;    --paint-text: #6E44A3;    --paint-soft: #EEE5F8;   /* AI 生图 */

  /* ---- Back-compat aliases (v2 names used by views and the 斗地主 UI) ---- */
  --accent: var(--primary);
  --accent-hover: var(--primary-hover);
  --accent-press: var(--primary-press);
  --accent-soft: var(--primary-soft);
  --accent-text: var(--primary-text);
  --on-accent: var(--on-primary);

  /* ---- Status (always paired with an icon and words) ---- */
  --danger: #B42318;
  --danger-soft: #FDE4E0;
  --warning: #8A5A10;
  --warning-soft: #FBEBC9;
  --success: #1F6E5F;
  --success-soft: #DDEEEA;

  /* ---- Todo priority rings (graphics: >= 3:1 against the card) ---- */
  --pri-urgent: #C8371F;
  --pri-important: #BF7E14;
  --pri-normal: #2F7F75;

  /* ---- Toast (ink pill) ---- */
  --toast-bg: #2B1E17;
  --toast-text: #FFF8F1;
  --toast-divider: rgba(255, 248, 241, 0.22);
  --toast-action: #F7B49A;

  /* ---- Elevation: warm-brown, layered, never coloured glows ---- */
  --shadow-1: 0 1px 2px rgba(84, 48, 24, 0.06), 0 2px 8px rgba(84, 48, 24, 0.05);
  --shadow-2: 0 2px 6px rgba(84, 48, 24, 0.06), 0 10px 26px rgba(84, 48, 24, 0.09);
  --shadow-3: 0 18px 44px rgba(84, 48, 24, 0.18), 0 4px 12px rgba(84, 48, 24, 0.08);
  --shadow-press: 0 1px 2px rgba(84, 48, 24, 0.08);
  --shadow-avatar: 0 8px 22px rgba(84, 48, 24, 0.20), 0 2px 6px rgba(84, 48, 24, 0.10);
  --avatar-ring: #FFFDFA;
  --sticker-bg: #FFFDFA;
  --lip: inset 0 -2px 0 rgba(60, 20, 5, 0.16);   /* tactile bottom edge on filled buttons */
  --edge: 0 0 0 1px rgba(84, 48, 24, 0.05);      /* hairline edge for photos on cream */
  --focus-ring: 0 0 0 3px rgba(194, 82, 46, 0.30);
  --press-tint: rgba(84, 48, 24, 0.06);           /* overlay for pressed custom surfaces */
  --on-scene-chip: rgba(255, 255, 255, 0.62);     /* chips sitting on the weather scene */
  --sheen: rgba(255, 255, 255, 0.62);             /* skeleton / image-loading shimmer highlight */
  --sheen-0: rgba(255, 255, 255, 0);
  --lh-wrap: 1.5;                                  /* UI text that may wrap (CJK needs air) */

  /* ---- Code (espresso block in both themes) ---- */
  --code-bg: #2B211B;
  --code-head: #34291F;
  --code-text: #F3E9DF;
  --code-dim: #A8978A;
  --code-inline-bg: #F3E8DA;
  --code-inline-text: #6B3A22;
  --code-keyword: #F4A285;
  --code-string: #BFDDA0;
  --code-number: #F2C878;
  --code-comment: #A08F82;
  --code-func: #93D3C7;

  /* ---- Playing cards & table (斗地主) ---- */
  --card-face: #FFFDF8;
  --card-edge: #E3D7C6;
  --card-red: #C0392B;
  --card-black: #2B1E17;
  --card-joker-big: #B23227;
  --card-joker-small: #2B1E17;
  --card-back: #A8403A;
  --card-back-pattern: rgba(255, 255, 255, 0.14);
  --card-selected-lift: 14px;
  --card-hint: #D9A441;
  --card-gold: #D9A441;
  --felt: #236A62;
  --felt-deep: #164641;
  --felt-line: rgba(255, 255, 255, 0.09);
  --felt-text: #FFF6EC;
  --felt-text-2: rgba(255, 246, 236, 0.82);
  --felt-gold: #F4CF80;
  --felt-chip: rgba(10, 30, 28, 0.28);
  --turn-ring: #F4CF80;
  --lobby-a: #B8322F;         /* 斗地主 lobby field (A's red hero, warmed) */
  --lobby-b: #D9573F;
  --on-lobby: #FFF6EF;

  /* ---- Typography: system sans only, strict scale 12/13/15/17/20/24/30 (+16 for inputs) ---- */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans",
    "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
  --fs-xs: 12px;              /* meta, timestamps, tab labels, badges */
  --fs-sm: 13px;              /* secondary lines, chips, labels */
  --fs-base: 15px;            /* body (minimum for running text) */
  --fs-input: 16px;           /* inputs only: iOS does not zoom at >= 16px */
  --fs-lg: 17px;              /* card titles, top-bar title, section titles */
  --fs-xl: 20px;
  --fs-2xl: 24px;             /* greetings, hero titles */
  --fs-3xl: 30px;             /* page titles, the date on 生活, big numbers */
  --fs-2xs: 11px;             /* LEGACY: 斗地主 felt micro-labels only. App UI must use 12+. */
  --fw-regular: 400;
  --fw-medium: 600;           /* v2.1 uses two weights: 400 and 600 (medium maps to 600) */
  --fw-semibold: 600;
  --fw-bold: 700;             /* big numbers and titles only */
  --lh-tight: 1.25;
  --lh-ui: 1.35;
  --lh-prose: 1.6;
  --tracking-tight: -0.01em;

  /* ---- Spacing (4px grid) ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 28px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --page-x: 16px;             /* the one horizontal page padding; every text left edge aligns to it */

  /* ---- Radii: 12 / 16 / 20 / 28, pills full ---- */
  --r-xs: 6px;                /* inline code, tiny tags only */
  --r-sm: 10px;               /* segmented thumb, small tiles inside cards */
  --r-md: 12px;               /* inputs, buttons, icon tiles */
  --r-lg: 16px;               /* cards, groups */
  --r-xl: 20px;               /* big cards, composer, hero */
  --r-2xl: 28px;              /* sheets, login card */
  --r-full: 999px;

  /* ---- Motion ---- */
  --dur-press: 80ms;          /* press-in: must feel instant */
  --dur-fast: 140ms;
  --dur: 180ms;               /* tab crossfade, toggles */
  --dur-slow: 260ms;
  --dur-page: 260ms;          /* subpage push / pop */
  --dur-sheet: 320ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
  --press-scale: 0.97;

  /* ---- Layout ---- */
  --topbar-h: 52px;
  --tabbar-h: 58px;
  --content-max: 680px;
  --tap: 44px;
  --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);

  /* ---- Z-index ---- */
  --z-topbar: 20;
  --z-tabbar: 30;
  --z-drawer: 40;
  --z-sheet: 50;
  --z-toast: 70;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Warm charcoal: roasted-brown blacks, never cold grey */
  --bg: #17120F;
  --bg-elev: #1D1713;
  --surface: #241D18;
  --surface-2: #2D251F;
  --surface-3: #392F28;
  --scrim: rgba(0, 0, 0, 0.58);
  --bg-fade: rgba(23, 18, 15, 0);

  --line: #362C25;
  --line-strong: #4A3D33;

  --text: #F5ECE3;
  --text-2: #CDBDAE;
  --text-3: #A3917F;
  --text-disabled: #6B5D52;
  --text-inverse: #2B1E17;

  --primary: #E67A57;         /* dark ink on it: 6.4:1 */
  --primary-hover: #EC8463;
  --primary-press: #D96D4B;
  --primary-soft: #3B231A;
  --primary-soft-press: #4A2C20;
  --primary-text: #F09A7C;
  --on-primary: #1E120C;

  --teal: #5DB3A6;
  --teal-press: #4FA195;
  --teal-soft: #19332F;
  --teal-text: #7FCABE;
  --on-teal: #0F1E1C;

  --amber: #E8B04F;
  --amber-soft: #3A2C14;
  --amber-text: #F0C574;
  --rose: #E58A99;
  --rose-soft: #3A1F25;
  --rose-text: #EFA3B0;

  --chat-ink: #F09A7C;     --chat-text: #F4A98E;     --chat-soft: #3B231A;
  --life-ink: #7CC68A;     --life-text: #8FD29B;     --life-soft: #1C3020;
  --workshop-ink: #F2A65A; --workshop-text: #F5B26E; --workshop-soft: #3A2814;
  --ddz-ink: #F07D80;      --ddz-text: #F49598;      --ddz-soft: #3D1D20;
  --me-ink: #6FC3B6;       --me-text: #7FCABE;       --me-soft: #19332F;
  --paint-ink: #B99AE6;    --paint-text: #C7ADEE;    --paint-soft: #2C2238;

  --danger: #F07B6B;
  --danger-soft: #3D1E19;
  --warning: #F0C574;
  --warning-soft: #3A2C14;
  --success: #7FCABE;
  --success-soft: #19332F;

  --pri-urgent: #F07B6B;
  --pri-important: #E8B04F;
  --pri-normal: #5DB3A6;

  --toast-bg: #F5ECE3;
  --toast-text: #2B1E17;
  --toast-divider: rgba(43, 30, 23, 0.18);
  --toast-action: #A8401F;

  --shadow-1: 0 0 0 1px rgba(255, 230, 210, 0.05), 0 2px 6px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 0 0 1px rgba(255, 230, 210, 0.06), 0 10px 26px rgba(0, 0, 0, 0.42);
  --shadow-3: 0 0 0 1px rgba(255, 230, 210, 0.07), 0 18px 48px rgba(0, 0, 0, 0.6);
  --shadow-press: 0 0 0 1px rgba(255, 230, 210, 0.05);
  --shadow-avatar: 0 8px 22px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 230, 210, 0.06);
  --avatar-ring: #E9DBCB;
  --sticker-bg: #3B3029;
  --lip: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
  --edge: 0 0 0 1px rgba(255, 230, 210, 0.08);
  --focus-ring: 0 0 0 3px rgba(230, 122, 87, 0.38);
  --press-tint: rgba(255, 230, 210, 0.06);
  --on-scene-chip: rgba(30, 22, 18, 0.55);
  --sheen: rgba(255, 225, 205, 0.08);
  --sheen-0: rgba(255, 225, 205, 0);

  --code-bg: #120E0B;
  --code-head: #1A1410;
  --code-dim: #9F8F82;
  --code-inline-bg: #33281F;
  --code-inline-text: #F4C2A6;

  /* Physical cards stay light in dark mode (legibility, realism); only the table darkens. */
  --card-face: #F7F0E6;
  --card-edge: #CDBFAC;
  --card-red: #B9352A;
  --card-black: #2B1E17;
  --card-back: #93372F;
  --card-hint: #F0C574;
  --felt: #1D564F;
  --felt-deep: #10332F;
  --felt-line: rgba(255, 255, 255, 0.07);
  --felt-text: #FFF6EC;
  --felt-text-2: rgba(255, 246, 236, 0.8);
  --felt-gold: #F0C574;
  --felt-chip: rgba(0, 0, 0, 0.26);
  --turn-ring: #F0C574;
  --lobby-a: #8F2826;
  --lobby-b: #B0442F;
  --on-lobby: #FFF3EA;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-press: 0ms;
    --dur-fast: 90ms;
    --dur: 120ms;
    --dur-slow: 160ms;
    --dur-page: 160ms;
    --dur-sheet: 180ms;
    --press-scale: 1;
  }
}
