/*
  NeuroVision Звонок - design tokens v0.1 (task D1)
  Mobile-first. Two themes: light (default) and dark.
  - Pre-call screens follow the system theme (prefers-color-scheme) unless
    data-theme="light" | "dark" is set on <html>.
  - The call screen is always dark: put class "theme-call" on its root.
    Video looks better on dark, the screen glares less in a dim room.
  Palette: NeuroVision orange, black, white. Functional colors (danger,
  success, warning) exist only to carry state, never as decoration, and
  always come with a word or an icon (color is never the only signal).
  Contrast: every text/background pair below is WCAG AA (>= 4.5:1) or
  better; ratios are in the comments next to the pair.
  Rule for the orange fill: text on it is always black (7.5:1). White
  text on orange is forbidden (2.6:1).
*/

:root {
  /* ---------- Raw palette (do not use directly in components) ---------- */
  --nv-orange-300: #ffa866;
  --nv-orange-400: #ff8f45;
  --nv-orange-500: #ff7a1a;   /* brand orange, fill only */
  --nv-orange-600: #e8650a;
  --nv-orange-700: #b54a00;   /* orange text on white: 5.3:1 */
  --nv-black: #0b0b0c;
  --nv-white: #ffffff;

  --gray-50: #f6f5f3;
  --gray-100: #ecebe7;
  --gray-200: #d9d6d0;
  --gray-400: #8d8d94;
  --gray-500: #5a5a61;
  --gray-700: #2e2e33;
  --gray-800: #212124;
  --gray-850: #18181b;
  --gray-900: #111113;

  /* ---------- Typography ---------- */
  /* Inter when installed or self-hosted in web/; never fetched from a
     third party (a call page must not ping Google). Full system fallback. */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Scale 1.25 from 16px. fs--1 (14px) is the single exception below the
     base: tile captions and timestamps only, never body text or buttons. */
  --fs--1: 0.875rem;   /* 14px  caption */
  --fs-0: 1rem;        /* 16px  body, inputs (16px stops iOS zoom on focus) */
  --fs-1: 1.25rem;     /* 20px  lead, button large */
  --fs-2: 1.5625rem;   /* 25px  screen title */
  --fs-3: 1.953rem;    /* 31px  hero */
  --fs-4: 2.441rem;    /* 39px  big numbers: challenge step, countdown */

  --lh-tight: 1.2;
  --lh-base: 1.45;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --tracking-caps: 0.04em;

  /* ---------- Spacing (4px base) ---------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* ---------- Radii ---------- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  /* ---------- Hit targets and sizes ---------- */
  --tap-min: 44px;        /* absolute minimum for anything tappable */
  --btn-height: 56px;     /* primary and secondary buttons */
  --ctl-size: 56px;       /* round call controls */
  --input-height: 52px;
  --focus-ring: 3px;

  /* ---------- Motion ---------- */
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* ---------- Layers ---------- */
  --z-tile-overlay: 10;
  --z-controls: 20;
  --z-banner: 30;
  --z-sheet: 40;
  --z-toast: 50;

  /* ---------- Safe areas (notch, home indicator) ---------- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* ---------- Breakpoints (reference; CSS vars do not work in @media)
     mobile  < 600px   one column, controls at the bottom
     tablet  600-1023  two-column grid for 3-4 tiles
     desktop >= 1024   side panel (people, lobby) + grid */

  /* ---------- Semantic colors: LIGHT (default) ---------- */
  color-scheme: light;
  --color-bg: var(--nv-white);
  --color-surface: var(--gray-50);
  --color-surface-raised: var(--nv-white);
  --color-surface-sunken: var(--gray-100);
  --color-border: var(--gray-200);
  --color-border-strong: var(--gray-500);
  --color-text: var(--gray-900);           /* on bg 18.9:1 */
  --color-text-muted: var(--gray-500);     /* on bg 6.8:1, on surface 6.3:1 */
  --color-accent: var(--nv-orange-500);    /* fill */
  --color-accent-hover: var(--nv-orange-600);
  --color-on-accent: var(--nv-black);      /* on accent 7.5:1 */
  --color-accent-text: var(--nv-orange-700); /* on bg 5.3:1 */
  --color-accent-soft: #fff1e6;
  --color-focus: var(--nv-orange-700);

  --color-danger: #c42b2b;                 /* on bg 5.6:1 */
  --color-danger-soft: #fdecec;
  --color-success: #11774a;                /* on bg 5.6:1 */
  --color-success-soft: #e7f5ee;
  --color-warning: #8a5a00;                /* on bg 5.9:1 */
  --color-warning-soft: #fff5dc;

  --color-scrim: rgba(11, 11, 12, 0.62);   /* under text on video: white on it >= 5.4:1 even over a white frame */
  --color-on-scrim: var(--nv-white);
  --color-video-bg: var(--gray-850);

  --trust-fill: var(--nv-orange-500);
  --trust-empty: var(--gray-200);

  --shadow-1: 0 1px 2px rgba(11, 11, 12, 0.08), 0 2px 8px rgba(11, 11, 12, 0.06);
  --shadow-sheet: 0 -8px 32px rgba(11, 11, 12, 0.18);
}

