/* ===== 基础变量（支持明暗主题） ===== */
:root {
  --bg: #ffffff;
  --bg-alt: #f6f8fa;
  --text: #24292f;
  --text-muted: #656d76;
  --border: #d0d7de;
  --accent: #0969da;
  --code-bg: #1e1e1e;
  --code-text: #d4d4d4;
  --max-width: 860px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --code-bg: #161b22;
}

/* ===== 全局 ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

/* ===== 顶部导航 ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.navbar .inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}

.brand::before { content: "~/"; color: var(--accent); }

.brand-icon {
  width: 20px;
  height: 20px;
  vertical-align: -4px;
  margin-right: 6px;
  border-radius: 4px;
}

.nav-links a {
  margin-left: 18px;
  color: var(--text-muted);
  font-size: 14px;
}

.nav-links a:hover, .nav-links a.active { color: var(--accent); }

.theme-toggle {
  margin-left: 18px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 2px 8px;
  cursor: pointer;
  font-size: 14px;
}

/* ===== 主体布局 ===== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ===== 首页：文章列表 ===== */
.hero {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0; color: var(--text-muted); }

.post-list { list-style: none; margin: 0; padding: 0; }

.post-item {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.post-item h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.post-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.post-excerpt {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.tag {
  display: inline-block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== 文章页：侧边目录 + 正文 ===== */
.post-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.article { flex: 1; min-width: 0; }

.toc-sidebar {
  position: sticky;
  top: 70px;
  width: 200px;
  flex-shrink: 0;
  order: 2; /* 目录显示在右侧 */
  font-size: 13px;
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.toc-title {
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.toc-sidebar ul { list-style: none; margin: 0; padding: 0; }
.toc-sidebar a {
  display: block;
  color: var(--text-muted);
  padding: 3px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-sidebar a:hover { color: var(--accent); text-decoration: none; }
.toc-sidebar .toc-h3 a { padding-left: 14px; }

@media (max-width: 800px) {
  .toc-sidebar { display: none; }
}

/* ===== 文章页 ===== */
.article h1 { font-size: 30px; line-height: 1.4; }

.article .post-meta { margin-bottom: 20px; }

.article h2, .article h3 {
  margin-top: 2em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.article img { max-width: 100%; }

.article blockquote {
  margin: 1em 0;
  padding: 4px 16px;
  border-left: 4px solid var(--accent);
  background: var(--bg-alt);
  color: var(--text-muted);
}

/* 行内代码 */
.article code:not(pre code) {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.9em;
}

/* 代码块 */
.code-block {
  position: relative;
  margin: 1em 0;
}

.code-block pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
}

.code-lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 2px 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0 8px 0 8px;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 80px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 10px;
  cursor: pointer;
}

.copy-btn:hover { color: var(--accent); }

/* 表格 */
.article table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 14px;
}

.article th, .article td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.article th { background: var(--bg-alt); }

/* ===== 归档页分组 ===== */
.archive-year {
  font-size: 20px;
  color: var(--accent);
  margin-top: 28px;
}

.archive-list { list-style: none; padding: 0; }

.archive-list li {
  display: flex;
  gap: 16px;
  padding: 6px 0;
  font-size: 14px;
}

.archive-list time {
  color: var(--text-muted);
  font-family: Consolas, monospace;
  white-space: nowrap;
}

/* ===== 上一页 / 下一页 ===== */
.pagination {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  font-size: 14px;
}

/* ===== 页脚 ===== */
.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  text-align: center;
  padding: 24px 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.footer .mono { display: block; margin-bottom: 4px; }

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .hero h1 { font-size: 22px; }
  .nav-links a { margin-left: 12px; }
}
