/* ==========================================================================
   Design Tokens — Semantic Palette, Typography, Spacing & Elevation
   WCAG 2.2 AA Compliant (min 4.5:1 text contrast, 3:1 UI/non-text contrast)
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Typography Families */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Type Scale */
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 0.96875rem; /* 15.5px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.375rem;     /* 22px */
  --text-2xl: clamp(1.85rem, 3.2vw, 2.5rem);
  --text-3xl: clamp(2.1rem, 3.8vw, 2.85rem);

  /* Layout & Spacing */
  --container-max: 1160px;
  --container-gutter: clamp(1.25rem, 4vw, 2.5rem);
  --header-height: 64px;
  --section-py: clamp(4.5rem, 9vh, 7.5rem);

  /* Radii */
  --radius-xs: 5px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 160ms;
  --duration-base: 260ms;
  --duration-slow: 360ms;

  /* Default fallback tokens (Dark Mode) */
  --bg-page: #0B0D10;
  --bg-surface: #12151B;
  --bg-surface-elevated: #171B22;
  --bg-header: rgba(11, 13, 16, 0.86);

  --border-subtle: #242933;
  --border-strong: #323946;
  --card-inner-border: rgba(244, 245, 247, 0.08);

  --text-primary: #F4F5F7;
  --text-secondary: #A1A8B3;
  --text-muted: #707885;
  --text-tertiary: #848E9E; /* >= 5.2:1 on #0B0D10 & #12151B */

  --accent-status: #4D9CFF;
  --accent-topo: rgba(77, 156, 255, 0.32);
  --accent-topo-secondary: rgba(161, 168, 179, 0.14);

  --tag-bg: #171B22;
  --tag-border: #242933;
  --tag-text: #D1D6DF;

  --card-shadow: 0 24px 64px -18px rgba(0, 0, 0, 0.72), 0 2px 8px rgba(0, 0, 0, 0.36);
  --card-shadow-sm: 0 10px 28px -12px rgba(0, 0, 0, 0.45);
  --node-halo: rgba(244, 245, 247, 0.18);
  --hover-surface: rgba(244, 245, 247, 0.035);

  --scrollbar-track: #171B22;
  --scrollbar-thumb: #596272; /* >= 3.2:1 against track & page bg */

  --qr-bg: #171B22;
  --qr-fg: #D5DAE3;
}

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

  --bg-page: #0B0D10;
  --bg-surface: #12151B;
  --bg-surface-elevated: #171B22;
  --bg-header: rgba(11, 13, 16, 0.86);

  --border-subtle: #242933;
  --border-strong: #323946;
  --card-inner-border: rgba(244, 245, 247, 0.08);

  --text-primary: #F4F5F7;
  --text-secondary: #A1A8B3;
  --text-muted: #707885;
  --text-tertiary: #848E9E;

  --accent-status: #4D9CFF;
  --accent-topo: rgba(77, 156, 255, 0.34);
  --accent-topo-secondary: rgba(161, 168, 179, 0.15);

  --tag-bg: #171B22;
  --tag-border: #242933;
  --tag-text: #D1D6DF;

  --card-shadow: 0 24px 64px -18px rgba(0, 0, 0, 0.72), 0 2px 8px rgba(0, 0, 0, 0.36);
  --card-shadow-sm: 0 10px 28px -12px rgba(0, 0, 0, 0.45);
  --node-halo: rgba(244, 245, 247, 0.18);
  --hover-surface: rgba(244, 245, 247, 0.035);

  --scrollbar-track: #171B22;
  --scrollbar-thumb: #596272;

  --qr-bg: #171B22;
  --qr-fg: #D5DAE3;
}

[data-theme="light"] {
  color-scheme: light;

  --bg-page: #F4F4F5;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #FAFAFA;
  --bg-header: rgba(244, 244, 245, 0.88);

  --border-subtle: #E4E4E7;
  --border-strong: #D4D4D8;
  --card-inner-border: rgba(17, 19, 24, 0.08);

  --text-primary: #111318;
  --text-secondary: #4B5260;
  --text-muted: #6B7280;
  --text-tertiary: #5B6270; /* >= 5.5:1 on #F4F4F5 & #FFFFFF */

  --accent-status: #2563EB;
  --accent-topo: rgba(17, 19, 24, 0.16);
  --accent-topo-secondary: rgba(17, 19, 24, 0.11);

  --tag-bg: #FFFFFF;
  --tag-border: #E4E4E7;
  --tag-text: #272B35;

  --card-shadow: 0 24px 56px -18px rgba(17, 19, 24, 0.12), 0 4px 12px rgba(17, 19, 24, 0.04);
  --card-shadow-sm: 0 8px 24px -10px rgba(17, 19, 24, 0.08);
  --node-halo: rgba(17, 19, 24, 0.14);
  --hover-surface: rgba(17, 19, 24, 0.03);

  --scrollbar-track: #E4E4E7;
  --scrollbar-thumb: #7B8290; /* >= 3.4:1 against track & page bg */

  --qr-bg: #FAFAFA;
  --qr-fg: #1F2430;
}

/* No-JS system preference fallback */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg-page: #F4F4F5;
    --bg-surface: #FFFFFF;
    --bg-surface-elevated: #FAFAFA;
    --bg-header: rgba(244, 244, 245, 0.88);
    --border-subtle: #E4E4E7;
    --border-strong: #D4D4D8;
    --text-primary: #111318;
    --text-secondary: #4B5260;
    --text-muted: #6B7280;
    --text-tertiary: #5B6270;
    --accent-status: #2563EB;
  }
}
