/**
 * Design Tokens & Core Variables
 * Built with strict 4px/8px modular rhythm, fluid typography clamps,
 * WCAG 2.1 AA accessible contrast ratios, and hardware safe-area support.
 */

:root {
  /* Color Palette - Light Mode (Default) */
  --bg-app: #f4f8f7;
  --bg-gradient-start: #eef6f5;
  --bg-gradient-mid: #f9faf8;
  --bg-gradient-end: #edf4f2;
  
  --surface-canvas: #ffffff;
  --surface-panel: rgba(255, 255, 255, 0.92);
  --surface-panel-solid: #ffffff;
  --surface-card: rgba(255, 255, 255, 0.85);
  --surface-subtle: #edf3f2;
  --surface-overlay: rgba(15, 23, 42, 0.6);
  --surface-drawer: rgba(255, 255, 255, 0.98);

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  --border-subtle: #e5e7eb;
  --border-line: #d1d5db;
  --border-strong: #9ca3af;
  --border-focus: #0f766e;

  /* Brand Accents */
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-active: #134e4a;
  --primary-subtle: rgba(15, 118, 110, 0.1);
  --primary-text: #0f766e;

  --accent-gold: #b45309;
  --accent-gold-subtle: rgba(180, 83, 9, 0.12);
  --accent-sky: #0369a1;
  --accent-sky-subtle: rgba(3, 105, 161, 0.12);

  /* Status Colors */
  --color-success-bg: #ecfdf5;
  --color-success-text: #065f46;
  --color-success-border: #a7f3d0;

  --color-danger-bg: #fef2f2;
  --color-danger-text: #991b1b;
  --color-danger-border: #fecaca;

  --color-warning-bg: #fffbeb;
  --color-warning-text: #92400e;
  --color-warning-border: #fde68a;

  --color-info-bg: #eff6ff;
  --color-info-text: #1e40af;
  --color-info-border: #bfdbfe;

  /* Accessibility & Focus */
  --ring-focus: #0284c7;
  --ring-focus-shadow: 0 0 0 3px rgba(2, 132, 199, 0.45);
  --ring-offset: 2px;

  /* Spacing Scale (4px/8px rhythm) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* Border Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --shadow-panel: 0 24px 70px rgba(15, 23, 42, 0.09), inset 0 1px 0 rgba(255, 255, 255, 0.8);

  /* Typography Scale */
  --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-family-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  
  --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);      /* 12px - 13px */
  --font-size-sm: clamp(0.84375rem, 0.8rem + 0.22vw, 0.875rem);    /* 13.5px - 14px */
  --font-size-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);        /* 15px - 16px */
  --font-size-lg: clamp(1.0625rem, 1rem + 0.3vw, 1.125rem);        /* 17px - 18px */
  --font-size-xl: clamp(1.25rem, 1.15rem + 0.5vw, 1.375rem);       /* 20px - 22px */
  --font-size-2xl: clamp(1.5rem, 1.35rem + 0.75vw, 1.75rem);       /* 24px - 28px */
  --font-size-3xl: clamp(1.875rem, 1.6rem + 1.25vw, 2.25rem);      /* 30px - 36px */
  --font-size-4xl: clamp(2.25rem, 1.9rem + 1.75vw, 3.25rem);       /* 36px - 52px */

  /* Safe Area Insets (Device Notches & Home Bars) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Layout Containers */
  --container-max-w-prose: 68ch;
  --container-max-w-form: 860px;
  --container-max-w-laptop: 1280px;
  --container-max-w-desktop: 1536px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-Index Hierarchy */
  --z-canvas: -1;
  --z-base: 1;
  --z-sticky: 100;
  --z-drawer: 200;
  --z-modal: 300;
  --z-command-palette: 400;
  --z-toast: 500;
}

/* Dark Mode Tokens */
[data-theme="dark"] {
  --bg-app: #090d12;
  --bg-gradient-start: #0b1319;
  --bg-gradient-mid: #0d1720;
  --bg-gradient-end: #090f14;

  --surface-canvas: #0b1319;
  --surface-panel: rgba(15, 23, 33, 0.88);
  --surface-panel-solid: #0f1721;
  --surface-card: rgba(22, 33, 46, 0.75);
  --surface-subtle: #16222f;
  --surface-overlay: rgba(0, 0, 0, 0.75);
  --surface-drawer: rgba(13, 21, 30, 0.98);

  --text-primary: #f3f4f6;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --text-inverse: #111827;

  --border-subtle: #1f2937;
  --border-line: #374151;
  --border-strong: #4b5563;
  --border-focus: #14b8a6;

  /* Brand Accents */
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-active: #0d9488;
  --primary-subtle: rgba(20, 184, 166, 0.16);
  --primary-text: #2dd4bf;

  --accent-gold: #f59e0b;
  --accent-gold-subtle: rgba(245, 158, 11, 0.18);
  --accent-sky: #38bdf8;
  --accent-sky-subtle: rgba(56, 189, 248, 0.18);

  /* Status Colors (Dark Mode) */
  --color-success-bg: rgba(6, 78, 59, 0.35);
  --color-success-text: #6ee7b7;
  --color-success-border: #065f46;

  --color-danger-bg: rgba(127, 29, 29, 0.35);
  --color-danger-text: #fca5a5;
  --color-danger-border: #991b1b;

  --color-warning-bg: rgba(120, 53, 15, 0.35);
  --color-warning-text: #fcd34d;
  --color-warning-border: #92400e;

  --color-info-bg: rgba(30, 58, 138, 0.35);
  --color-info-text: #93c5fd;
  --color-info-border: #1e40af;

  /* Accessibility Focus in Dark Mode */
  --ring-focus: #38bdf8;
  --ring-focus-shadow: 0 0 0 3px rgba(56, 189, 248, 0.55);

  --shadow-panel: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
