/*
 * The dashboard's design tokens (UI redesign "Showroom", docs/ui-redesign/00-design-direction.md).
 *
 * Every colour, shadow, radius, space, type size and duration a stylesheet uses comes from here; hex
 * and rgb() literals are allowed in no other file (test-tokens.mjs, apart from its LEGACY_CSS list).
 * Two themes, named by role, not by colour:
 *   Cream (light, the default)  :root
 *   Walnut (dark)               :root[data-theme="walnut"], and again for a page without JS whose
 *                               system is dark (the @media block at the end: keep the two identical)
 * <html data-theme> is set before first paint by public/appearance.js, then by src/ui/useAppearance.js.
 * Every pair a component uses is checked against WCAG 2.2 by scripts/check-contrast.mjs (in the tests).
 */

:root {
  color-scheme: light;

  /* ---- colour: Cream ---- */
  --bg: #F3EADA;                 /* page */
  --surface: #FBF6EC;            /* cards, sheets */
  --surface-2: #EADFCB;          /* wells, inputs' rest state, table stripes: --text or --text-2 only */
  --line: #D6C7AD;               /* hairlines, input borders */
  --line-strong: #8A7860;        /* control borders that must reach 3:1 */
  --text: #2A2420;               /* body */
  --text-2: #574B41;             /* secondary */
  --text-3: #6F6156;             /* hints */
  --cabinet: #6B4226;            /* walnut: sidebar, tab bar, cabinet drawing */
  --cabinet-ink: #FBF6EC;        /* text on walnut */
  --mask: #26211E;               /* charcoal: screen bezels, primary button */
  --glow: #E9A23B;               /* the phosphor accent: fills, glows, the selected mark */
  --glow-ink: #8A5200;           /* the accent as text or icon on a surface */
  --on-glow: #2A2420;            /* text on an amber fill */
  --focus: #1F5FA8;              /* focus ring, 2px + 2px offset, never removed */
  --focus-on-cabinet: #FBF6EC;   /* focus ring on walnut wood (--focus is 1.34:1 on --cabinet) */

  /* the cabinet drawing (src/shell/cabinetModels.js ROLE_FILL): the sets' cream plastic, brass trim, the legs'
     darker walnut and the drawing's ink line; the walnut band is --cabinet, the masks and knobs --mask */
  --cab-shell: #E8DCC4;
  --cab-brass: #B48A3C;
  --cab-leg: #5A361E;
  --cab-line: #2E2017;

  /* the TV's status light (pi-client status_led.py): a vivid dot, and an -ink for the word beside it */
  --led-idle: #278A48;           /* Ready: green */
  --led-idle-ink: #1F6B3A;
  --led-listening: #2F74E0;      /* blue */
  --led-listening-ink: #1D4F9E;
  --led-thinking: #D93A3A;       /* red */
  --led-thinking-ink: #A82424;
  --led-speaking: var(--led-thinking);          /* the TV shows one red */
  --led-speaking-ink: var(--led-thinking-ink);
  --led-error: #B06A00;          /* Can't talk: amber */
  --led-error-ink: #8A4B00;
  --led-offline: #857B72;        /* grey */
  --led-offline-ink: #5F5750;

  /* feedback: a tint, an edge and a text colour per tone */
  --success-bg: #E3F1E4;
  --success-line: #4F9462;
  --success-ink: #1F6B3A;
  --warning-bg: #FBEBCB;
  --warning-line: #A57A2E;
  --warning-ink: #7A4A00;
  --danger-bg: #F8E0DC;
  --danger-line: #C46A62;
  --danger-ink: #A12020;
  --info-bg: #E1EAF6;
  --info-line: #6A8FC4;
  --info-ink: #1D4F9E;
  --danger-fill: #A12020;        /* the danger button */
  --on-danger: #FBF6EC;

  /* the Usage page's chart series (UI redesign, Task 10): each 3:1 on --surface and told apart from the
     others by eye and under red-green colour blindness (check-contrast.mjs SERIES); never alone: a
     legend with words, the numbers on hover or focus, and a table view go with them */
  --chart-voice: #2F6FBF;
  --chart-listening: #C2551F;
  --chart-ai: #1E8A63;
  --chart-talk: var(--chart-voice);   /* conversations: one series, the first colour */

  /* paper (UI redesign, Task 13): the Build guide's diagrams are drawn for white paper, so their card stays
     white in both themes, with dark words on it; a printout is black on white with grey rules */
  --paper: #FFFFFF;
  --paper-ink: #2A2420;
  --paper-line: #999999;

  /* warm shadows (brown, never grey-blue) */
  --shadow-1: 0 1px 2px rgb(74 46 24 / .10);
  --shadow-2: 0 2px 6px rgb(74 46 24 / .12), 0 8px 24px rgb(74 46 24 / .10);
  --shadow-3: 0 12px 40px rgb(74 46 24 / .22);

  /* ---- the same in both themes ---- */
  --glow-ring: 0 0 0 1px var(--glow), 0 0 22px color-mix(in srgb, var(--glow) 40%, transparent);
  --scanlines: repeating-linear-gradient(to bottom, rgb(0 0 0 / .18) 0 1px, transparent 1px 3px);

  /* type: Fraunces for display only (titles, big numbers), Atkinson Hyperlegible Next for everything else */
  --font-display: 'Fraunces', Georgia, serif;
  --font-text: 'Atkinson Hyperlegible Next', system-ui, sans-serif;
  --text-xs: .8125rem;           /* the smallest text anywhere */
  --text-sm: .875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --text-4xl: 3rem;
  --text-5xl: 4rem;              /* the landing page only */
  --leading-body: 1.5;
  --leading-head: 1.15;
  --tracking-tight: -0.015em;    /* the two biggest sizes */

  /* space: a 4px base */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;

  --radius-input: 6px;           /* inputs, chips */
  --radius-btn: 10px;            /* buttons, small cards */
  --radius-card: 16px;
  --radius-sheet: 24px;          /* sheets, the screen card */
  --radius-pill: 999px;

  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --dur-channel: 160ms;          /* the channel change between areas */
  --ease: cubic-bezier(.2,.8,.2,1);

  --target: 44px;                /* the smallest touch target */
  --col-form: 720px;             /* content column for forms */
  --col-media: 1120px;           /* … and for media grids */
  --sidebar-w: 232px;
  --rail-w: 72px;
  --preview-w: 320px;            /* 360px from 1280px, below */
  --bar-h: 56px;                 /* the phone tab bar, before the safe area */
  --chrome-bottom: 0px;          /* fixed chrome along the bottom (the shell's tab bar sets it): toasts and the save bar sit above it */
}

