/* ═══════════════════════════════════════════════════════════════════
   ExamFlow design tokens (audit 01-design-system §3)
   Load order: tokens.css → components.css. Light values on :root,
   dark values on [data-theme="dark"] (set on <html> before first paint).

   Cascade layers (declared first, so the order is fixed for every file):
     a11y        only !important rules that must beat everything, e.g. reduced motion.
                 Inside layers, !important precedence is reversed: the EARLIEST layer
                 wins, which is why this layer comes first.
     base        reset, element defaults, type scale, focus ring (components.css)
     components  .btn .card .field … (components.css)
     utilities   single-purpose helpers (components.css)
═══════════════════════════════════════════════════════════════════ */
@layer a11y, base, components, utilities;

:root {
  color-scheme: light;

  /* ── Neutrals (warm) ─────────────────────────────── */
  --bg:            #FFFBF7;  /* app canvas */
  --surface:       #FFFFFF;  /* cards, sheets, inputs */
  --sunken:        #FFF6ED;  /* input fill, table header, chip idle */
  --hover:         #FFEEDC;  /* row / ghost hover */
  --border:        #F0E4D8;  /* decorative dividers only (1.25:1) */
  --border-2:      #E5D5C3;  /* decorative component edges and neutral lips (1.43:1, not for controls) */
  --border-strong: #9C8670;  /* input / checkbox edges: 3.47:1 on surface */
  --text-1:        #3D3229;  /* 12.45 on surface */
  --text-2:        #6B5B4C;  /*  6.51 */
  --text-3:        #7A6A5A;  /*  5.20: placeholders, captions */
  --text-disabled: #B3A392;  /* disabled / decorative only */

  /* ── Brand ───────────────────────────────────────── */
  --brand:         #FF6B00;  /* logo, flame, progress, illustration. Never under text. */
  --brand-soft:    #FFEEDC;
  --primary:       #C2410C;  /* button / chip fill: white text 5.18 */
  --primary-lip:   #9A3412;
  --primary-hover: #B34700;  /* white 5.50 */
  --on-primary:    #FFFFFF;
  --primary-text:  #B34700;  /* orange text, links, active nav: 5.50 */
  --focus:         #C2410C;
  --grad-primary:  linear-gradient(135deg, #B34700 0%, #C2410C 100%);
  --grad-brand:    linear-gradient(135deg, #FF6B00 0%, #FF9433 100%); /* decorative only */

  /* ── Status: fill (decor/lip) · text (≥4.5) · soft bg ─ */
  --success: #58CC02; --success-lip: #58A700; --success-text: #2E7D00; --success-bg: #EAF7DC; --success-btn-lip: #1F5600;
  --danger:  #FF4B4B; --danger-lip:  #EA2B2B; --danger-text:  #C0261B; --danger-bg:  #FDECEA; --danger-btn-lip:  #8F1C14;
  --warning: #FFB020; --warning-lip: #E89900; --warning-text: #8A5300; --warning-bg: #FFF3D6;
  --info:    #1CB0F6; --info-lip:    #1899D6; --info-text:    #0A6AA1; --info-bg:    #E3F3FC;
  --xp:      #A560F0; --xp-lip:      #8B45D6; --xp-text:      #6D28D9; --xp-bg:      #F3EAFE;
  --on-status-soft: var(--text-1);
  --on-status:     #FFFFFF;  /* text on a solid --success-text / --danger-text fill */
  --danger-btn-hover:  #A82017;
  --success-btn-hover: #276B00;

  /* Inverse surface: toasts, tips, snackbars. Stays dark in both themes. */
  --inverse:    #3D3229;
  --on-inverse: #FFFFFF;
  --inverse-accent: #FF9F5C;  /* links/actions on --inverse: 5.9:1 */
  --inverse-hover: rgba(255, 255, 255, .1);
  --code-bg: #2A211A;  /* code blocks are dark in both themes */
  --code-fg: #F7EFE8;

  /* Rank medals: fill with --on-medal on top (same in both themes) */
  --gold: #FFC83D; --silver: #D5D9E0; --bronze: #E3A06B; --on-medal: #3D3229;

  --overlay: rgba(40, 28, 18, .48);

  /* ── Typography (§3.2) ───────────────────────────── */
  --font-display: 'Baloo 2', 'Outfit', system-ui, sans-serif;
  --font-body:    'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-code:    'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --fs-display: 2rem;      --lh-display: 1.2;     /* 32/38 */
  --fs-h1:      1.625rem;  --lh-h1:      1.23;    /* 26/32 */
  --fs-h2:      1.25rem;   --lh-h2:      1.3;     /* 20/26 */
  --fs-h3:      1.0625rem; --lh-h3:      1.41;    /* 17/24 */
  --fs-body-lg: 1.0625rem; --lh-body-lg: 1.53;    /* 17/26 */
  --fs-body:    .9375rem;  --lh-body:    1.47;    /* 15/22 */
  --fs-label:   .875rem;   --lh-label:   1.43;    /* 14/20 */
  --fs-small:   .8125rem;  --lh-small:   1.38;    /* 13/18 */
  --fs-caption: .75rem;    --lh-caption: 1.33;    /* 12/16: the floor */
  --fs-num-kpi: 1.75rem;   --lh-num-kpi: 1.14;    /* 28/32 */

  /* ── Spacing (4-pt, §3.3) ────────────────────────── */
  --sp-0: 0; --sp-0h: 2px; --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;
  --gutter: 16px;
  --card-pad: 16px;
  --stack-gap: 12px;
  --nav-h: 64px;
  --nav-float: 12px;   /* gap between the floating phone tab bar and the screen edges */
  --topbar-h: 56px;
  --sidebar-w-ds: 248px;
  --tap-min: 44px;
  --content-max: 1120px;

  /* ── Radii (§3.4) ────────────────────────────────── */
  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px; --r-full: 999px;

  /* ── Motion (§3.6) ───────────────────────────────── */
  --dur-instant: 80ms;
  --dur-fast: 150ms;
  --dur-base: 220ms;
  --dur-slow: 320ms;
  --dur-celebrate: 700ms;
  --ease-standard: cubic-bezier(.2, 0, 0, 1);
  --ease-exit: cubic-bezier(.3, 0, 1, 1);
  --ease-press: cubic-bezier(.2, 0, .4, 1);
  --ease-celebrate: cubic-bezier(.34, 1.56, .64, 1);

  /* ── Elevation + z-index (§3.7.12) ───────────────── */
  --lip-sm: 0 2px 0;
  --lip: 0 4px 0;
  --float-1: 0 1px 2px rgba(61,50,41,.06), 0 1px 1px rgba(61,50,41,.04);
  --float-2: 0 6px 16px rgba(61,50,41,.10), 0 2px 4px rgba(61,50,41,.06);
  --float-3: 0 16px 40px rgba(61,50,41,.16), 0 4px 8px rgba(61,50,41,.06);
  --z-base: 0; --z-sticky: 100; --z-nav: 300; --z-drawer: 400; --z-overlay: 500; --z-modal: 510;
  --z-toast: 600; --z-tour: 700; --z-loader: 1000;
}

@media (min-width: 600px) {
  :root { --gutter: 20px; --card-pad: 20px; }
}
@media (min-width: 900px) {
  :root { --gutter: 32px; --stack-gap: 16px; --fs-h1: 2rem; --lh-h1: 1.19; --fs-h2: 1.375rem; --lh-h2: 1.27; }
}

/* Reduced motion at the token level: every consumer inherits 0ms (§3.6). */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-instant: 0ms; --dur-fast: 0ms; --dur-base: 0ms; --dur-slow: 0ms; --dur-celebrate: 0ms; }
}

