/*
 * KAN-894: the one place that decides light or dark, and the colours every
 * page uses.
 *
 * Every page loads this file first. Pages and stylesheets use only these
 * tokens (var(--…)); they never write a colour of their own and never say
 * prefers-color-scheme. scripts/testColorTokens.ts fails the build when one
 * does. A new page that uses the tokens works in both modes without anyone
 * thinking about it.
 *
 * Light values sit on :root. Dark values sit in the one media block below.
 * (Not light-dark(): older iOS Safari drops the whole declaration, and the
 * page would lose its backgrounds.)
 *
 * The tokens are semantic: what a colour is for, not what it looks like.
 * Add one only when two places need it.
 *
 * The dark palette is the approved tutorial and profile spec (KAN-981):
 * page #121212, cards #1E1E1E, the green card family #16241B with #22392A
 * dividers, text #F3F4F6, muted #9CA3AF, green text #4ADE80. Solid green
 * buttons keep the brand green in both modes.
 */

:root {
    color-scheme: light dark;

    /* Page and surfaces */
    --bg: #FFFFFF;               /* the page */
    --bg-raised: #F8FAFC;        /* bands and panels set off from the page */
    --bg-accent: #F0FDF4;        /* the green-tinted card family */
    --bg-accent-cool: #ECFEFF;   /* far end of the green card's gradient (profile summary) */
    --bg-accent-feature: #EDE9FE; /* far end of the green-to-purple card (app invite) */
    --surface: #FFFFFF;          /* cards, inputs, menus, modals */
    --surface-sunken: #F3F4F6;   /* wells, tracks, neutral chips */
    --nav-bg: rgba(255, 255, 255, 0.97);
    --overlay: rgba(0, 0, 0, 0.5);
    --surface-veil: rgba(255, 255, 255, 0.7); /* frosted cover over content */

    /* Text */
    --text: #1F2937;
    --text-muted: #4B5563;
    --text-subtle: #6B7280;      /* captions and placeholders; not for body text */

    /* Lines */
    --border: #E5E7EB;
    --border-strong: #D1D5DB;    /* input outlines */

    /* Brand. --accent is the solid green (buttons, bars); text on it is
       --on-accent. Green words on the page use --accent-text, which is dark
       enough to read on white and light enough to read on #121212. */
    --accent: #16A34A;
    --accent-strong: #15803D;    /* hover and pressed */
    --accent-deep: #166534;      /* the dark end of buttons that carry small white text */
    --accent-bright: #22C55E;
    --accent-text: #15803D;
    --on-accent: #FFFFFF;
    --on-accent-veil: rgba(255, 255, 255, 0.3); /* shimmer and pressed tints on solid colour */
    --on-accent-wash: rgba(255, 255, 255, 0.15); /* light chips on solid colour */
    --shade: rgba(0, 0, 0, 0.2);  /* dark chips on solid colour */
    --edge-on-black: transparent; /* an edge for black brand badges (App Store) that only shows on a dark page */
    --apple-badge: #000000;      /* Apple's App Store badge: black on light, white on dark */
    --on-apple-badge: #FFFFFF;
    --glow-accent: none;         /* the green glow behind buttons on a dark page */
    --device-frame: #1F2937;     /* the bezel of phone mock-ups */
    --app-bg: #F7F8F9;           /* the app's own screen background, behind its screenshots */
    --brand-purple: #7C3AED;
    --brand-indigo: #4F46E5;
    --brand-night: #312E81;      /* the tutorial's purple stage, both modes */
    --accent-glow: #4ADE80;      /* bright green on the purple stage and focus rings, both modes */
    --accent-glow-rgb: 74, 222, 128;
    --accent-rgb: 22, 163, 74;   /* for rgba(var(--accent-rgb), a) tints of the solid green */
    --accent-chip: #DCFCE7;      /* pale green chips and icon tiles */
    --accent-chip-text: #14532D;
    --focus: rgba(22, 163, 74, 0.25);
    --accent-wash: rgba(22, 163, 74, 0.08); /* hover tint behind green things */
    --shadow-accent: 0 2px 8px rgba(22, 163, 74, 0.3);
    --shadow-accent-hover: 0 4px 16px rgba(22, 163, 74, 0.4);

    /* States: text, background, border for each */
    --danger: #DC2626;
    --danger-strong: #B91C1C;
    --danger-bg: #FEF2F2;
    --danger-border: #FECACA;
    --danger-ring: rgba(220, 38, 38, 0.15);
    --danger-band: rgba(220, 38, 38, 0.35); /* a range to avoid, on a track */
    --success: #15803D;
    --success-bg: #F0FDF4;
    --success-border: #BBF7D0;
    --warning: #B45309;
    --warning-bg: #FFFBEB;
    --warning-border: #FDE68A;
    --info: #1D4ED8;
    --info-bg: #EFF6FF;
    --info-border: #BFDBFE;
    --feature: #6D28D9;          /* the purple "new" and plan family */
    --feature-bg: #F5F3FF;
    --feature-border: #DDD6FE;

    /* The bipolar rating palette, mirrors the Flutter app (app_theme.dart
       kRating*). Solid chips, the same in both modes. */
    --rating-neg-3: #DC2626;     /* Hate */
    --rating-neg-2: #F97316;     /* Dislike */
    --rating-neg-1: #FBBF24;     /* Slightly dislike */
    --rating-zero: #9CA3AF;      /* Neutral */
    --rating-pos-1: #86EFAC;     /* Slightly like */
    --rating-pos-2: #22C55E;     /* Like */
    --rating-pos-3: #16A34A;     /* Love */
    --rating-pos-1-text: #14532D; /* text on the pale chips */
    --rating-neg-1-text: #78350F;
    --chart-android-text: #15803D; /* the Android green as text; #3DDC84 is too pale on white */
    /* The same as r, g, b, for alpha tints: rgba(var(--rating-pos-2-rgb), 0.1) */
    --rating-zero-rgb: 156, 163, 175;
    --rating-pos-1-rgb: 134, 239, 172;
    --rating-pos-2-rgb: 34, 197, 94;
    --rating-pos-3-rgb: 22, 163, 74;

    /* Charts (admin): platform colours, the same in both modes */
    --chart-ios: #007AFF;
    --chart-android: #3DDC84;
    --chart-unknown: #9CA3AF;
    --chart-blue: #2563EB;

    /* Shadows */
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-small: 0 1px 3px rgba(0, 0, 0, 0.08);
    /* Cards floating on the purple stage (the tutorial), both modes */
    --shadow-on-brand: 0 28px 56px rgba(23, 12, 74, 0.4);
    --shadow-on-brand-small: 0 8px 20px rgba(23, 12, 74, 0.28);
    --shadow-float: 0 24px 50px rgba(0, 0, 0, 0.18); /* phone mock-ups */
}

