/* ==========================================================================
   Global CSS — Reset, Custom Properties, Typography, Layout System
   ========================================================================== */

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
}

body {
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* --- Custom Properties (Design Tokens) --- */
:root {
  /* Era Colors */
  --era-0: #00cc66;
  --era-0-bg: #0a1f0a;
  --era-0-light: #00ff88;
  --era-1: #ff1493;
  --era-1-bg: #1a0a14;
  --era-1-light: #ff69b4;
  --era-2: #cc0000;
  --era-2-bg: #1a0a0a;
  --era-2-light: #ff4444;
  --era-3: #ff6600;
  --era-3-bg: #1a100a;
  --era-3-light: #ff8833;
  --era-4: #6644cc;
  --era-4-bg: #0f0a1a;
  --era-4-light: #9977ff;
  --era-5: #1da1f2;
  --era-5-bg: #0a141a;
  --era-5-light: #4db8ff;
  --era-6: #ff0050;
  --era-6-bg: #1a0a10;
  --era-6-light: #ff3377;
  --era-7: #8ace00;
  --era-7-bg: #141a0a;
  --era-7-light: #aaee33;

  /* Status Colors */
  --status-active: #22c55e;
  --status-dead: #6b7280;
  --status-classic: #f59e0b;
  --status-cyclical: #8b5cf6;
  --status-ascendant: #ef4444;
  --status-declining: #f97316;
  --status-controversial: #dc2626;

  /* Impact Stars */
  --star-filled: #f59e0b;
  --star-empty: #374151;

  /* Spacing (8px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;
  --space-10: 128px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.15), 0 8px 10px rgba(0,0,0,0.04);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", "Liberation Mono", monospace;
  --font-impact: Impact, "Arial Black", sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-6xl: 3.75rem;

  /* Layout */
  --max-width: 1200px;
  --max-reading: 700px;
  --nav-height: 64px;
  --sidebar-width: 280px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;

  /* Z-index layers */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;
  --z-tooltip: 600;
}

/* --- Light Mode (default) --- */
:root, [data-theme="light"] {
  --bg-primary: #fafaf9;
  --bg-secondary: #f5f5f4;
  --bg-tertiary: #e7e5e4;
  --bg-card: #ffffff;
  --bg-card-hover: #fafaf9;
  --bg-overlay: rgba(0,0,0,0.5);
  --bg-code: #f1f5f9;

  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #a8a29e;
  --text-inverse: #fafaf9;
  --text-link: #2563eb;
  --text-link-hover: #1d4ed8;

  --border-primary: #d6d3d1;
  --border-secondary: #e7e5e4;
  --border-focus: #2563eb;

  --accent-primary: #2563eb;
  --accent-secondary: #7c3aed;
  --accent-success: #16a34a;
  --accent-warning: #d97706;
  --accent-error: #dc2626;
  --text-accent: #2563eb;

  --shadow-color: rgba(0,0,0,0.1);
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --card-shadow-hover: 0 10px 20px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg-primary: #0c0a09;
  --bg-secondary: #1c1917;
  --bg-tertiary: #292524;
  --bg-card: #1c1917;
  --bg-card-hover: #292524;
  --bg-overlay: rgba(0,0,0,0.7);
  --bg-code: #1e293b;

  --text-primary: #fafaf9;
  --text-secondary: #a8a29e;
  --text-tertiary: #78716c;
  --text-inverse: #1c1917;
  --text-link: #60a5fa;
  --text-link-hover: #93bbfd;

  --border-primary: #44403c;
  --border-secondary: #292524;
  --border-focus: #60a5fa;

  --accent-primary: #60a5fa;
  --accent-secondary: #a78bfa;
  --accent-success: #4ade80;
  --accent-warning: #fbbf24;
  --accent-error: #f87171;
  --text-accent: #60a5fa;

  --shadow-color: rgba(0,0,0,0.3);
  --card-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.15);
  --card-shadow-hover: 0 10px 20px rgba(0,0,0,0.3), 0 4px 8px rgba(0,0,0,0.15);
}

/* --- Base Styles --- */
body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color var(--transition-base), color var(--transition-base);
}

/* Skip to content */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--accent-primary);
  color: white;
  border-radius: var(--radius-md);
  z-index: var(--z-tooltip);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-4);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

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

p {
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
  line-height: 1.7;
}

.reading-width p,
.reading-width li {
  font-size: var(--text-lg);
  line-height: 1.8;
}

strong, b { font-weight: 700; }
em, i { font-style: italic; }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--bg-code);
  border-radius: var(--radius-sm);
}

blockquote {
  border-left: 4px solid var(--accent-primary);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-5) 0;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--text-secondary);
}

a:not(.btn):not(.card):not(.nav-link) {
  color: var(--text-link);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: text-decoration-color var(--transition-fast), color var(--transition-fast);
}

a:not(.btn):not(.card):not(.nav-link):hover {
  text-decoration-color: currentColor;
  color: var(--text-link-hover);
}

/* --- Layout System --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.container-narrow {
  max-width: var(--max-reading);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.page-content {
  padding-top: calc(var(--nav-height) + var(--space-6));
  padding-bottom: var(--space-9);
  min-height: 100vh;
}

/* Flexbox utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
.gap-7 { gap: var(--space-7); }

/* Grid utilities */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto-fill { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-auto-fit { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* Section spacing */
.section {
  padding: var(--space-8) 0;
}

.section + .section {
  border-top: 1px solid var(--border-secondary);
}

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-muted { color: var(--text-tertiary); }
.text-secondary { color: var(--text-secondary); }
.text-mono { font-family: var(--font-mono); }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.overflow-hidden { overflow: hidden; }
.relative { position: relative; }

/* --- Emoji Display --- */
.emoji-display {
  font-size: var(--text-6xl);
  line-height: 1;
  display: inline-block;
}

.emoji-display-sm {
  font-size: var(--text-3xl);
  line-height: 1;
}

.emoji-display-lg {
  font-size: 6rem;
  line-height: 1;
}

/* --- Impact Stars --- */
.impact-stars {
  display: inline-flex;
  gap: 2px;
  font-size: var(--text-sm);
  color: var(--star-filled);
}

.impact-stars .empty {
  color: var(--star-empty);
}

/* --- Dividers --- */
.divider {
  height: 1px;
  background: var(--border-secondary);
  margin: var(--space-6) 0;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* --- Selection --- */
::selection {
  background: var(--accent-primary);
  color: white;
}

/* --- Focus Visible --- */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: var(--text-4xl); }
  h2 { font-size: var(--text-3xl); }
}

@media (max-width: 768px) {
  html { font-size: 15px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .grid-auto-fill { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  .container { padding: 0 var(--space-4); }
  .section { padding: var(--space-6) 0; }
  .page-content { padding-top: calc(var(--nav-height) + var(--space-4)); }
  .hide-mobile { display: none !important; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .grid-auto-fill { grid-template-columns: 1fr; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}

/* --- Print --- */
@media print {
  nav, footer, .no-print { display: none !important; }
  body { background: white; color: black; }
  .page-content { padding-top: 0; }
}