:root[data-theme="walnut"] {
  color-scheme: dark;

  --bg: #1B1410;
  --surface: #271D17;
  --surface-2: #33261D;
  --line: #4B3A2C;
  --line-strong: #8C7A63;
  --text: #F4EAD8;
  --text-2: #D2C3AB;
  --text-3: #A99A85;
  --cabinet: #8A5A36;
  --cabinet-ink: #FBF6EC;
  --mask: #0F0B09;
  --glow: #F3B552;
  --glow-ink: #F3B552;
  --on-glow: #2A2420;
  --focus: #8CC4FF;
  --focus-on-cabinet: #FBF6EC;

  --cab-shell: #D9CAAE;
  --cab-brass: #C69A4A;
  --cab-leg: #6E4527;
  --cab-line: #0B0806;

  --led-idle: #4CC777;
  --led-idle-ink: #7FDB9C;
  --led-listening: #5B9BFF;
  --led-listening-ink: #9CC3FF;
  --led-thinking: #F25C5C;
  --led-thinking-ink: #FF9B9B;
  --led-speaking: var(--led-thinking);
  --led-speaking-ink: var(--led-thinking-ink);
  --led-error: #F5A524;
  --led-error-ink: #FFC870;
  --led-offline: #857A70;
  --led-offline-ink: #BDB2A5;

  --success-bg: #1E2E22;
  --success-line: #3F7A52;
  --success-ink: #8FE0A8;
  --warning-bg: #352713;
  --warning-line: #8A6A2E;
  --warning-ink: #FFC870;
  --danger-bg: #3A1C1A;
  --danger-line: #A65A54;
  --danger-ink: #FFA8A0;
  --info-bg: #1C2633;
  --info-line: #5A7FAD;
  --info-ink: #9CC3FF;
  --danger-fill: #E8655E;
  --on-danger: #1B1410;

  --chart-voice: #5B97E0;
  --chart-listening: #E0784A;
  --chart-ai: #38B486;
  --chart-talk: var(--chart-voice);

  --paper: #FFFFFF;
  --paper-ink: #2A2420;
  --paper-line: #999999;

  /* Walnut lifts with a lighter top edge more than with shadow */
  --shadow-1: inset 0 1px 0 rgb(255 240 220 / .06);
  --shadow-2: inset 0 1px 0 rgb(255 240 220 / .07), 0 2px 8px rgb(0 0 0 / .35);
  --shadow-3: inset 0 1px 0 rgb(255 240 220 / .08), 0 16px 48px rgb(0 0 0 / .5);
}

