/* ===== CSS Variables & Themes ===== */
:root {
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --code-bg: #f1f5f9;
  --tag-bg: #eff6ff;
  --tag-text: #2563eb;
  --tag-hover-bg: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --max-width: 1200px;
  --content-width: 720px;
  --header-height: 64px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #60a5fa;
  --accent-hover: #93bbfc;
  --accent-light: #1e3a5f;
  --border: #334155;
  --border-light: #1e293b;
  --code-bg: #1e293b;
  --tag-bg: #1e3a5f;
  --tag-text: #60a5fa;
  --tag-hover-bg: #1e3a5f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'Noto Sans SC', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

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

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

/* ===== Utility ===== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

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

.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;
}

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  background-color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .site-header {
  background-color: rgba(15, 23, 42, 0.85);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.site-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

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

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

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

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.theme-btn:hover {
  background-color: var(--accent-light);
  color: var(--accent);
}

/* ===== Mobile Menu Toggle ===== */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 5px;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ===== Main Content ===== */
.main-content {
  min-height: calc(100vh - var(--header-height) - 120px);
  padding: 40px 0 60px;
}

/* ===== Article List ===== */
.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.03em;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
}

.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: all var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.article-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.article-card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 10px;
  line-height: 1.4;
  color: var(--text);
}

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

.article-card-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 16px;
  flex: 1;
}

.article-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.article-card-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.article-card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ===== Tags ===== */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--tag-text);
  background: var(--tag-bg);
  border-radius: 20px;
  transition: all var(--transition);
  cursor: pointer;
}

.tag:hover {
  background: var(--tag-hover-bg);
}

/* ===== Tag Cloud ===== */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 32px;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tag-cloud-title {
  width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.tag-count {
  font-size: 0.75rem;
  opacity: 0.7;
}

.tag-filter-active {
  background: var(--accent);
  color: #fff;
}

.tag-filter-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* ===== Tags Page ===== */
.tags-page {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0;
}

.tag-lg {
  padding: 8px 16px;
  font-size: 0.95rem;
}

/* Article card reading time */
.article-card-reading {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Article Detail ===== */
.article-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.article-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.article-back:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.article-title {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 16px;
  letter-spacing: -0.03em;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.article-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.article-body {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
}

/* Article Body Typography */
.article-body h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 40px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.02em;
}

.article-body h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
}

.article-body h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.article-body p {
  margin-bottom: 20px;
}

.article-body ul,
.article-body ol {
  margin-bottom: 20px;
  padding-left: 24px;
}

.article-body li {
  margin-bottom: 6px;
}

.article-body li > ul,
.article-body li > ol {
  margin-bottom: 0;
}

.article-body blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 4px solid var(--accent);
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.article-body blockquote p:last-child {
  margin-bottom: 0;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 0.95rem;
}

.article-body th,
.article-body td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.article-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.article-body tr:nth-child(even) {
  background: var(--bg-secondary);
}

.article-body hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 32px 0;
}

/* ===== Article Navigation (Prev/Next) ===== */
.article-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.article-nav-link {
  flex: 1;
  max-width: 50%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-decoration: none;
}

.article-nav-link:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  text-decoration: none;
}

.article-nav-link-right {
  text-align: right;
}

.article-nav-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.article-nav-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

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

.article-body img {
  margin: 24px 0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

/* ===== Code Highlighting ===== */
.article-body pre {
  margin: 24px 0;
  padding: 20px;
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  border: 1px solid var(--border);
  position: relative;
}

.article-body pre code {
  padding: 0;
  background: transparent;
  border: none;
  font-size: 0.9rem;
  line-height: 1.6;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
}

.article-body code {
  padding: 2px 6px;
  background: var(--code-bg);
  border-radius: var(--radius-xs);
  font-size: 0.88em;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
  border: 1px solid var(--border);
}

/* Highlight.js theme overrides */
.hljs {
  background: transparent !important;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 24px;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state-desc {
  color: var(--text-secondary);
}

/* ===== Loading ===== */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 80px 24px;
  gap: 8px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--text-secondary);
}

.site-footer a:hover {
  color: var(--accent);
}

/* ===== Error Page ===== */
.error-page {
  text-align: center;
  padding: 80px 24px;
}

.error-code {
  font-size: 4rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
}

.error-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.error-desc {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}

.btn:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
  }

  .container,
  .container-narrow {
    padding: 0 16px;
  }

  .main-content {
    padding: 24px 0 40px;
  }

  /* Mobile menu: navigation becomes a sliding overlay */
  .menu-toggle {
    display: flex;
  }

  .header-nav {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-direction: column;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    gap: 4px;
    box-shadow: var(--shadow-lg);
  }

  .header-nav.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .nav-link {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
  }

  .nav-link span {
    display: inline;
  }

  .article-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .article-title {
    font-size: 1.6rem;
  }

  .article-body {
    font-size: 1rem;
  }

  .article-body h2 {
    font-size: 1.35rem;
  }

  .article-body h3 {
    font-size: 1.15rem;
  }

  .page-title {
    font-size: 1.6rem;
  }

  .article-card {
    padding: 20px;
  }

  .tag-cloud {
    padding: 16px;
  }

  .article-body pre {
    padding: 16px;
    margin: 16px -8px;
    border-radius: 0;
  }

  /* Article nav stacks on mobile */
  .article-nav {
    flex-direction: column;
  }

  .article-nav-link {
    max-width: 100%;
  }

  .article-nav-link-right {
    text-align: left;
  }

  .tags-page {
    gap: 8px;
  }

  .tag-lg {
    padding: 6px 14px;
  }
}

@media (max-width: 480px) {
  .article-grid {
    grid-template-columns: 1fr;
  }

  .article-card-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .article-meta {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
}

/* ===== Print ===== */
@media print {
  .site-header,
  .theme-btn,
  .article-back,
  .site-footer {
    display: none;
  }

  .main-content {
    padding: 0;
  }

  .article-body pre {
    white-space: pre-wrap;
    break-inside: avoid;
  }
}