/* ── Dark theme (§3.1) ───────────────────────────────────────────────
   <html data-theme="dark"> is set before first paint by the inline head
   script (localStorage ef_theme; light by default, "system" follows the OS) and kept in
   sync by ui.js (ef.setTheme). Me › Profile › Appearance is the setting.
   In dark, --primary is a light fill, so text on it is --on-primary (dark). */
[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #16110D;
  --surface:       #201913;
  --sunken:        #2A211A;
  --hover:         #33291F;
  --border:        #3A2F26;
  --border-2:      #4A3D32;
  --border-strong: #7A6958;
  --text-1:        #F7EFE8;
  --text-2:        #CDBCAC;
  --text-3:        #A8978A;
  --text-disabled: #6F6154;
  --brand:         #FF8A3D;
  --brand-soft:    #3A2414;
  --primary:       #FF8A3D;
  --primary-lip:   #C2410C;
  --primary-hover: #FF9F5C;
  --on-primary:    #1A0F06;
  --primary-text:  #FF9F5C;
  --focus:         #FF9F5C;
  --grad-primary:  linear-gradient(135deg, #FF9F5C 0%, #FF8A3D 100%);
  --success-text: #7DDC3A; --success-bg: #1E2A12;
  --danger-text:  #FF7A70; --danger-bg:  #3A1A16;
  --warning-text: #FFC24D; --warning-bg: #33270F;
  --info-text:    #5CC4FF; --info-bg:    #0F2633;
  --xp-text:      #B794FF; --xp-bg:      #2A1D3F;
  --success: #6FCF2A; --danger: #FF6B61; --warning: #FFBF40; --info: #3DBDF7; --xp: #B794FF;
  --on-status: #16110D;
  --success-btn-lip: #3F7F12; --danger-btn-lip: #B23A31;
  --danger-btn-hover: #FF968E; --success-btn-hover: #97E65E;
  --inverse: #3A2F26;
  --on-inverse: #F7EFE8;
  --inverse-hover: rgba(255, 255, 255, .08);
  --code-bg: #0F0B08;
  --overlay: rgba(0, 0, 0, .6);
  --float-1: 0 1px 2px rgba(0,0,0,.4);
  --float-2: 0 6px 16px rgba(0,0,0,.5);
  --float-3: 0 16px 40px rgba(0,0,0,.6);
}
