/* ========================================
   DESIGN SYSTEM - THEME FOUNDATION
   ======================================== */

/* CSS Custom Properties - Theme Tokens */
:root {
  /* ===== DARK MODE (DEFAULT) ===== */
  --theme-bg-primary: #070707;
  --theme-bg-secondary: rgba(21, 21, 21, 0.4);
  --theme-bg-tertiary: #2a2a2a;
  --theme-text-primary: #ffffff;
  --theme-text-secondary: #b3b3b3;
  --theme-text-muted: #666666;
  --theme-text-inverse: #ffffff; /* Lightest in dark mode */
  --theme-text-hover: rgba(255, 255, 255, 0.7); /* Nav hover text in dark mode */
  --theme-accent-primary: #667eea;
  --theme-accent-secondary: #764ba2;
  --theme-border-primary: #333333;
  --theme-border-secondary: #444444;
  --theme-shadow: rgba(0, 0, 0, 0.3);
  --theme-shadow-hover: rgba(0, 0, 0, 0.5);
  
  /* ===== LIGHT MODE ===== */
  --theme-light-bg-primary: #ffffff;
  --theme-light-bg-secondary: #f8f9fa;
  --theme-light-bg-tertiary: #e9ecef;
  --theme-light-text-primary: #212529;
  --theme-light-text-secondary: #6c757d;
  --theme-light-text-muted: #adb5bd;
  --theme-light-text-inverse: #070707; /* Darkest in light mode */
  --theme-light-text-hover: rgba(33, 37, 41, 0.7); /* Nav hover text in light mode */
  --theme-light-accent-primary: #667eea;
  --theme-light-accent-secondary: #764ba2;
  --theme-light-border-primary: #dee2e6;
  --theme-light-border-secondary: #e9ecef;
  --theme-light-shadow: rgba(0, 0, 0, 0.1);
  --theme-light-shadow-hover: rgba(0, 0, 0, 0.15);
  
  /* ===== TYPOGRAPHY SYSTEM ===== */
  --font-family-primary: 'Archivo', 'Helvetica', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-family-body: 'Archivo', 'Helvetica', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-family-display: 'Clash Display', 'Helvetica', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-family-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  
  /* Font Sizes - Responsive Scale */
  --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --font-size-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  --font-size-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
  --font-size-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --font-size-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
  --font-size-3xl: clamp(2rem, 1.7rem + 1.5vw, 2.5rem);
  --font-size-4xl: clamp(2.5rem, 2.1rem + 2vw, 3.5rem);
  --font-size-5xl: clamp(3rem, 2.5rem + 2.5vw, 4rem);
  
  /* Font Weights */
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-snug: 1.375;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
  --line-height-loose: 2;
  
  /* ===== SPACING SYSTEM ===== */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  --space-24: 6rem;     /* 96px */
  --space-32: 8rem;     /* 128px */
  
  /* ===== LAYOUT TOKENS ===== */
  --container-max-width: 1200px;
  --container-padding: 20px;
  --site-margin: 20px;
  --border-radius-sm: 0.25rem;
  --border-radius-md: 0.5rem;
  --border-radius-lg: 0.75rem;
  --border-radius-xl: 1rem;
  --border-radius-2xl: 1.5rem;
  --border-radius-full: 9999px;
  
  /* ===== SPACING TOKENS ===== */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;
  --space-4xl: 40px;
  --space-5xl: 48px;
  --space-6xl: 64px;
  --space-7xl: 80px;
  --space-8xl: 120px;
  
  /* ===== POSITIONING TOKENS ===== */
  --popup-jay-offset-left: 20px;
  --popup-jay-offset-top: 50vh;
  --popup-jay-offset-bottom: 120px;
  
  /* ===== TRANSITION TOKENS ===== */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-theme: 200ms ease;
  
  /* ===== Z-INDEX SCALE ===== */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
}

/* ===== THEME SWITCHING ===== */
[data-theme="light"] {
  --theme-bg-primary: var(--theme-light-bg-primary);
  --theme-bg-secondary: var(--theme-light-bg-secondary);
  --theme-bg-tertiary: var(--theme-light-bg-tertiary);
  --theme-text-primary: var(--theme-light-text-primary);
  --theme-text-secondary: var(--theme-light-text-secondary);
  --theme-text-muted: var(--theme-light-text-muted);
  --theme-text-inverse: var(--theme-light-text-inverse);
  --theme-text-hover: var(--theme-light-text-hover);
  --theme-accent-primary: var(--theme-light-accent-primary);
  --theme-accent-secondary: var(--theme-light-accent-secondary);
  --theme-border-primary: var(--theme-light-border-primary);
  --theme-border-secondary: var(--theme-light-border-secondary);
  --theme-shadow: var(--theme-light-shadow);
  --theme-shadow-hover: var(--theme-light-shadow-hover);
}

/* ===== BASE STYLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family-primary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--theme-text-primary);
  background-color: var(--theme-bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color var(--transition-theme), color var(--transition-theme);
}

/* ===== TYPOGRAPHY SYSTEM ===== */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--theme-text-primary);
  margin: 0;
}

