/* ============================================================
   1. CSS Variables / Theme
   ============================================================ */
:root {
  --bg: #fafaf9;
  --card-bg: #fff;
  --text: #1a1a1a;
  --text-light: #6b6b6b;
  --text-muted: #999;
  --accent: #c75b39;
  --accent-hover: #b04d2e;
  --code-accent: #2563eb;
  --border: #e5e5e5;
  --tag-bg: #f0ebe3;
  --code-bg: #f5f2ed;
  --pre-bg: #2d2d2d;
  --pre-color: #f8f8f2;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
  --radius: 8px;
  --max-width: 680px;

  /* Typography scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.563rem;
  --text-2xl: 1.953rem;
  --text-3xl: 2.2rem;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-serif: "Georgia", "Noto Serif SC", "STSong", "Songti SC", serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", monospace;

  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 40px;

  --transition: 200ms ease;
}

[data-theme="dark"] {
  --bg: #171717;
  --card-bg: #262626;
  --text: #e5e5e5;
  --text-light: #a3a3a3;
  --text-muted: #737373;
  --accent: #e07b5a;
  --accent-hover: #f09070;
  --code-accent: #60a5fa;
  --border: #404040;
  --tag-bg: #333;
  --code-bg: #2a2a2a;
  --pre-bg: #0d0d0d;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 20px rgba(0,0,0,0.4);
}

/* ============================================================
   2. Reset / Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  transition: background var(--transition), color var(--transition);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

a { color: var(--code-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   3. Typography
   ============================================================ */
h2 { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.3px; }
h3 { font-size: var(--text-lg); font-weight: 600; }

/* ============================================================
   4. Layout
   ============================================================ */

/* Header */
.site-header {
  padding: 24px 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  transition: background var(--transition), border-color var(--transition);
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title a {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  transition: color var(--transition);
}
.site-title a:hover { text-decoration: none; color: var(--accent); }

/* Nav */
nav { display: flex; gap: 16px; align-items: center; }

.nav-link {
  font-size: var(--text-sm);
  color: var(--text-light);
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { text-decoration: none; color: var(--text); }
.nav-link.active { color: var(--text); border-bottom-color: var(--accent); }

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 300ms ease, border-color var(--transition);
  color: var(--text);
}
.theme-toggle:hover { transform: rotate(30deg); }

/* Progress bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 99;
  width: 0%;
  transition: width 100ms linear;
}

/* Footer */
.site-footer {
  padding: 24px 0 40px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--spacing-xl);
}

/* ============================================================
   5. Homepage
   ============================================================ */

/* Hero */
.hero {
  padding: 40px 0 28px;
  text-align: center;
}
.hero h2 {
  font-size: var(--text-3xl);
  font-weight: 800;
  letter-spacing: -0.8px;
  line-height: 1.25;
  margin-bottom: var(--spacing-sm);
}
.hero p {
  color: var(--text-light);
  font-size: var(--text-base);
  max-width: 400px;
  margin: 0 auto;
}
.hero-separator {
  width: 48px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  margin: var(--spacing-md) auto 0;
}

/* Tag filter */
.tag-filter {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  padding: 0 0 12px;
}
.tag-pill {
  font-size: var(--text-xs);
  padding: 3px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.tag-pill:hover { border-color: var(--accent); color: var(--accent); }
.tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Article cards */
.article-list { padding: 0 0 var(--spacing-xl); }

.article-card {
  display: flex;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}
.article-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.article-card .card-cover {
  flex-shrink: 0;
  width: 120px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--tag-bg);
}
.article-card .card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.article-card .card-body { flex: 1; min-width: 0; }
.article-card .card-date {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 2px;
}
.article-card .card-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}
.article-card .card-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 4px;
}
.article-card .card-excerpt {
  font-size: var(--text-sm);
  color: var(--text-light);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.6;
}

/* Card tags */
.card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.card-tag {
  font-size: 0.7rem;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--tag-bg);
  color: var(--accent);
}

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
  font-size: var(--text-sm);
}

/* ============================================================
   6. Article Detail
   ============================================================ */
.view {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  position: absolute;
  width: 100%;
  transition: opacity var(--transition), transform var(--transition);
}
.view.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  position: relative;
}

.back-btn {
  display: inline-block;
  margin: 20px 0 8px;
  padding: 4px 14px;
  font-size: var(--text-sm);
  color: var(--text-light);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
}
.back-btn:hover { color: var(--text); border-color: var(--accent); }

#article-detail { padding-bottom: 60px; }

.article-header {
  padding: 8px 0 24px;
}

.article-header .article-meta {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}
.article-header .article-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
}

.article-header .article-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: -0.5px;
}

.article-body {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: 2.1;
}

.article-body p { margin-bottom: 1.3em; }
.article-body h2 {
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  margin: 2em 0 0.6em;
}
.article-body h3 {
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  margin: 1.8em 0 0.5em;
}
.article-body ul, .article-body ol { margin-bottom: 1.3em; padding-left: 1.5em; }
.article-body li { margin-bottom: 0.4em; }
.article-body blockquote {
  margin: 1.5em 0;
  padding: 6px 0 6px 18px;
  border-left: 3px solid var(--accent);
  color: var(--text-light);
}
.article-body code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}
.article-body pre {
  background: var(--pre-bg);
  color: var(--pre-color);
  padding: 16px 20px;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 1.3em;
  font-size: var(--text-sm);
  line-height: 1.6;
}
.article-body pre code { background: none; padding: 0; color: inherit; }
.article-body img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}
.article-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.article-body .figure-caption {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 6px;
  margin-bottom: 1.8em;
}

/* Cover image */
.article-cover {
  margin: 0 0 24px;
  border-radius: var(--radius);
  overflow: hidden;
}
.article-cover img { width: 100%; display: block; }

/* Image gallery */
.image-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 1.5em 0;
}
.image-gallery img {
  border-radius: 6px;
  width: 100%;
  height: 200px;
  object-fit: contain;
  background: var(--tag-bg);
}

/* Article tags */
.article-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.article-tag {
  font-size: var(--text-xs);
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--tag-bg);
  color: var(--accent);
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox.active { display: flex; }
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 28px;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  opacity: 0.7;
}
.lightbox-close:hover { opacity: 1; }

/* ============================================================
   7. About Page
   ============================================================ */
.about-content { padding: 40px 0; }
.about-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--spacing-md);
}
.about-content h2 { margin-bottom: var(--spacing-sm); }
.about-content p { margin-bottom: var(--spacing-sm); color: var(--text-light); line-height: 1.8; }
.about-links { display: flex; gap: var(--spacing-md); margin-top: var(--spacing-md); }
.about-links a { font-size: var(--text-sm); }

/* ============================================================
   8. Weather Widget
   ============================================================ */
.weather-widget {
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: var(--spacing-sm);
}
.weather-pulse {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

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

/* ============================================================
   10. Responsive
   ============================================================ */
@media (max-width: 640px) {
  .hero { padding: 32px 0 20px; }
  .hero h2 { font-size: 1.6rem; }
  .site-title a { font-size: 1.1rem; }
  .article-header .article-title { font-size: 1.5rem; }
  .article-body { line-height: 1.9; }

  /* Stack cards vertically on mobile */
  .article-card { flex-direction: column; }
  .article-card .card-cover {
    width: 100%;
    height: 160px;
  }

  .image-gallery { grid-template-columns: 1fr; }
  .image-gallery img { height: auto; max-height: 300px; }
}