/* ---------- Semantic colors: DARK ---------- */
/* Same block twice: explicit choice, and system preference without an explicit light choice. */
[data-theme="dark"],
.theme-call {
  color-scheme: dark;
  --color-bg: var(--nv-black);
  --color-surface: var(--gray-850);
  --color-surface-raised: var(--gray-800);
  --color-surface-sunken: var(--gray-900);
  --color-border: var(--gray-700);
  --color-border-strong: var(--gray-400);
  --color-text: #f5f5f4;                   /* on bg 18.0:1 */
  --color-text-muted: #a8a8ae;             /* on bg 8.3:1, on surface 7.5:1, on raised 6.8:1 */
  --color-accent: var(--nv-orange-500);
  --color-accent-hover: var(--nv-orange-400);
  --color-on-accent: var(--nv-black);
  --color-accent-text: var(--nv-orange-400); /* on bg 8.7:1 */
  --color-accent-soft: #2a1a0d;
  --color-focus: var(--nv-orange-300);

  --color-danger: #ff6b6b;                 /* on bg 7.1:1 */
  --color-danger-soft: #3a1515;
  --color-success: #3dd68c;                /* on bg 10.5:1 */
  --color-success-soft: #0f2a1d;
  --color-warning: #ffc247;                /* on bg 12.2:1 */
  --color-warning-soft: #33270b;

  --color-scrim: rgba(11, 11, 12, 0.62);
  --color-on-scrim: var(--nv-white);
  --color-video-bg: var(--gray-900);

  --trust-fill: var(--nv-orange-500);
  --trust-empty: var(--gray-500);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-bg: var(--nv-black);
    --color-surface: var(--gray-850);
    --color-surface-raised: var(--gray-800);
    --color-surface-sunken: var(--gray-900);
    --color-border: var(--gray-700);
    --color-border-strong: var(--gray-400);
    --color-text: #f5f5f4;
    --color-text-muted: #a8a8ae;
    --color-accent: var(--nv-orange-500);
    --color-accent-hover: var(--nv-orange-400);
    --color-on-accent: var(--nv-black);
    --color-accent-text: var(--nv-orange-400);
    --color-accent-soft: #2a1a0d;
    --color-focus: var(--nv-orange-300);
    --color-danger: #ff6b6b;
    --color-danger-soft: #3a1515;
    --color-success: #3dd68c;
    --color-success-soft: #0f2a1d;
    --color-warning: #ffc247;
    --color-warning-soft: #33270b;
    --color-video-bg: var(--gray-900);
    --trust-empty: var(--gray-500);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.6);
  }
}

/* Light theme forced explicitly (wins over the system dark preference). */
[data-theme="light"] {
  color-scheme: light;
}

/* Motion off when the person asked for it. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur-base: 0ms;
    --dur-slow: 0ms;
  }
}

/* High contrast request: borders get stronger, muted text gets darker. */
@media (prefers-contrast: more) {
  :root {
    --color-border: var(--color-border-strong);
  }
}