/* Safari paints overscroll (pull to refresh, rubber band) with the <html>
   background, so the root carries the page colour, not just <body>. */
html {
    background: var(--bg);
    color: var(--text);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121212;
        --bg-raised: #1A1A1A;
        --bg-accent: #16241B;
        --bg-accent-cool: #132A2E;
        --bg-accent-feature: #241B3A;
        --surface: #1E1E1E;
        --surface-sunken: #2A2A2A;
        --nav-bg: rgba(18, 18, 18, 0.97);
        --overlay: rgba(0, 0, 0, 0.7);
        --surface-veil: rgba(30, 30, 30, 0.7);

        --text: #F3F4F6;
        --text-muted: #9CA3AF;
        --text-subtle: #9CA3AF;

        --border: #22392A;
        --border-strong: #3F3F46;

        --accent: #16A34A;
        --accent-strong: #15803D;
        --accent-deep: #166534;
        --accent-bright: #22C55E;
        --accent-text: #4ADE80;
        --on-accent: #FFFFFF;
        --on-accent-veil: rgba(255, 255, 255, 0.3);
        --on-accent-wash: rgba(255, 255, 255, 0.15);
        --shade: rgba(0, 0, 0, 0.2);
        --edge-on-black: #3F3F46;
        --apple-badge: #FFFFFF;
        --on-apple-badge: #000000;
        --glow-accent: 0 0 40px rgba(34, 197, 94, 0.25);
        --device-frame: #3F3F46;
        --app-bg: #121212;
        --brand-purple: #7C3AED;
        --brand-indigo: #4F46E5;
        --accent-chip: #1F3A2A;
        --accent-chip-text: #86EFAC;
        --chart-android-text: #3DDC84;
        --focus: rgba(74, 222, 128, 0.35);
        --accent-wash: rgba(74, 222, 128, 0.08);
        --shadow-accent: 0 2px 8px rgba(0, 0, 0, 0.45);
        --shadow-accent-hover: 0 4px 16px rgba(0, 0, 0, 0.55);

        --danger: #F87171;
        --danger-strong: #FCA5A5;
        --danger-bg: #3B1515;
        --danger-border: #7F1D1D;
        --danger-ring: rgba(248, 113, 113, 0.3);
        --danger-band: rgba(248, 113, 113, 0.4);
        --success: #4ADE80;
        --success-bg: #16241B;
        --success-border: #22392A;
        --warning: #FBBF24;
        --warning-bg: #3A2A0B;
        --warning-border: #78530F;
        --info: #93C5FD;
        --info-bg: #172554;
        --info-border: #1E3A8A;
        --feature: #C4B5FD;
        --feature-bg: #2E1065;
        --feature-border: rgba(167, 139, 250, 0.45);

        --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
        --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.55);
        --shadow-small: 0 1px 3px rgba(0, 0, 0, 0.45);
        --shadow-float: 0 24px 50px rgba(0, 0, 0, 0.5);
    }
}