@media (min-width: 1280px) {
  :root { --preview-w: 360px; }
}

/* No JS (or before it runs) and a dark system: Walnut. Keep this body identical to the one above. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --bg: #1B1410;
    --surface: #271D17;
    --surface-2: #33261D;
    --line: #4B3A2C;
    --line-strong: #8C7A63;
    --text: #F4EAD8;
    --text-2: #D2C3AB;
    --text-3: #A99A85;
    --cabinet: #8A5A36;
    --cabinet-ink: #FBF6EC;
    --mask: #0F0B09;
    --glow: #F3B552;
    --glow-ink: #F3B552;
    --on-glow: #2A2420;
    --focus: #8CC4FF;
    --focus-on-cabinet: #FBF6EC;

    --cab-shell: #D9CAAE;
    --cab-brass: #C69A4A;
    --cab-leg: #6E4527;
    --cab-line: #0B0806;

    --led-idle: #4CC777;
    --led-idle-ink: #7FDB9C;
    --led-listening: #5B9BFF;
    --led-listening-ink: #9CC3FF;
    --led-thinking: #F25C5C;
    --led-thinking-ink: #FF9B9B;
    --led-speaking: var(--led-thinking);
    --led-speaking-ink: var(--led-thinking-ink);
    --led-error: #F5A524;
    --led-error-ink: #FFC870;
    --led-offline: #857A70;
    --led-offline-ink: #BDB2A5;

    --success-bg: #1E2E22;
    --success-line: #3F7A52;
    --success-ink: #8FE0A8;
    --warning-bg: #352713;
    --warning-line: #8A6A2E;
    --warning-ink: #FFC870;
    --danger-bg: #3A1C1A;
    --danger-line: #A65A54;
    --danger-ink: #FFA8A0;
    --info-bg: #1C2633;
    --info-line: #5A7FAD;
    --info-ink: #9CC3FF;
    --danger-fill: #E8655E;
    --on-danger: #1B1410;

    --chart-voice: #5B97E0;
    --chart-listening: #E0784A;
    --chart-ai: #38B486;
    --chart-talk: var(--chart-voice);

    --paper: #FFFFFF;
    --paper-ink: #2A2420;
    --paper-line: #999999;

    /* Walnut lifts with a lighter top edge more than with shadow */
    --shadow-1: inset 0 1px 0 rgb(255 240 220 / .06);
    --shadow-2: inset 0 1px 0 rgb(255 240 220 / .07), 0 2px 8px rgb(0 0 0 / .35);
    --shadow-3: inset 0 1px 0 rgb(255 240 220 / .08), 0 16px 48px rgb(0 0 0 / .5);
  }
}
