/* ==========================================================================
   CSS Variables & Theme System
   ========================================================================== */

:root {
  /* Dark theme (default) */
  --bg-primary: #0d0d0f;
  --bg-secondary: #161619;
  --bg-tertiary: #1e1e22;
  --bg-elevated: #26262b;
  
  --text-primary: #e8e6e3;
  --text-secondary: #a8a5a0;
  --text-muted: #6b6965;
  
  --accent-primary: #d4a574;
  --accent-secondary: #e8c9a0;
  --accent-glow: rgba(212, 165, 116, 0.15);
  
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  
  --code-bg: #1a1a1e;
  --code-text: #c9d1d9;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  
  /* Typography scale */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1.05rem;
  --text-lg: 1.175rem;
  --text-xl: 1.35rem;
  --text-2xl: 1.65rem;
  --text-3xl: 2.1rem;
  --text-4xl: 2.75rem;
  --text-5xl: 3.5rem;
  
  --leading-tight: 1.25;
  --leading-normal: 1.7;
  --leading-relaxed: 1.85;
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-24: 6rem;
  
  /* Layout */
  --content-width: 680px;
  --content-wide: 900px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #faf9f7;
  --bg-secondary: #f2f0ec;
  --bg-tertiary: #e8e6e1;
  --bg-elevated: #ffffff;
  
  --text-primary: #1a1918;
  --text-secondary: #4a4845;
  --text-muted: #7a7875;
  
  --accent-primary: #8b5a2b;
  --accent-secondary: #a67c52;
  --accent-glow: rgba(139, 90, 43, 0.1);
  
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-medium: rgba(0, 0, 0, 0.1);
  
  --code-bg: #f5f4f2;
  --code-text: #1a1918;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */

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

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color var(--transition-base), color var(--transition-base);
  min-height: 100vh;
}

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

/* ==========================================================================
   Navigation & Header
   ========================================================================== */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: var(--space-4) var(--space-6);
  background: linear-gradient(to bottom, var(--bg-primary) 0%, var(--bg-primary) 70%, transparent 100%);
  pointer-events: none;
}

.site-header > * {
  pointer-events: auto;
}

.nav-container {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-logo {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: color var(--transition-fast);
}

.site-logo:hover {
  color: var(--accent-primary);
}

.nav-links {
  display: flex;
  gap: var(--space-6);
  align-items: center;
  list-style: none;
}

.nav-link {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  transition: color var(--transition-fast);
}

.nav-link:hover {
  color: var(--accent-primary);
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-elevated);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

/* ==========================================================================
   Homepage Styles
   ========================================================================== */

.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-24) var(--space-6);
  max-width: var(--content-width);
  margin: 0 auto;
}

.hero-intro {
  font-size: var(--text-sm);
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: var(--space-4);
  font-weight: 500;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, var(--text-5xl));
  font-weight: 700;
  line-height: var(--leading-tight);
  margin-bottom: var(--space-6);
  letter-spacing: -0.03em;
}

.hero-title .accent {
  color: var(--accent-primary);
  font-style: italic;
}

.hero-description {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  max-width: 540px;
  margin-bottom: var(--space-8);
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 500;
  transition: gap var(--transition-fast);
}

.hero-cta:hover {
  gap: var(--space-3);
}

.hero-cta svg {
  width: 20px;
  height: 20px;
}

/* Recent Posts Section */
.section {
  padding: var(--space-16) var(--space-6);
  max-width: var(--content-width);
  margin: 0 auto;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.section-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-link {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.section-link:hover {
  color: var(--accent-primary);
}

/* Post Cards */
.post-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.post-card {
  display: block;
  padding: var(--space-6);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  text-decoration: none;
  transition: all var(--transition-base);
}

.post-card:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-medium);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.post-meta {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.post-tag {
  color: var(--accent-primary);
  font-weight: 500;
}

.post-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  letter-spacing: -0.01em;
  transition: color var(--transition-fast);
}

.post-card:hover .post-title {
  color: var(--accent-primary);
}

.post-excerpt {
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

/* ==========================================================================
   Article Styles
   ========================================================================== */

.article-header {
  padding: calc(var(--space-24) + 60px) var(--space-6) var(--space-12);
  max-width: var(--content-width);
  margin: 0 auto;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.article-tag {
  background: var(--accent-glow);
  color: var(--accent-primary);
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
  font-weight: 500;
}

.article-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, var(--text-4xl));
  font-weight: 700;
  line-height: var(--leading-tight);
  margin-bottom: var(--space-6);
  letter-spacing: -0.03em;
}

.article-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  font-style: italic;
}

