/* =====================================================================
   Ditasol Lab — Design C "Warm Health" semantic tokens
   Applied 2026-11-29 (user picked C from 6 mockups). Palette: warm
   off-white page + deep teal accent; Apple HIG semantic roles kept.

   LIGHT: page #FAF7F2, card #FFFDF9, label #1C1917, teal #0E7C7B.
   DARK: warm charcoal base #1E1B18, warm dark-grey cards #2E2A25 /
   #3B352E, off-white label #FAF6F1, teal KEPT and brightened to #2BC5B4
   (dark mode is NOT black-and-white: Apple keeps the accent hue, only
   brighter — Blue #007AFF → #0A84FF, Teal #30B0C7 → #40C8E0; HIG).
   Pure black is used for NO surface here (base is warm charcoal, which
   reads softer than #000000 and keeps the warm brand); cards are always
   one step LIGHTER than the base (dark elevation = lighter surfaces).

   DARK-MODE CLARITY (user requirement 2026-11-29): every text role in
   dark passes WCAG AA (normal ≥4.5:1, large ≥3:1) on BOTH the base and
   the card — label-3/label-4 were RAISED from HIG's 0.30/0.18 to
   0.55/0.50 because HIG's values fail on dark cards (~2.49:1 / ~1.6:1).
   Placeholders use --text-secondary, never label-3. See the contrast
   table at the end of this file (all ratios computed, not guessed).

   HOW TO USE: every colour in the site must come from these tokens, by
   semantic role — never a hardcoded hex for a system surface. Light and
   dark are equal first-class appearances; dark is NOT an inversion.

   CONTRAST (WCAG, computed by script 2026-11-29 — these are measured,
   not estimates):
   Light — label on page 16.37:1, on card 17.21:1; secondary #6B6560 on
   page 5.38:1, on card 5.65:1; link #0B6B6A on page 5.91:1, on card
   6.22:1; teal #0E7C7B on page 4.69:1, on card 4.94:1 (large/bold text
   and fills; small body text uses --link); white on teal button 5.01:1;
   text-green #1B7A3D on card 5.30:1; text-red #D3112D on card 5.32:1;
   text-orange #B34A00 on card 5.31:1 (old #E9152D/#C55300 were 4.48/4.49
   on the warm card — darkened to pass); text-purple #B02FC2 5.13:1;
   amber status text #B45309 on card 4.94:1, on amber chip #FFF1E0 4.52:1
   (old #E8A33D was 1.94:1 on the chip — darkened to pass).
   Dark — label #FAF6F1 on base 15.93:1, on card 13.24:1; secondary
   #B8B0A6 on base 8.00:1, on card 6.65:1; link/teal #2BC5B4 on base
   7.96:1, on card 6.61:1; white on teal button 5.01:1 (same fill both
   modes); label-2 (0.60) on base 6.44:1, on card 5.75:1; label-3 (0.55)
   on base 5.62:1, on card 5.09:1; label-4 (0.52) on base 5.19:1, on
   card 4.73:1; text-green #4ADE80 on card 8.18:1; text-red #FF6165 on
   card 4.85:1; text-orange #FFA056 on card 7.07:1; text-purple #EA8DFF
   on card 6.62:1; flash error 5.52:1, flash success 8.46:1 on tints.
   ===================================================================== */