h1 { font-size: var(--font-size-5xl); }
h2 { font-size: var(--font-size-4xl); }
h3 { font-size: var(--font-size-3xl); }
h4 { font-size: var(--font-size-2xl); }
h5 { font-size: var(--font-size-xl); }
h6 { font-size: var(--font-size-lg); }

p {
  margin: 0;
  color: var(--theme-text-primary);
  opacity: 0.8;
  line-height: var(--line-height-relaxed);
}

a {
  color: var(--theme-accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

/* Global link styles - remove default browser styles */
a {
  color: inherit;
  text-decoration: none;
  transition: none;
}

a:hover,
a:focus,
a:visited,
a:active {
  color: inherit;
  text-decoration: none;
  outline: none;
}

/* Override global link styles for navigation */
.nav-logo a,
.nav-link {
  color: var(--theme-text-primary);
  text-decoration: none;
}

.nav-logo a,
.nav-link {
  animation: none; /* Ensure no animation by default */
}

/* Ensure no animation in both themes */
[data-theme="light"] .nav-logo a,
[data-theme="light"] .nav-link,
[data-theme="dark"] .nav-logo a,
[data-theme="dark"] .nav-link {
  animation: none; /* Ensure no animation by default in both themes */
}

.nav-link:hover,
.nav-link:focus {
  text-decoration: none;
  animation: rainbow-cycle 1s linear infinite;
  mix-blend-mode: normal; /* Override blend mode on hover */
}

/* When blend mode is supported, use white base for proper inversion */
@supports (mix-blend-mode: exclusion) {
  .nav-logo a,
  .nav-link {
    color: #ffffff;
  }
  
  .nav-logo a:hover,
  .nav-logo a:focus,
  .nav-link:hover,
  .nav-link:focus {
    animation: rainbow-cycle 1s linear infinite;
    mix-blend-mode: normal; /* Override blend mode on hover */
  }
}

/* Ensure rainbow animation works in both light and dark modes */
[data-theme="light"] .nav-logo a:hover,
[data-theme="light"] .nav-logo a:focus,
[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link:focus,
[data-theme="dark"] .nav-logo a:hover,
[data-theme="dark"] .nav-logo a:focus,
[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-link:focus {
  animation: rainbow-cycle 1s linear infinite;
  mix-blend-mode: normal; /* Override blend mode on hover */
}

/* Ensure navigation is visible in light mode with blend mode */
[data-theme="light"] .navbar {
  mix-blend-mode: exclusion;
  -webkit-mix-blend-mode: exclusion;
}

[data-theme="light"] .nav-logo a,
[data-theme="light"] .nav-link {
  color: #ffffff;
}

/* Rainbow Animation Keyframes */
@keyframes rainbow-cycle {
  0% { color: #E40303 !important; } /* Red */
  25% { color: #FFED00 !important; } /* Yellow */
  50% { color: #004DFF !important; } /* Blue */
  75% { color: #750787 !important; } /* Purple */
  100% { color: #E40303 !important; } /* Back to red */
}

/* ===== LAYOUT SYSTEM ===== */
.container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0 var(--container-padding);
}

/* Responsive utilities */
@media (max-width: 768px) {
  .container {
    padding: 0 var(--site-margin);
  }
  
  /* Ensure proper mobile layout */
  body {
    overflow-x: hidden;
  }
  
  /* Force mobile layout snap */
  .navbar {
    transition: all 0.3s ease;
  }
}

.section {
  padding: var(--space-20) 0;
}

.section-sm {
  padding: var(--space-16) 0;
}

.section-lg {
  padding: var(--space-24) 0;
}

/* ===== UTILITY CLASSES ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.focus-visible {
  outline: 2px solid var(--theme-accent-primary);
  outline-offset: 2px;
}

/* ===== THEME TOGGLE COMPONENT ===== */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--theme-border-primary);
  border-radius: var(--border-radius-md);
  background-color: var(--theme-bg-secondary);
  color: var(--theme-text-primary);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.theme-toggle:hover {
  background-color: var(--theme-bg-tertiary);
  border-color: var(--theme-border-secondary);
}

.theme-toggle:focus {
  outline: 2px solid var(--theme-accent-primary);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform var(--transition-normal);
}

.theme-toggle[aria-pressed="true"] svg {
  transform: rotate(180deg);
}

/* ===== RESPONSIVE BREAKPOINTS ===== */
@media (max-width: 768px) {
  :root {
    --container-padding: var(--space-3);
    --space-20: var(--space-16);
    --space-24: var(--space-20);
  }
}

@media (max-width: 480px) {
  :root {
    --container-padding: var(--space-2);
    --space-16: var(--space-12);
    --space-20: var(--space-16);
  }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: high) {
  :root {
    --theme-border-primary: #666666;
    --theme-border-secondary: #888888;
  }
  
  [data-theme="light"] {
    --theme-light-border-primary: #333333;
    --theme-light-border-secondary: #666666;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .theme-toggle {
    display: none;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  a {
    color: black !important;
    text-decoration: underline;
  }
}
