/**
 * Base Styles
 * CSS custom properties (variables) and reset
 */

:root {
  /* Colors - Light Mode */
  --color-background: #FFFFFF;
  --color-surface: #F8F9FA;
  --color-surface-hover: #F1F3F5;
  --color-border: #E1E4E8;
  --color-text: #24292F;
  --color-text-secondary: #57606A;
  --color-text-tertiary: #8B949E;
  
  /* Brand Colors */
  --color-primary: #007AFF;
  --color-primary-hover: #0051D5;
  --color-primary-light: rgba(0, 122, 255, 0.1);
  
  /* Feedback Colors */
  --color-success: #34C759;
  --color-warning: #FF9F0A;
  --color-error: #FF3B30;
  --color-info: #5AC8FA;
  
  /* Glass Morphism */
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: rgba(0, 0, 0, 0.04);
  
  /* Typography */
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  
  /* Font Sizes (Modular Scale 1.125) */
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-md: 1rem;        /* 16px */
  --font-size-lg: 1.125rem;    /* 18px */
  --font-size-xl: 1.25rem;     /* 20px */
  --font-size-2xl: 1.5rem;     /* 24px */
  --font-size-3xl: 1.875rem;   /* 30px */
  --font-size-4xl: 2.25rem;    /* 36px */
  --font-size-5xl: 3rem;       /* 48px */
  
  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.7;
  
  /* Spacing (8px Grid System) */
  --space-2xs: 0.25rem;  /* 4px */
  --space-xs: 0.5rem;    /* 8px */
  --space-sm: 0.75rem;   /* 12px */
  --space-md: 1rem;      /* 16px */
  --space-lg: 1.5rem;    /* 24px */
  --space-xl: 2rem;      /* 32px */
  --space-2xl: 3rem;     /* 48px */
  --space-3xl: 4rem;     /* 64px */
  --space-4xl: 6rem;     /* 96px */
  
  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --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);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  /* Transitions (Material Design easing) */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Z-Index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-modal: 1040;
  --z-tooltip: 1050;
  
  /* Layout */
  --container-width: 1200px;
  --reading-width: 65ch;
  --nav-height: 60px;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-background: #0D1117;
    --color-surface: #161B22;
    --color-surface-hover: #1C2128;
    --color-border: #30363D;
    --color-text: #C9D1D9;
    --color-text-secondary: #8B949E;
    --color-text-tertiary: #6E7681;
    
    --color-primary: #58A6FF;
    --color-primary-hover: #79B8FF;
    --color-primary-light: rgba(88, 166, 255, 0.15);
    
    --glass-bg: rgba(13, 17, 23, 0.8);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  }
}

/**
 * Base Reset
 * Modern CSS reset following best practices
 */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

/* Respect user motion preferences (WCAG 2.2) */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  line-height: var(--line-height-relaxed);
  color: var(--color-text);
  background: var(--color-background);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sticky Footer System */
body > main {
  flex: 1 0 auto;
}

body > footer,
body > .footer {
  flex-shrink: 0;
}

/* Skip to Main Content Link (Accessibility) */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: var(--space-md) var(--space-lg);
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) 0);
  z-index: var(--z-tooltip);
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-primary-hover);
  outline-offset: 2px;
}

/* Reading Progress Bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-info));
  z-index: calc(var(--z-modal) + 1);
  transition: width 0.1s ease-out;
}

/* Selection Color */
::selection {
  background: var(--color-primary-light);
  color: var(--color-text);
}

::-moz-selection {
  background: var(--color-primary-light);
  color: var(--color-text);
}

/* ========================================
   ACCESSIBILITY - WCAG 2.2 AA
======================================== */

/* Focus indicators for keyboard navigation (WCAG 2.4.7) */
*:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Better focus for interactive elements */
button:focus,
a:focus,
input:focus,
textarea:focus,
select:focus {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

/* Modern focus-visible (only keyboard, not mouse clicks) */
*:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  *:focus-visible {
    outline: 3px solid var(--color-text);
    outline-offset: 4px;
  }
}

/* Hyphenation support for long words (better text flow) */
h1, h2, h3, h4, h5, h6,
.post-card-title,
.article-title,
.listing-title {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  max-width: 100%;
  box-sizing: border-box;
}

/* Very long URLs and code in headings */
h1 code, h2 code, h3 code,
.post-card-title code {
  word-break: break-all;
  overflow-wrap: break-word;
}