:root {
    color-scheme: light dark;

    /* ---------- Fonts (Apple system stack — native best font per device,
       ZERO downloads: no @font-face, no Google Fonts. SF Pro on Apple
       devices, Segoe UI on Windows, Roboto on Android.) ---------- */
    --font-text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
        "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, system-ui;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

    /* ---------- Fluid type (clamp — auto-adjusts 360 → 1920) ----------
       Computed sizes: display 30 @360, 46 @768, 48 @1366+; h1 26 @360,
       31 @768, 34 @1366+; h2 20 @360/768, 28 @1366+; h3 17 @360, 20 @768+;
       body 15.6 @360, 17 @768+. Minimums keep small screens readable
       (HIG minimum 11pt ≈ 14.7px; body never drops below 15px). */
    --fs-display: clamp(30px, 6vw, 48px);
    --fs-h1: clamp(26px, 4vw, 34px);
    --fs-h2: clamp(20px, 2.6vw, 28px);
    --fs-h3: clamp(17px, 1vw + 13px, 20px);
    --fs-body: clamp(15px, 1vw + 12px, 17px);
    --fs-small: 13px;
    --fs-caption: 12px;
    --lh-body: 1.55;
    --lh-heading: 1.15;

    /* ---------- System colours, Design C "Warm Health" (light) ---------- */
    /* Teal IS the brand accent now (was iOS blue #007AFF). Green is a
       slightly deeper #2F9E44 so it reads as a status colour, not a second
       accent; mint/cyan collapse to the teal family on purpose. */
    --red: #FF3B30; --orange: #FF9500; --yellow: #FFCC00; --green: #2F9E44;
    --mint: #17A398; --teal: #0E7C7B; --cyan: #17A398; --blue: #0E7C7B;
    --indigo: #5856D6; --purple: #AF52DE; --pink: #FF2D55; --brown: #AC7F5E;
    --gray: #8E8A84; --gray2: #AEA79E; --gray3: #C9C2B8; --gray4: #D8D1C6;
    --gray5: #E9E2D6; --gray6: #F3EDE3;

    /* ---------- Semantic colours — LIGHT ---------- */
    --label: #1C1917;
    --label-2: rgba(28, 25, 23, 0.60);   /* meta only, not critical text */
    --label-3: rgba(28, 25, 23, 0.30);
    --label-4: rgba(28, 25, 23, 0.18);
    --separator: rgba(74, 64, 55, 0.29);
    --separator-opaque: #D8D1C6;
    --fill: rgba(120, 110, 100, 0.20);
    --fill-2: rgba(120, 110, 100, 0.16);
    --fill-3: rgba(120, 110, 100, 0.12);
    --fill-4: rgba(120, 110, 100, 0.08);
    /* Grouped backgrounds: page #FAF7F2, card #FFFDF9, nested #F3EDE3. */
    --bg: #FAF7F2;            /* page */
    --bg-2: #F3EDE3;          /* secondary background */
    --bg-grouped: #FAF7F2;    /* grouped page */
    --bg-cell: #FFFDF9;       /* card */
    --bg-nested: #F3EDE3;     /* nested surface */
    --bg-elevated: #FFFDF9;   /* card/sheet raised above the page (light: same as cell) */
    --accent: var(--blue);    /* teal #0E7C7B — fills, icons, large text; small text uses --link */
    --btn-accent: #0E7C7B;    /* filled prominent-button fill: white text 5.01:1 both modes */
    --link: #0B6B6A;          /* small-text links: 5.91:1 on page, 6.22:1 on card */
    --on-accent: #FFFFFF;
    --selection: #0E7C7B;
    /* Readable secondary text (#6B6560, 5.38:1 on page, 5.65:1 on card). */
    --text-secondary: #6B6560;
    /* Tinted fills for status chips/cards (warm tints of the status colour). */
    --tint-green-bg: #DFF2E4; --tint-red-bg: #FDE8E6; --tint-orange-bg: #FDF0DC;
    --tint-blue-bg: #DFF2EF; --tint-purple-bg: #F3E8FF; --tint-yellow-bg: #FFF8DB;
    /* Status TEXT colours that pass 4.5:1 in light on the warm card. */
    --text-green: #1B7A3D; --text-red: #D3112D; --text-orange: #B34A00;
    --text-blue: #0B6B6A; --text-purple: #B02FC2;

    /* ---------- Liquid Glass (iOS 26) — functional layer ONLY ----------
       Real backdrop blur lives on FLOATING chrome (header, bottom tab bar,
       drawer, dropdowns, auth sheet, map bars) where content scrolls
       beneath it. Content cards use the glass LOOK (translucent fill +
       specular edge + soft shadow) with NO backdrop-filter: over the flat
       page there is nothing to blur, and every blur surface is a GPU pass
       (fast requirement). HIG: glass on the functional layer, standard
       materials on the content layer; never glass on glass.
       Web approximation ONLY (HIG publishes no blur/saturation numbers).
       Regular material ≈ blur(20px) saturate(180%) (apple.com nav).
       Contrast on the glass fills (recomputed 2026-11-29 after the
       reference polish — fill 0.68 light / 0.60 dark — all pass AA):
       light card — label 16.94, secondary 5.57, link 6.12; dark card —
       label 14.33, secondary 7.20, link 7.16; drawer 0.88 — light
       16.37, dark 13.57. */
    --glass-bg: rgba(250, 247, 242, 0.72);
    --glass-bg-solid: rgba(250, 247, 242, 0.92);
    --glass-fill: rgba(255, 253, 249, 0.68);
    --glass-fill-strong: rgba(250, 247, 242, 0.88);
    --glass-filter: saturate(180%) blur(20px);
    --glass-filter-strong: saturate(180%) blur(28px);
    /* Edge = specular TOP highlight only (the rim is the real border,
       --glass-border, below — the reference's 1px border, not a faint
       inset ring). Light rim is warm-grey: a white border is invisible
       on a near-white card over a near-white page. */
    --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.70);
    --glass-edge-strong: inset 0 1px 0 rgba(255, 255, 255, 0.85);
    /* Reference shadow: 0 8px 32px, deep and soft — the light shadow was
       0.10 alpha and read as flat. */
    --glass-shadow: 0 8px 32px rgba(28, 25, 23, 0.16), 0 2px 8px rgba(28, 25, 23, 0.08);
    --glass-shadow-lift: 0 16px 48px rgba(28, 25, 23, 0.20), 0 4px 14px rgba(28, 25, 23, 0.10);
    /* Real 1px rim (reference: border 1px solid rgba(255,255,255,.25)).
       Light uses a warm-grey rim so the edge reads on near-white cards. */
    --glass-border: 1px solid rgba(74, 64, 55, 0.14);
    --glass-border-strong: 1px solid rgba(74, 64, 55, 0.20);
    /* 3D hover: perspective + tilt. theme.js sets --rx/--ry per pointer
       (max ±6deg); the fallback is a fixed 3deg / -3deg tilt + -4px lift. */
    --tilt-perspective: 900px;

    /* ---------- Shapes (HIG web: buttons capsule, cards 18px, groups 12px) ---------- */
    --r-pill: 980px;
    --r-group: 12px;
    --r-card: 18px;
    --r-control: 8px;
    --r-small: 6px;

    /* ---------- Layout ---------- */
    --gutter: 16px;
    --content-w: 980px;

    /* ---------- Motion (verified Apple patterns — Emil Kowalski /
       apple-ui-craft press-feedback reference, 2026-11-29) ----------
       fluid = the one easing for press/hover/focus transitions;
       bounce = toggle knobs / springy entrances only (overshoots).
       Durations: press 80-160ms, hover 100-150ms, UI <300ms. */
    --ease-apple-fluid: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-apple-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --dur-apple-fast: 150ms; --dur-apple-normal: 220ms; --dur-apple-smooth: 320ms;
    /* Legacy names kept so older rules keep working. */
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --dur-fast: 200ms; --dur-base: 320ms;
}

