/* ===== 主题变量 ===== */
:root {
  --accent: #2563eb;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --code-bg: #f8f8f8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10);
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #16181d;
  --surface: #1a1d23;
  --border: #2a2e37;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --code-bg: #272822;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* 无 JS 时的自动深色兜底 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f1115;
    --bg-soft: #16181d;
    --surface: #1a1d23;
    --border: #2a2e37;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --code-bg: #272822;
  }
}

/* ===== 基础 ===== */
* { 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", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  transition: background 0.2s, color 0.2s;
}

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

h1, h2, h3, h4 { line-height: 1.3; }

.muted { color: var(--text-muted); }

/* ===== 头部 ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }

.site-nav { display: flex; gap: 4px; margin-left: auto; }
.site-nav a {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.site-nav a:hover { color: var(--text); background: var(--bg-soft); text-decoration: none; }

.write-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
}
.write-btn:hover { opacity: 0.9; text-decoration: none; }

.theme-toggle, .menu-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 36px; height: 36px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle:hover, .menu-toggle:hover { background: var(--bg-soft); }
.menu-toggle { display: none; }

/* ===== 布局 ===== */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
/* 有 TOC 时三列 */
.layout:has(.toc) { grid-template-columns: 220px minmax(0, 1fr) 220px; }

.content { min-width: 0; }

/* ===== 侧边栏目录树 ===== */
.sidebar {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 4px;
}
.sidebar-title { font-weight: 600; margin-bottom: 8px; color: var(--text-muted); font-size: 0.85rem; }

.tree { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree li { margin: 2px 0; }
.tree-file a {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text);
}
.tree-file a:hover { background: var(--bg-soft); text-decoration: none; }
.tree-file a.active {
  background: var(--accent);
  color: #fff;
}
.tree-dir-name {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}
.tree-dir-name:hover { background: var(--bg-soft); }
.tree-dir.collapsed > .tree-sub { display: none; }

/* ===== 卡片 ===== */
.hero { padding: 12px 0 8px; }
.hero h1 { margin: 0 0 4px; font-size: 1.9rem; }
.hero-desc { margin: 0; color: var(--text-muted); }
.hero-author { margin: 6px 0 0; color: var(--text-muted); font-size: 0.9rem; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}
.card-pinned { border-color: var(--accent); }
.pin-badge {
  position: absolute;
  top: 14px; right: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
}
.card-title { margin: 0 0 8px; font-size: 1.25rem; }
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); text-decoration: none; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 10px; }
.card-cover { width: 100%; max-height: 240px; object-fit: cover; border-radius: 8px; margin: 8px 0; }
.card-desc { margin: 0; color: var(--text-muted); }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}
.chip:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.chip-tag { font-size: 0.78rem; }

/* ===== 分页 ===== */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  color: var(--text-muted);
}
.pagination a { padding: 6px 14px; border: 1px solid var(--border); border-radius: 8px; }
.pagination a:hover { background: var(--bg-soft); text-decoration: none; }

/* ===== 文章详情 ===== */
.page-title { margin: 0 0 20px; font-size: 1.7rem; }

.post-header { margin-bottom: 20px; }
.post-title { margin: 0 0 10px; font-size: 1.8rem; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--text-muted); font-size: 0.88rem; }
.post-meta .updated { font-size: 0.82rem; }
.post-tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.post-cover { width: 100%; max-height: 360px; object-fit: cover; border-radius: 12px; margin-bottom: 20px; }

/* ===== 正文排版 ===== */
.post-body { font-size: 1.02rem; }
.post-body h1, .post-body h2, .post-body h3, .post-body h4 {
  margin: 1.6em 0 0.6em;
  scroll-margin-top: 80px;
}
.post-body h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.post-body p { margin: 0.8em 0; }
.post-body a { text-decoration: underline; text-underline-offset: 2px; }
.post-body img { max-width: 100%; border-radius: 8px; }
.post-body ul, .post-body ol { padding-left: 1.4em; }
.post-body li { margin: 4px 0; }
.post-body blockquote {
  margin: 1em 0;
  padding: 2px 16px;
  border-left: 4px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
.post-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

.post-body :not(pre) > code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 0.9em;
}

.post-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.9rem;
}
.post-body pre code {
  background: transparent;
  padding: 0;
  font-family: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}
.code-block { position: relative; }
.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.8;
}
.copy-btn:hover { opacity: 1; color: var(--text); }

.post-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2em 0;
  font-size: 0.95rem;
}
.post-body th, .post-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.post-body th { background: var(--bg-soft); }

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.post-nav a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-nav .next { text-align: right; }

/* ===== TOC ===== */
.toc {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 0.85rem;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.toc-title { font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 4px 0; }
.toc-level-3 { padding-left: 14px; }
.toc a { color: var(--text-muted); }
.toc a:hover, .toc a.active { color: var(--accent); text-decoration: none; }

/* ===== 归档 / 标签 / 分类 ===== */
.archive-year h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.archive-list { list-style: none; padding: 0; margin: 0 0 16px; }
.archive-list li { display: flex; gap: 16px; padding: 5px 0; }
.archive-list time { color: var(--text-muted); font-size: 0.9rem; min-width: 92px; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}
.tag-item:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.tag-item .count {
  background: var(--bg-soft);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.78rem;
}

/* ===== 404 / 按钮 ===== */
.not-found { text-align: center; padding: 60px 0; }
.not-found h1 { font-size: 4rem; margin: 0; color: var(--text-muted); }
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 10px 22px;
  border-radius: 8px;
  margin-top: 12px;
}
.btn:hover { text-decoration: none; opacity: 0.9; }

/* ===== 页脚 / 返回顶部 / 遮罩 ===== */
.site-footer {
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 20px;
}

.back-to-top {
  position: fixed;
  right: 24px; bottom: 24px;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.back-to-top.show { opacity: 1; pointer-events: auto; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
  display: none;
}
.overlay.show { display: block; }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .layout,
  .layout:has(.toc) {
    grid-template-columns: 1fr;
  }
  .toc { display: none; }

  .menu-toggle { display: block; }
  .site-nav {
    position: fixed;
    top: 60px; right: 0;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    padding: 8px;
    box-shadow: var(--shadow-lg);
    display: none;
    min-width: 160px;
  }
  .site-nav.open { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 20px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s;
    max-height: none;
  }
  .sidebar.open { transform: translateX(0); }
}