/* Article Content */
.article-content {
  padding: 0 var(--space-6) var(--space-16);
  max-width: var(--content-width);
  margin: 0 auto;
}

.article-content > * + * {
  margin-top: var(--space-6);
}

.article-content p {
  line-height: var(--leading-relaxed);
}

.article-content h2 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.article-content h3 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  margin-top: var(--space-8);
  margin-bottom: var(--space-3);
  letter-spacing: -0.01em;
}

.article-content h4 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
  color: var(--accent-primary);
}

/* Horizontal rule / section break */
.article-content hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-medium), transparent);
  margin: var(--space-12) 0;
}

/* Lists */
.article-content ul,
.article-content ol {
  padding-left: var(--space-6);
}

.article-content li {
  margin-bottom: var(--space-2);
}

.article-content li::marker {
  color: var(--accent-primary);
}

/* Strong and emphasis */
.article-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.article-content em {
  font-style: italic;
  color: var(--text-primary);
}

/* Links */
.article-content a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-decoration-color: var(--accent-glow);
  text-underline-offset: 3px;
  transition: all var(--transition-fast);
}

.article-content a:hover {
  text-decoration-color: var(--accent-primary);
}

/* Blockquotes */
.article-content blockquote {
  border-left: 3px solid var(--accent-primary);
  padding-left: var(--space-6);
  margin-left: 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Code */
.article-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.article-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: var(--space-4);
  overflow-x: auto;
}

.article-content pre code {
  background: none;
  padding: 0;
}

/* Tables */
.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-6) 0;
  font-size: var(--text-sm);
}

.article-content th,
.article-content td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.article-content th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-primary);
}

.article-content tr:hover td {
  background: var(--bg-secondary);
}

/* Images and Figures */
.article-content figure {
  margin: var(--space-8) 0;
}

.article-content img,
.article-content svg {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.article-content figcaption {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

/* SVG diagrams specific styling */
.diagram-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: var(--space-6);
  margin: var(--space-8) 0;
  overflow-x: auto;
}

.diagram-container svg {
  display: block;
  margin: 0 auto;
}

/* Lead paragraph */
.lead {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

/* Numbered list for outline */
.outline-list {
  counter-reset: outline;
  list-style: none;
  padding-left: 0;
}

.outline-list li {
  counter-increment: outline;
  padding-left: var(--space-8);
  position: relative;
}

.outline-list li::before {
  content: counter(outline) ".";
  position: absolute;
  left: 0;
  color: var(--accent-primary);
  font-weight: 600;
  font-family: var(--font-display);
}

/* Callout boxes */
.callout {
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent-primary);
  padding: var(--space-4) var(--space-6);
  border-radius: 0 8px 8px 0;
  margin: var(--space-6) 0;
}

.callout-title {
  font-weight: 600;
  color: var(--accent-primary);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  padding: var(--space-12) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-16);
}

.footer-content {
  max-width: var(--content-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.footer-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: var(--space-6);
  list-style: none;
}

.footer-link {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-link:hover {
  color: var(--accent-primary);
}

/* ==========================================================================
   Utilities & Responsive
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 640px) {
  html {
    font-size: 16px;
  }
  
  .nav-links {
    gap: var(--space-4);
  }
  
  .hero {
    padding-top: var(--space-16);
  }
  
  .article-header {
    padding-top: calc(var(--space-16) + 60px);
  }
  
  .post-card {
    padding: var(--space-4);
  }
  
  .article-content table {
    font-size: var(--text-xs);
  }
  
  .article-content th,
  .article-content td {
    padding: var(--space-2);
  }
}

/* Animation keyframes */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-up {
  animation: fadeInUp 0.6s ease forwards;
}

.delay-1 { animation-delay: 0.1s; opacity: 0; }
.delay-2 { animation-delay: 0.2s; opacity: 0; }
.delay-3 { animation-delay: 0.3s; opacity: 0; }
.delay-4 { animation-delay: 0.4s; opacity: 0; }