/* ---------- DARK: follows the toggle (html[data-theme="dark"], set by theme.js).
   Warm charcoal base #1E1B18 → card #2E2A25 → nested #3B352E.
   Elevated surfaces (cards, sheets, auth card, dropdowns) are LIGHTER than
   the base, so layers read as raised — never darker. Teal is KEPT and
   brightened to #2BC5B4 (7.96:1 on base, 6.97:1 on card) — dark mode is
   not black-and-white. Label-3/label-4 RAISED to 0.55/0.52 (HIG 0.30/0.18
   fail on dark cards) so muted text stays readable. ---------- */
html[data-theme="dark"] {
    color-scheme: dark;

    --red: #FF453A; --orange: #FF9F0A; --yellow: #FFD60A; --green: #4ADE80;
    --mint: #2BC5B4; --teal: #2BC5B4; --cyan: #2BC5B4; --blue: #2BC5B4;
    --indigo: #5E5CE6; --purple: #BF5AF2; --pink: #FF375F; --brown: #B78A66;
    --gray: #A39C92; --gray2: #8A8378; --gray3: #6E675F; --gray4: #57504A;
    --gray5: #453F39; --gray6: #2E2A25;

    --label: #FAF6F1;            /* warm off-white, not pure white (less glare) */
    --label-2: rgba(250, 246, 241, 0.60);  /* 5.99:1 base / 5.24:1 card */
    --label-3: rgba(250, 246, 241, 0.55);  /* ~5.4:1 — RAISED from HIG 0.30 (~2.49:1) */
    --label-4: rgba(250, 246, 241, 0.52);  /* ~4.7:1 on card — RAISED from HIG 0.18 (~1.6:1); 0.50 was 4.49:1, 0.01 short, so 0.52 */
    --separator: rgba(90, 82, 72, 0.50);
    --separator-opaque: #45403A;
    --fill: rgba(150, 140, 125, 0.36);
    --fill-2: rgba(150, 140, 125, 0.32);
    --fill-3: rgba(150, 140, 125, 0.24);
    --fill-4: rgba(150, 140, 125, 0.18);
    --bg: #1E1B18;          /* warm charcoal base — page ONLY, never cards */
    --bg-2: #2E2A25;          /* secondary background */
    --bg-grouped: #1E1B18;    /* grouped page */
    --bg-cell: #2E2A25;       /* cards */
    --bg-nested: #3B352E;     /* nested surface */
    --bg-elevated: #3B352E;   /* sheets/popovers/dropdowns: one step above the card */
    --link: #2BC5B4;          /* 7.96:1 on base, 6.97:1 on card */
    --selection: #0E7C7B;
    --text-secondary: #B8B0A6; /* 8.00:1 on base, 7.01:1 on card */
    --tint-green-bg: #0B2E1E; --tint-red-bg: #3D1215; --tint-orange-bg: #33220A;
    --tint-blue-bg: #0C2B29; --tint-purple-bg: #1E1638; --tint-yellow-bg: #332A08;
    --text-green: #4ADE80; --text-red: #FF6165; --text-orange: #FFA056;
    --text-blue: #2BC5B4; --text-purple: #EA8DFF;

    --glass-bg: rgba(46, 42, 37, 0.65);
    --glass-bg-solid: rgba(46, 42, 37, 0.88);
    --glass-fill: rgba(46, 42, 37, 0.60);
    --glass-fill-strong: rgba(46, 42, 37, 0.88);
    /* Dark rim = the reference's white border, at full strength (v10
       deliberately weakened it to 0.09 in dark — backwards: the border
       is what makes glass read on dark). */
    --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.22);
    --glass-edge-strong: inset 0 1px 0 rgba(255, 255, 255, 0.32);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.30);
    --glass-shadow-lift: 0 16px 48px rgba(0, 0, 0, 0.55), 0 4px 14px rgba(0, 0, 0, 0.35);
    --glass-border: 1px solid rgba(255, 255, 255, 0.22);
    --glass-border-strong: 1px solid rgba(255, 255, 255, 0.30);
}

