/* ========== 主题变量 ========== */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --card: #ffffff;
  --text: #1f2328;
  --text-soft: #57606a;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-weak: #ddf4ff;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.04), 0 4px 12px rgba(31, 35, 40, 0.05);
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --card: #0d1117;
  --text: #e6edf3;
  --text-soft: #9198a1;
  --border: #30363d;
  --accent: #4493f8;
  --accent-weak: rgba(56, 139, 253, 0.15);
  --code-bg: #161b22;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #0d1117;
    --bg-soft: #161b22;
    --card: #0d1117;
    --text: #e6edf3;
    --text-soft: #9198a1;
    --border: #30363d;
    --accent: #4493f8;
    --accent-weak: rgba(56, 139, 253, 0.15);
    --code-bg: #161b22;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.25);
  }
}

/* ========== 基础 ========== */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }
.loading { color: var(--text-soft); }

/* ========== 顶部导航 ========== */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.logo { font-size: 17px; font-weight: 700; color: var(--text); }
.logo:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a {
  color: var(--text-soft); padding: 5px 10px; border-radius: 6px;
  font-size: 14.5px; transition: color 0.15s, background 0.15s;
}
.nav a:hover { color: var(--text); text-decoration: none; background: var(--bg-soft); }
.nav a.active { color: var(--accent); font-weight: 600; }
.theme-toggle {
  margin-left: 8px; border: 1px solid var(--border); background: transparent;
  color: var(--text-soft); width: 32px; height: 32px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-soft); }
.theme-toggle svg { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
html:not([data-theme="dark"]) .theme-toggle .icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .theme-toggle .icon-moon { display: block; }
  html:not([data-theme]) .theme-toggle .icon-sun { display: none; }
}

/* ========== 首页 ========== */
.home-head { padding: 48px 0 8px; }
.home-head h1 { margin: 0 0 6px; font-size: 28px; line-height: 1.3; }
.home-sub { margin: 0; color: var(--text-soft); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 24px; }
.tag-chip {
  border: 1px solid var(--border); background: transparent; color: var(--text-soft);
  border-radius: 999px; padding: 4px 14px; font-size: 13px; cursor: pointer;
  transition: all 0.15s;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.post-list { display: flex; flex-direction: column; gap: 18px; padding-bottom: 48px; }
.post-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px;
  background: var(--card); box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s;
}
.post-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.post-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; font-size: 13px; color: var(--text-soft); }
.post-meta time::before { content: ""; display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--text-soft); margin: 0 8px 2px 0; opacity: 0.6; }
.post-card h2 { margin: 8px 0 6px; font-size: 20px; line-height: 1.4; }
.post-card h2 a { color: var(--text); }
.post-card h2 a:hover { color: var(--accent); text-decoration: none; }
.post-summary { margin: 0; color: var(--text-soft); font-size: 14.5px; }
.tag { display: inline-block; font-size: 12px; color: var(--accent); background: var(--accent-weak); border-radius: 4px; padding: 1px 8px; }
.empty { text-align: center; color: var(--text-soft); padding: 48px 0; }

/* ========== 文章页 ========== */
.article-wrap {
  display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 40px;
  padding-top: 36px; padding-bottom: 48px; align-items: start;
}
.article { min-width: 0; }
.article-head { margin-bottom: 20px; }
.article-head h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.35; }
.article-back { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; }

/* ========== Markdown 排版 ========== */
.markdown-body { word-break: break-word; }
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  margin: 28px 0 12px; line-height: 1.4; font-weight: 700;
  scroll-margin-top: 72px;
}
.markdown-body h1 { font-size: 24px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 21px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 17.5px; }
.markdown-body h4 { font-size: 16px; }
.markdown-body p { margin: 12px 0; }
.markdown-body ul, .markdown-body ol { margin: 12px 0; padding-left: 26px; }
.markdown-body li { margin: 4px 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 4px 0; }
.markdown-body blockquote {
  margin: 16px 0; padding: 2px 16px; color: var(--text-soft);
  border-left: 4px solid var(--border); background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}
.markdown-body code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em; background: var(--code-bg); border-radius: 5px; padding: 2px 6px;
}
.markdown-body pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; overflow-x: auto; line-height: 1.6;
}
.markdown-body pre code { background: transparent; padding: 0; font-size: 13.5px; }
.markdown-body table {
  border-collapse: collapse; margin: 16px 0; width: 100%;
  font-size: 14.5px; display: block; overflow-x: auto;
}
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 14px; text-align: left; }
.markdown-body th { background: var(--bg-soft); font-weight: 600; }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.markdown-body a code { color: inherit; }
.markdown-body .hljs { background: transparent; }

/* ========== 目录 ========== */
.toc { position: sticky; top: 80px; }
.toc-inner {
  border-left: 1px solid var(--border); padding-left: 14px; max-height: calc(100vh - 110px);
  overflow-y: auto; font-size: 13.5px;
}
.toc-title { font-weight: 700; color: var(--text); margin-bottom: 6px; font-size: 13px; letter-spacing: 0.5px; text-transform: uppercase; opacity: 0.7; }
.toc nav { display: flex; flex-direction: column; gap: 2px; }
.toc a { color: var(--text-soft); padding: 3px 0; line-height: 1.4; display: block; }
.toc a:hover { color: var(--accent); text-decoration: none; }
.toc .lv3 { padding-left: 14px; }

/* ========== 页脚 ========== */
.site-footer { border-top: 1px solid var(--border); padding: 20px 0; margin-top: 20px; }
.footer-inner { color: var(--text-soft); font-size: 13px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }

/* ========== 响应式 ========== */
@media (max-width: 820px) {
  .article-wrap { grid-template-columns: 1fr; }
  .toc { display: none; }
  .home-head { padding-top: 32px; }
  .article-head h1 { font-size: 24px; }
  .header-inner { height: 52px; }
}