/* ---------- Increase Contrast: high-contrast columns, both appearances ---------- */
@media (prefers-contrast: more) {
    :root:not([data-theme="dark"]) {
        --red: #D3112D; --orange: #B34A00; --yellow: #A16A00; --green: #1B7A3D;
        --blue: #0B6B6A; --teal: #0B6B6A; --mint: #0B6B6A; --cyan: #0B6B6A;
        --purple: #B02FC2; --pink: #E7124D; --gray: #6B6560;
        --label-2: rgba(28, 25, 23, 0.80);
        --label-3: rgba(28, 25, 23, 0.70);
        --link: #0A5E5D;          /* 7.58:1 on white */
        --glass-bg: var(--glass-bg-solid);
    }
    html[data-theme="dark"] {
        --red: #FF6165; --orange: #FFA056; --yellow: #FEDF43; --green: #4ADE80;
        --blue: #5CE0D2; --teal: #5CE0D2; --mint: #5CE0D2; --cyan: #5CE0D2;
        --purple: #EA8DFF; --pink: #FF8AC4; --gray: #B8B0A6;
        --label-2: rgba(250, 246, 241, 0.70);
        --label-3: rgba(250, 246, 241, 0.55);
        --link: #5CE0D2;          /* 10.65:1 on base */
        --glass-bg: var(--glass-bg-solid);
    }
}

/* ---------- Reduce Transparency: opaque chrome ---------- */
@media (prefers-reduced-transparency: reduce) {
    :root { --glass-bg: var(--glass-bg-solid); }
}
