:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f2f4f7;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #3b62f6;
  --primary-dark: #2b4bd8;
  --primary-soft: rgba(59, 98, 246, 0.1);
  --border: #e4e7ec;
  --code-bg: #f5f6f8;
  --inline-code: #c7254e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  /* 页面外壳宽度：前台与后台使用同一画布，页头、正文、页脚保持一致，避免宽屏下左右错位 */
  --maxw: 1640px;
  --sidebar: 300px;
  --header-h: 60px;
}

html[data-theme="dark"] {
  --bg: #0f1116;
  --surface: #171a21;
  --surface-alt: #1d212a;
  --text: #e6e8ec;
  --muted: #98a2b3;
  --primary: #7aa2ff;
  --primary-dark: #5b86f7;
  --primary-soft: rgba(122, 162, 255, 0.14);
  --border: #262b36;
  --code-bg: #12151c;
  --inline-code: #ff8fab;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* 让原生表单控件、滚动条跟随主题 */
html { scroll-behavior: smooth; color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  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.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 内容不足一屏时页脚仍贴在底部 */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

img { max-width: 100%; height: auto; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }

/* 键盘可达性：只在键盘聚焦时显示明显的焦点环 */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 尊重系统的「减弱动画」偏好 */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px);
}

/* ---------- 头部 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  /* 不支持 color-mix / backdrop-filter 的浏览器退化为不透明实色头，保证可读性 */
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--header-h);
  padding: 8px clamp(16px, 3vw, 32px);
  max-width: var(--maxw);
  margin: 0 auto;
}

/* 前后台共用同一画布宽度，页头与正文无需再单独适配 */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: clamp(1rem, 1.4vw, 1.15rem);
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  flex: none;
}

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.94rem;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-alt); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search-form { display: flex; align-items: center; }
.search-form input {
  width: clamp(140px, 18vw, 260px);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* 搜索自动补全下拉：绝对定位浮在输入框下方，跟随输入框宽度 */
.suggest-box {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.search-form, .search-panel .btn-row { position: relative; }
.suggest-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none;
}
.suggest-item:hover, .suggest-item:focus { background: var(--primary-soft); text-decoration: none; }
/* 类型标签与 .badge 统一风格，post / tag 保持同一视觉以免花哨 */
.suggest-type {
  flex: 0 0 auto;
  font-size: 0.72rem; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border);
}

.inline-search { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-search input[type="search"] {
  flex: 1 1 240px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: .9rem;
}
.inline-search input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.user-menu { display: flex; align-items: center; gap: 8px; margin: 0; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  flex: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { border-color: var(--primary); background: var(--primary-soft); }

/* 移动端用搜索图标进入 /search，避免输入框挤占页眉；桌面端隐藏该图标。
   必须放在 .icon-btn 之后，否则 display:grid 会覆盖这里的隐藏。 */
.search-link { display: none; }

/* ---------- 栅格布局：主内容 + 侧边栏 ---------- */
main.container {
  padding-top: clamp(20px, 3vw, 34px);
  padding-bottom: clamp(32px, 5vw, 64px);
  flex: 1 0 auto;
  width: 100%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2vw, 28px);
  align-items: start;
}

.layout-main { min-width: 0; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.side-card h3 { font-size: 0.92rem; letter-spacing: 0.02em; }

.side-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.side-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.side-stat b { font-size: 1.15rem; line-height: 1.2; }
.side-stat span { color: var(--muted); font-size: 0.78rem; }

@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) var(--sidebar); }
  .sidebar {
    position: sticky;
    top: calc(var(--header-h) + 20px);
    /* 目录/侧栏内容过长时，让侧栏自身在视口内滚动，
       避免 sticky 容器底部被裁掉、鼠标滚轮只能滚动正文而看不到后面的目录 */
    max-height: calc(100vh - var(--header-h) - 40px);
    overflow-y: auto;
    /* 细滚动条，避免占用过多空间 */
    scrollbar-width: thin;
  }
  .sidebar:empty { display: none; }
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(120% 140% at 0% 0%, var(--primary-soft), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(22px, 3vw, 34px);
  box-shadow: var(--shadow);
  margin-bottom: clamp(18px, 2.4vw, 28px);
}
.hero h1 { margin: 0 0 6px; font-size: clamp(1.4rem, 2.6vw, 2rem); letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--muted); font-size: clamp(0.94rem, 1.3vw, 1.05rem); }

/* 错误页（404/5xx）：居中展示大号状态码与返回入口 */
.error-hero { text-align: center; }
.error-code { font-size: 3rem; margin-bottom: 4px; }
.error-actions { margin-top: 18px; }

.stats { display: flex; gap: clamp(12px, 2vw, 26px); flex-wrap: wrap; margin-top: 16px; }
.stat { font-size: 0.85rem; color: var(--muted); }
.stat b { color: var(--text); font-size: 1.1rem; }

.stats-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 2vw, 22px);
  box-shadow: var(--shadow);
  margin-bottom: clamp(16px, 2vw, 24px);
}
.stats-panel .side-stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

/* ---------- 文章卡片 ---------- */
.post-list { display: flex; flex-direction: column; gap: clamp(12px, 1.6vw, 18px); }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 2vw, 22px);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.post-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 12px 32px rgba(16, 24, 40, 0.1);
}
/* 列表卡片封面：右侧小缩略图，与无封面卡片保持统一观感（标题/摘要排版不变） */
.post-card.has-cover { display: flow-root; }
.post-card-cover { float: right; width: clamp(110px, 14vw, 170px); margin: 2px 0 12px 18px; border-radius: var(--radius-sm); overflow: hidden; }
.post-card-cover img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: var(--primary-soft); }
.pin-input {
  /* type=number 不在全局输入样式选择器内，这里补齐主题化外观 */
  width: 64px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  vertical-align: middle;
  -moz-appearance: textfield;
  appearance: textfield;
}
.pin-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.pin-input::-webkit-outer-spin-button,
.pin-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pin-cell { white-space: nowrap; }
.pin-cell a { font-size: 0.86rem; margin-left: 4px; }

.post-card h2 { margin: 0 0 8px; font-size: clamp(1.1rem, 1.8vw, 1.32rem); line-height: 1.4; }
.post-card h2 a { color: var(--text); }
.post-card h2 a:hover { color: var(--primary); text-decoration: none; }

.post-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  color: var(--muted); font-size: 0.84rem; margin-bottom: 10px;
}
.post-meta .dot { opacity: 0.5; }

.post-summary { color: var(--muted); margin: 0 0 12px; font-size: 0.96rem; }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  line-height: 1.6;
}
a.tag:hover { text-decoration: none; background: var(--primary); color: #fff; }
.tag-count { color: var(--muted); font-size: 0.76rem; }

/* 页脚渲染耗时：比标签行更淡更小的技术信息行 */
.render-time { color: var(--muted); opacity: 0.5; font-size: 0.72rem; margin-top: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  background: var(--surface-alt);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.draft { background: #fef3c7; color: #92400e; border-color: #fde68a; }
/* 置顶 / 管理员徽标：主题色弱底，与「草稿」的琥珀色区分开 */
.badge.pin, .badge.admin { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.empty {
  text-align: center;
  padding: clamp(40px, 8vw, 72px) 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- 分页 ---------- */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: clamp(18px, 2.4vw, 28px); }
.pager a, .pager span {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}
.pager a:hover { border-color: var(--primary); text-decoration: none; }
.pager .disabled { opacity: 0.45; }
.pager-info { align-self: center; color: var(--muted); font-size: 0.85rem; }
/* 分页分组：左右各一组「首页/上一页」「下一页/尾页」，中间放页码与跳页表单 */
.pager-group { display: flex; align-items: center; gap: 8px; }
.pager-jump { display: flex; align-items: center; gap: 6px; }
.pager-jump-label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 0.85rem;
}
.pager-jump input {
  width: 5.5em;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}
.pager-jump input::-webkit-outer-spin-button,
.pager-jump input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pager-jump input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.pager-jump button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.pager-jump button:hover { border-color: var(--primary); }

/* ---------- 文章详情 ---------- */
/* 标题区左右分栏：标题/元信息/标签在左，管理端「编辑/删除」固定右上角 */
.post-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.post-heading { flex: 1 1 auto; min-width: 0; }
.post-header-actions { display: flex; gap: 8px; flex: none; margin-top: 4px; }
.post-header h1 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.post-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 42px);
  box-shadow: var(--shadow);
}

.post-content { font-size: clamp(0.98rem, 1.1vw, 1.05rem); }

/* 详情页封面：紧贴标题下方，圆角裁切 */
.post-cover { margin: 18px 0 0; }
.post-cover img { display: block; width: 100%; max-height: 420px; object-fit: cover; border-radius: var(--radius); background: var(--primary-soft); }

/* 正文随容器自适应：标题、段落、图片、表格、代码块都铺满整列宽度，
   不再用固定行宽（ch）截断，避免宽屏下正文右侧留出大片空白。 */

.post-content h1, .post-content h2, .post-content h3, .post-content h4 {
  margin: 1.6em 0 0.6em; line-height: 1.35; scroll-margin-top: calc(var(--header-h) + 16px);
}
.post-content h1 { font-size: 1.5rem; }
.post-content h2 { font-size: 1.32rem; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.post-content h3 { font-size: 1.14rem; }
.post-content p { margin: 0.9em 0; }
.post-content ul, .post-content ol { padding-left: 1.4em; }
.post-content li { margin: 0.3em 0; }
.post-content blockquote {
  margin: 1em 0; padding: 2px 16px;
  border-left: 3px solid var(--primary);
  background: var(--surface-alt);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}
/* 提示块（> [!NOTE] / > [!WARNING] …）：在引用基础上按类型换色 */
.post-content blockquote.callout {
  border-left-width: 4px;
  background: var(--surface-alt);
  border-radius: 0 8px 8px 0;
  color: var(--text);
  padding: 10px 16px 12px;
}
.post-content blockquote.callout > *:first-of-type { margin-top: 0.2em; }
.post-content blockquote.callout > *:last-child { margin-bottom: 0.2em; }
.post-content .callout-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 0.4em;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}
.post-content .callout-title::before {
  font-size: 1em;
  line-height: 1;
}
.post-content blockquote.callout-note      { border-left-color: #3b82f6; }
.post-content blockquote.callout-note      .callout-title { color: #3b82f6; }
.post-content blockquote.callout-note      .callout-title::before { content: "ⓘ"; }
.post-content blockquote.callout-info      { border-left-color: #0ea5e9; }
.post-content blockquote.callout-info      .callout-title { color: #0ea5e9; }
.post-content blockquote.callout-info      .callout-title::before { content: "ⓘ"; }
.post-content blockquote.callout-tip       { border-left-color: #10b981; }
.post-content blockquote.callout-tip       .callout-title { color: #10b981; }
.post-content blockquote.callout-tip       .callout-title::before { content: "✓"; }
.post-content blockquote.callout-success   { border-left-color: #22c55e; }
.post-content blockquote.callout-success   .callout-title { color: #22c55e; }
.post-content blockquote.callout-success   .callout-title::before { content: "✓"; }
.post-content blockquote.callout-important { border-left-color: #8b5cf6; }
.post-content blockquote.callout-important .callout-title { color: #8b5cf6; }
.post-content blockquote.callout-important .callout-title::before { content: "!"; }
.post-content blockquote.callout-warning   { border-left-color: #f59e0b; }
.post-content blockquote.callout-warning   .callout-title { color: #f59e0b; }
.post-content blockquote.callout-warning   .callout-title::before { content: "▲"; }
.post-content blockquote.callout-caution   { border-left-color: #ef4444; }
.post-content blockquote.callout-caution   .callout-title { color: #ef4444; }
.post-content blockquote.callout-caution   .callout-title::before { content: "▲"; }
.post-content blockquote.callout-danger    { border-left-color: #dc2626; }
.post-content blockquote.callout-danger    .callout-title { color: #dc2626; }
.post-content blockquote.callout-danger    .callout-title::before { content: "▲"; }

/* [TOC] 生成的文内目录 */
.post-content nav.toc {
  margin: 1em 0 1.4em;
  padding: 10px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
}
.post-content nav.toc ol { list-style: none; padding-left: 0; margin: 0; }
.post-content nav.toc li { margin: 0.15em 0; }
.post-content nav.toc .toc-h2 { padding-left: 0.9em; }
.post-content nav.toc .toc-h3 { padding-left: 1.8em; }
.post-content nav.toc a { color: var(--muted); }
.post-content nav.toc a:hover { color: var(--primary); }

/* 公式（没有公式引擎时按代码保留）：去掉行号，更像一段公式源码 */
.post-content .code-block[data-lang="math"] .code-line::before { content: none; width: 0; margin-right: 0; }
.post-content .math-inline { background: var(--code-bg); padding: 2px 6px; border-radius: 6px; font-size: 0.9em; }

/* 行锚点：渲染器为编辑器预览插入的零高度标记，仅用于滚动映射，不占版面。
   height:0 的块级元素不产生可见空间，相邻块的外边距仍会正常折叠。 */
.post-content .md-anchor { display: block; height: 0; overflow: hidden; }

.post-content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.88em;
  color: var(--inline-code);
  border: 1px solid var(--border);
}
.post-content .code-block {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  /* 顶部留出一条放置语言标签与复制按钮的空间 */
  padding: 34px 16px 14px;
  overflow-x: auto;
  margin: 1.2em 0;
}
.post-content .code-block code {
  background: none;
  padding: 0;
  border: none;      /* code 是行内元素，跨行时每行都会绘制边框，必须重置 */
  border-radius: 0;
  color: inherit;    /* 防止行内代码配色漏进代码块，污染未着色的文本 */
  font-size: 0.86rem;
  line-height: 1.6;
  counter-reset: code-line;
}
/* 行号由 CSS 计数器绘制：不进入文本节点，因此复制代码时不会被带上 */
.post-content .code-line { counter-increment: code-line; }
.post-content .code-line::before {
  content: counter(code-line);
  display: inline-block;
  width: 2.2em;
  margin-right: 12px;
  text-align: right;
  color: var(--muted);
  opacity: 0.5;
  user-select: none;
  -webkit-user-select: none;
}
.post-content .code-lang {
  position: absolute; top: 9px; right: 14px;
  font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
/* 由 JS 包一层不滚动的容器，保证按钮/标签在横向滚动时保持可见 */
.code-wrap { position: relative; margin: 1.2em 0; }
.code-wrap .code-block { margin: 0; }
.code-wrap .code-lang { position: absolute; top: 10px; left: 16px; right: auto; }
.code-copy {
  position: absolute; top: 7px; right: 10px;
  padding: 3px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.code-wrap:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--primary); border-color: var(--primary); }
.code-copy.done { color: #16a34a; border-color: #86efac; opacity: 1; }

.post-content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.post-content .table-wrap { overflow-x: auto; margin: 1.2em 0; }
.post-content table { border-collapse: collapse; width: 100%; font-size: 0.94rem; }
.post-content th, .post-content td { padding: 8px 12px; border: 1px solid var(--border); }
.post-content th { background: var(--surface-alt); font-weight: 600; }
.post-content tbody tr:nth-child(even) td { background: var(--surface-alt); }
.post-content img { border-radius: 10px; }
.post-content img.zoomable { cursor: zoom-in; }
/* 任务列表：隐藏原生圆点，勾选框与文字对齐 */
/* 任务列表：去掉项目符号，用绝对定位把复选框固定在原本项目符号的位置，
   这样既不依赖负 margin（负 margin 会把嵌套层级的缩进抵消掉，导致子任务看不出缩进），
   又能让复选框与文字同行对齐，列表项内出现 <p> 块时也不会让复选框悬空。 */
.post-content li.task { list-style: none; position: relative; padding-left: 1.6em; }
.post-content li.task > input[type="checkbox"] {
  position: absolute; left: 0; top: 0.32em; margin: 0; vertical-align: baseline;
}

/* 高亮 ==文本== */
.post-content mark {
  /* 不支持 color-mix 的浏览器退化为主题软色高亮 */
  background: var(--primary-soft);
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: inherit;
  padding: 0 3px;
  border-radius: 4px;
}

/* 定义列表 */
.post-content dl { margin: 1.1em 0; }
.post-content dt { font-weight: 600; margin-top: 0.7em; }
.post-content dd {
  margin: 0.15em 0 0 0;
  padding-left: 1.1em;
  border-left: 2px solid var(--border);
  color: var(--muted);
}

/* 图注 */
.post-content .post-figure { margin: 1.4em 0; text-align: center; }
.post-content .post-figure img { display: block; margin: 0 auto; }
.post-content .post-figure figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

/* 脚注 */
.post-content .fn-ref { font-size: 0.72em; line-height: 1; }
.post-content .fn-ref a { padding: 0 2px; }
.post-content .footnotes {
  margin-top: 2.4em;
  font-size: 0.88rem;
  color: var(--muted);
}
.post-content .footnotes ol { padding-left: 1.3em; }
.post-content .footnotes li { scroll-margin-top: calc(var(--header-h) + 16px); }
.post-content .fn-back { margin-left: 4px; }

/* 标题锚点（由 JS 注入，不改变 Markdown 输出） */
.post-content .heading-anchor {
  margin-left: 8px;
  color: var(--muted);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.post-content h1:hover .heading-anchor,
.post-content h2:hover .heading-anchor,
.post-content h3:hover .heading-anchor,
.post-content h4:hover .heading-anchor,
.post-content h5:hover .heading-anchor,
.post-content h6:hover .heading-anchor { opacity: 0.6; }
.post-content .heading-anchor:hover { opacity: 1; text-decoration: none; }

/* 代码着色：浅色/深色各一套，取自常见编辑器配色 */
.tok-comment { color: #6a737d; font-style: italic; }
.tok-string { color: #0a7c42; }
.tok-number { color: #b8500f; }
.tok-keyword { color: #8250df; }
.tok-func { color: #1153a8; }
html[data-theme="dark"] .tok-comment { color: #7c8695; }
html[data-theme="dark"] .tok-string { color: #7ee787; }
html[data-theme="dark"] .tok-number { color: #ffab70; }
html[data-theme="dark"] .tok-keyword { color: #d2a8ff; }
html[data-theme="dark"] .tok-func { color: #79c0ff; }

/* ---------- 目录 ---------- */
.toc ul { list-style: none; margin: 0; padding-left: 0; }
.toc li { margin: 4px 0; font-size: 0.92rem; }
.toc .lv2 { padding-left: 0; }
.toc .lv3 { padding-left: 16px; font-size: 0.86rem; }

.toc-mobile { display: none; margin-bottom: clamp(12px, 2vw, 18px); }
.toc-mobile summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
}
.toc-mobile summary::-webkit-details-marker { display: none; }
.toc-mobile summary::after { content: " ▾"; color: var(--muted); }
.toc-mobile[open] summary::after { content: " ▴"; }
.toc-mobile ul { margin-top: 10px; }

/* ---------- 上一篇 / 下一篇 ---------- */
.post-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 1.6vw, 16px);
  margin-top: clamp(16px, 2vw, 22px);
}
.post-nav-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  min-width: 0;
}
.post-nav-item:hover { border-color: var(--primary); text-decoration: none; }
.post-nav-item.next { text-align: right; }
.post-nav-label { color: var(--muted); font-size: 0.78rem; }
.post-nav-item b { font-weight: 600; font-size: 0.95rem; }
.post-nav-item.placeholder { visibility: hidden; }

/* ---------- 相关文章 ---------- */
.related { margin-top: clamp(12px, 1.6vw, 18px); }
.related-list { list-style: none; margin: 0; padding: 0; }
.related-list li {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}
.related-list li:first-child { border-top: none; padding-top: 0; }
.related-list a { min-width: 0; }
.related-list .tag-count { flex: none; }

/* ---------- 评论 ---------- */
.comments { margin-top: clamp(16px, 2vw, 24px); }
.comments h3, .card h3 { font-size: 1.05rem; margin: 0 0 14px; }
.comment { border-top: 1px solid var(--border); padding: 12px 0; }
.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.comment-head b { color: var(--text); font-size: 0.94rem; }
/* 管理员自己发表的评论：作者名用主题色并带徽标，与普通访客一眼区分 */
.comment-head b.is-admin { color: var(--primary); }
/* 管理员发表评论时的身份提示条（替代昵称/邮箱输入框） */
.admin-identity {
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.9rem;
}
.admin-identity b { color: var(--primary); }
.comment-body { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; }
.comment.is-pending { background: var(--primary-soft); border-radius: var(--radius-sm); padding: 12px; }

/* 评论嵌套：回复整体缩进并加左侧引导线，层级一目了然 */
.comment-replies { margin-top: 10px; padding-left: 14px; margin-left: 2px; border-left: 2px solid var(--border); }
.comment-replies .comment { border-top: none; padding: 8px 0; }
.comment-replies .comment:first-child { padding-top: 0; }
/* 邮箱（仅管理员可见）与回复链接同属辅助信息，弱化显示，避免抢作者名的视觉重心 */
.comment-email { font-size: 0.8rem; }
.comment-reply { font-size: 0.8rem; }
/* 超出缩进上限的回复被压平到同级，正文前以「回复 @某人」标注实际回复对象 */
.comment-replyto { color: var(--primary); }

/* 评论分页：仅当评论超过一页时出现 */
.comment-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.comment-pager .disabled { color: var(--muted); opacity: 0.6; }

/* 评论回复指示条：位于表单上方，提示当前正在回复哪一层。
   显式处理 [hidden]：作者样式里的 display 会盖过 UA 的 [hidden]{display:none}，否则空条也会常显。 */
.reply-to { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
.reply-to[hidden] { display: none; }
.reply-cancel {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--primary); font: inherit; font-size: 0.85rem;
}
.reply-cancel:hover { text-decoration: underline; }
.client-brief { font-size: 0.78rem; color: var(--muted); opacity: 0.85; }
.client-ip { font-size: 0.78rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
/* IP 归属地简述：与客户端信息同色系，作为轻量补充信息 */
.client-geo, .geo { font-size: 0.76rem; color: var(--muted); opacity: 0.85; }
.client-geo::before { content: "·"; margin-right: 0.3em; color: var(--muted); }
.badge.pending {
  background: var(--primary-soft); color: var(--primary);
  border: 1px solid var(--primary);
}
/* 客户端详情：默认折叠，避免后台被长 UA 占满 */
.client-info { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }
.client-info summary { cursor: pointer; width: fit-content; }
.client-info dl {
  display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px;
  margin: 8px 0 0; padding: 10px 12px;
  background: var(--surface-alt); border-radius: var(--radius-sm);
}
.client-info dt { color: var(--muted); }
.client-info dd { margin: 0; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- 卡片 / 表单 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 2vw, 24px);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: clamp(12px, 1.6vw, 18px); }
.card h2 { margin: 0 0 14px; font-size: 1.12rem; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="url"], input[type="email"],
input[type="datetime-local"], input[type="date"], input[type="time"], textarea, select {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea {
  min-height: clamp(240px, 46vh, 620px);
  resize: vertical;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}
textarea#comment-content { min-height: 120px; }
textarea#footer { min-height: 160px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 220px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 0.92rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap; /* 按钮文字不换行，避免被相邻输入框挤压后折行 */
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { background: transparent; color: #dc2626; border-color: #fca5a5; }
.btn.danger:hover { background: #fee2e2; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; } /* 整宽按钮（登录 / 改密等表单） */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* 复选框统一跟随主题主色（后台批量操作、浏览记录勾选等处保持一致） */
input[type="checkbox"] { accent-color: var(--primary); }

/* 视觉隐藏（仍可被 label / JS 触发），如自定义样式的文件选择框 */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* 媒体库 */
.upload-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload-row .btn, .upload-row label.btn { flex: 0 0 auto; white-space: nowrap; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
/* 每张图片是一个圆角方框，悬停（或键盘聚焦、已勾选）时浮出信息层 */
.media-item { position: relative; margin: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface-alt); }
.media-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-alt); }
/* 信息层自身即遮罩渐变，保证浮层文字在任何图片上都可读 */
.media-overlay {
  position: absolute; inset: 0;
  display: grid; grid-template-rows: auto 1fr auto; gap: 6px; padding: 8px;
  background: linear-gradient(180deg, rgba(8, 10, 16, 0.52) 0%, rgba(8, 10, 16, 0.08) 32%, rgba(8, 10, 16, 0.1) 62%, rgba(8, 10, 16, 0.68) 100%);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.media-item:hover .media-overlay,
.media-item:focus-within .media-overlay { opacity: 1; pointer-events: auto; }
/* 已勾选的卡片即使不悬停也保持浮层可见（与 :has 分开写，避免老浏览器丢掉整条规则） */
.media-item:has(input[name="media"]:checked) .media-overlay { opacity: 1; pointer-events: auto; }
.media-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.media-check { display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 6px; background: rgba(255, 255, 255, 0.9); cursor: pointer; }
.media-check input { width: 15px; height: 15px; margin: 0; cursor: pointer; }
.media-size { flex: none; padding: 2px 8px; border-radius: 999px; background: rgba(8, 10, 16, 0.55); color: #fff; font-size: 0.74rem; white-space: nowrap; }
.media-name { display: grid; place-items: center; min-width: 0; padding: 0 4px; }
/* 文件名在正中：平时是透明的输入框（看着就是标题），聚焦后才露出可编辑外观 */
.media-rename-input { width: 100%; min-width: 0; padding: 4px 6px; font-size: 0.85rem; text-align: center; background: transparent; border-color: transparent; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55); }
.media-rename-input:focus { background: var(--surface); border-color: var(--primary); color: var(--text); text-shadow: none; }
.media-actions { display: flex; gap: 6px; }
/* 触屏没有悬停状态，浮层改为常驻，否则操作按钮无从触发 */
@media (hover: none) {
  .media-overlay { opacity: 1; pointer-events: auto; }
}

/* 带操作按钮的输入行（如封面：输入框 + 上传按钮） */
.input-with-action { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.input-with-action input[type="text"],
.input-with-action input[type="url"] { flex: 1 1 220px; min-width: 0; }
/* 按钮不被输入框挤压换行 */
.input-with-action .btn, .btn-row .btn, .media-actions .btn { flex: 0 0 auto; white-space: nowrap; }
/* 媒体卡片底部的操作按钮：一行内平均分布。必须排在上一条 .media-actions .btn（同特异性，后者生效）之后，
   且刻意不用 btn-sm —— .btn.ghost.btn-sm 的特异性更高且定义更靠后，会盖掉这里的紧凑内边距。 */
.media-actions .btn { flex: 1 1 0; min-width: 0; padding: 4px 2px; font-size: 0.78rem; background: var(--surface); border-color: var(--border); color: var(--text); }
.media-actions .btn:hover { background: var(--primary-soft); }
.media-actions .btn.danger { color: #dc2626; border-color: #fca5a5; }
.media-actions .btn.danger:hover { background: #fee2e2; }
.editor-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
/* alt 输入框比正文窄，避免与「插入图片」按钮抢空间（需盖过基础输入样式的 width:100%） */
input.alt-input { width: clamp(140px, 20vw, 220px); flex: 0 1 auto; }

/* 后台编辑评论：内联编辑框 */
.comment-edit-box { margin-top: 6px; }
.comment-edit-input { min-height: 80px; }

/* 标签管理列表 */
.tag-mgmt-list { display: flex; flex-direction: column; }
.tag-mgmt-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--border); }
.tag-mgmt-item:first-child { border-top: none; padding-top: 0; }
.tag-mgmt-head { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.tag-mgmt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag-mgmt-actions .tag-rename-input { width: clamp(120px, 18vw, 180px); }
.tag-mgmt-actions .tag-merge-select { width: auto; min-width: 120px; }
.btn-sm { padding: 4px 11px; font-size: 0.8rem; }

/* 待审核评论批量操作工具条 */
.comment-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; }
.check-inline { display: inline-flex; align-items: center; align-self: center; gap: 6px; color: var(--muted); font-size: 0.85rem; cursor: pointer; }

.notice { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.9rem; margin-bottom: 14px; }
.notice.error { background: #fee2e2; color: #991b1b; }
.notice.ok { background: #dcfce7; color: #166534; }

/* ---------- 登录 / 改密 ---------- */
.auth-page {
  display: grid;
  place-items: center;
  padding: clamp(24px, 6vw, 64px) 0;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-title { margin: 0 0 4px; font-size: clamp(1.2rem, 2.4vw, 1.5rem); }
.auth-desc { margin: 0 0 18px; color: var(--muted); font-size: 0.9rem; }
.auth-hint { margin: 16px 0 0; line-height: 1.6; }

/* ---------- 归档 & 标签 & 搜索 ---------- */
.archive-year { margin-bottom: 26px; }
.archive-year h2 { font-size: clamp(1.15rem, 2vw, 1.4rem); margin: 0 0 4px; }
.archive-year .year-meta { color: var(--muted); font-size: 0.84rem; margin-bottom: 12px; }
.archive-month { margin-bottom: 12px; }
.archive-month h3 { font-size: 0.95rem; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li {
  display: flex; gap: 12px; align-items: baseline;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.archive-list .date { color: var(--muted); font-size: 0.84rem; min-width: 84px; font-variant-numeric: tabular-nums; flex: none; }
.archive-list a { flex: 1; min-width: 0; }

.search-result { border-top: 1px solid var(--border); padding: 14px 0; }
.search-result:first-of-type { border-top: none; padding-top: 0; }
.search-result h3 { margin: 0 0 4px; font-size: 1.06rem; }
.search-result p { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.search-panel { margin-bottom: clamp(12px, 1.6vw, 18px); }
.search-panel input[type="text"] { flex: 1 1 260px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: clamp(14px, 2vw, 22px); flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: clamp(1.25rem, 2.4vw, 1.6rem); }
/* 卡片内的小标题与操作按钮同行时，去掉默认外边距 */
.page-head h2 { margin: 0; font-size: 1.12rem; }
.page-head .meta { color: var(--muted); font-size: 0.86rem; display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.84rem; }

/* ---------- 管理端 ---------- */
/* 分页锚点定位到表格时，留出吸顶页头的高度，避免表头被遮住 */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; scroll-margin-top: calc(var(--header-h) + 16px); }
table.admin { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.admin th, table.admin td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; }
table.admin th { color: var(--muted); font-weight: 600; font-size: 0.82rem; white-space: nowrap; }
table.admin tr:hover td { background: var(--surface-alt); }
table.admin .actions { display: flex; gap: 12px; white-space: nowrap; }
table.admin .actions a { font-size: 0.86rem; }

/* 浏览记录等表格的选择列 */
table.admin th.pick, table.admin td.pick { width: 36px; text-align: center; }
table.admin .pick input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* 浏览记录：详情入口与异常标记 */
.detail-cell { white-space: nowrap; }
.badge.warn { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn.ghost.btn-sm { padding: 4px 11px; font-size: 0.8rem; }

/* 深色模式下，下方语义色原本写死的是浅色配色，在深色背景上观感突兀，
   统一改为半透明的主题色，避免「浅色小卡片」与环境格格不入 */
html[data-theme="dark"] .badge.draft { background: rgba(245, 158, 11, 0.16); color: #fcd34d; border-color: rgba(245, 158, 11, 0.34); }
html[data-theme="dark"] .notice.error { background: rgba(239, 68, 68, 0.14); color: #fca5a5; }
html[data-theme="dark"] .notice.ok { background: rgba(34, 197, 94, 0.14); color: #86efac; }
html[data-theme="dark"] .badge.warn { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
html[data-theme="dark"] .btn.danger { color: #f87171; border-color: rgba(248, 113, 113, 0.45); }
html[data-theme="dark"] .btn.danger:hover { background: rgba(239, 68, 68, 0.16); }
.tag.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* 浏览记录详情：模态框。内容由 JS 从行内 <template> 克隆，样式与后台保持一致 */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: clamp(12px, 3vw, 32px); }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(12, 14, 20, 0.62); }
.modal-panel {
  position: relative;
  width: min(900px, 100%);
  max-height: min(86vh, 880px);
  display: flex;
  flex-direction: column;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.34);
  animation: modal-in 0.16s ease-out;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(14px, 2vw, 22px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-close {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); border-color: var(--primary); }
.modal-body { padding: clamp(14px, 2vw, 22px); }
/* 打开模态框时锁住页面滚动，关闭后回到原来的位置 */
body.modal-open { overflow: hidden; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* 通用提示框（替代原生 alert / confirm）：复用 .modal 框架，面板收窄以适配简短文案 */
#app-modal .modal-panel { width: min(440px, 100%); }
#app-modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
#app-modal .modal-message {
  position: relative; margin: 0; padding: 4px 0 4px 30px;
  font-size: 0.95rem; line-height: 1.65; color: var(--text);
}
#app-modal .modal-message[data-kind]::before {
  position: absolute; left: 0; top: 2px; width: 22px; text-align: center;
  font-size: 1.15rem; line-height: 1.4; font-weight: 700;
}
#app-modal .modal-message[data-kind="error"] { color: #dc2626; }
#app-modal .modal-message[data-kind="error"]::before { content: "\26A0"; color: #dc2626; } /* ⚠ */
#app-modal .modal-message[data-kind="ok"]::before { content: "\2713"; color: var(--primary); }   /* ✓ */
#app-modal .modal-message[data-kind="confirm"]::before { content: "\2753"; color: var(--muted); } /* ❓ */
#app-modal .modal-message[data-kind="info"]::before { content: "\2139"; color: var(--primary); }  /* ℹ */
html[data-theme="dark"] #app-modal .modal-message[data-kind="error"],
html[data-theme="dark"] #app-modal .modal-message[data-kind="error"]::before { color: #f87171; }

.visit-detail { display: grid; gap: clamp(12px, 1.6vw, 18px); }
.detail-section h3 { margin: 0 0 8px; font-size: 0.95rem; }
.detail-section dl.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}
.detail-section dt { color: var(--muted); white-space: nowrap; }
.detail-section dd { margin: 0; min-width: 0; }
.detail-note { margin: 6px 0 0; color: var(--muted); font-size: 0.78rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.84em; }
.wrap { word-break: break-all; white-space: pre-wrap; }

.header-list { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.header-row {
  display: grid;
  grid-template-columns: minmax(120px, 32%) minmax(0, 1fr);
  gap: 10px;
  padding: 7px 12px;
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
}
.header-row:first-child { border-top: none; }
.header-row > span:first-child { color: var(--muted); }

/* 移动端：详情面板里的键值改为上下排列，避免长值被挤到看不见 */
@media (max-width: 560px) {
  .detail-section dl.kv, .header-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .detail-section dd { margin-bottom: 8px; }
}

/* 移动端：表格转为卡片，避免横向滚动 */
@media (max-width: 760px) {
  table.admin thead { display: none; }
  table.admin, table.admin tbody, table.admin tr, table.admin td { display: block; width: 100%; }
  table.admin tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    margin-bottom: 10px;
  }
  table.admin tr:hover td { background: none; }
  table.admin td { border: none; padding: 6px 0; }
  table.admin td[data-label]::before {
    content: attr(data-label) "：";
    color: var(--muted);
    font-size: 0.78rem;
    margin-right: 2px;
  }
  table.admin .actions { gap: 16px; padding-top: 2px; }
}

/* ---------- Markdown 编辑器界面 ---------- */
.editor-page { overflow: hidden; background: var(--bg); }
.editor-page .site-header,
.editor-page .site-footer { display: none !important; }
.editor-page main.container {
  display: flex;
  flex-direction: column;
  padding: 0;
  max-width: none;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

/* 顶层容器 */
.editor-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* ===== 工具条 ===== */
.md-toolbar {
  display: flex;
  align-items: center;
  gap: 0;
  height: 44px;
  min-height: 44px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
  user-select: none;
}
.md-toolbar-left,
.md-toolbar-center,
.md-toolbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
.md-toolbar-center { flex: 1 1 auto; justify-content: center; }
.md-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 6px;
  flex: none;
}

/* 工具条按钮 */
.md-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  flex: none;
}
.md-btn:hover { background: var(--surface-alt); color: var(--text); }
.md-btn:active { background: var(--primary-soft); }
.md-btn-icon { width: 30px; padding: 0; }
/* 开关类按钮（如行号）的按下状态 */
.md-btn.active { background: var(--primary-soft); color: var(--primary); }
.md-btn-publish {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  padding: 0 14px;
}
.md-btn-publish:hover { background: var(--primary-dark); color: #fff; }
.md-btn-publish.published { background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); font-weight: 400; }
.md-btn-publish.published:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* ===== 草稿恢复提示条 ===== */
.md-draft {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 8px 12px;
  background: var(--primary-soft);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 0.83rem;
}
.md-draft[hidden] { display: none; }
.md-draft-text { flex: 1 1 auto; }
.md-draft-btn {
  height: 26px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ===== 设置面板 ===== */
.md-settings {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.md-settings:not([hidden]) {
  max-height: min(52vh, 360px);
  overflow-x: hidden;
  overflow-y: auto;
}
.md-settings-inner { padding: 14px 16px; }
.md-set-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-top: 10px; }
.md-set-row:first-child { margin-top: 0; }
.md-set-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
}
.md-set-field-wide { flex: 1 1 200px; }
.md-set-field label { font-size: 0.76rem; color: var(--muted); }
.md-set-field input,
.md-set-field select {
  height: 30px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 0.83rem;
}
.md-set-field input:focus,
.md-set-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.md-cover-row { display: flex; gap: 8px; align-items: center; }
.md-cover-row input { flex: 1 1 auto; }

/* ===== 工作区 ===== */
.md-workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* 编辑/预览面板 */
.md-pane {
  flex: 1 1 50%;
  min-width: 0;
  /* min-height:0 同样不能少：竖排（移动端）时若允许按内容撑开，
     预览面板会把工作区顶破，被 overflow:hidden 裁掉后表现为错位。 */
  min-height: 0;
  overflow: auto;
  background: var(--surface);
  /* 必须是即时滚动：smooth 会让同步滚动写入的 scrollTop 变成动画，
     反过来又触发对方的 scroll 事件，造成来回抖动。 */
  scroll-behavior: auto;
}
.md-src {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  position: relative;
  overflow: hidden;
}

/* 行号列：默认隐藏，由工具条按钮给 .md-src 加上 show-line-nums 打开 */
.md-line-nums {
  display: none;
  flex: none;
  width: 44px;
  min-width: 44px;
  padding: clamp(20px, 3vw, 40px) 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--muted);
  opacity: 0.4;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--border);
  margin-right: 12px;
}
.md-src.show-line-nums .md-line-nums { display: block; }
/* 内层随编辑框滚动位移，保证长行折行后行号依然与正文对齐 */
.md-line-nums-inner { will-change: transform; }
.md-line-nums .ln { white-space: pre; }

/* 隐形测量层：与编辑框同宽同字体，用于量出每一行折行后的真实高度 */
.md-measure {
  position: absolute;
  top: 0;
  left: -9999px;
  visibility: hidden;
  pointer-events: none;
  padding: 0;
  border: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  line-height: 1.8;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* 源码编辑框 */
.md-src textarea {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: auto;
  padding: clamp(20px, 3vw, 40px) clamp(24px, 5vw, 80px);
  border: none;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  line-height: 1.8;
  resize: none;
  outline: none;
  tab-size: 2;
  caret-color: var(--primary);
  align-self: stretch;
}
.md-src textarea::placeholder { color: var(--muted); }

/* 预览区：与编辑区相同的 padding，但最大宽度限制以保证阅读舒适 */
.md-pre { background: var(--bg); }
.md-pre .post-content {
  max-width: 780px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px) clamp(24px, 5vw, 80px);
}

/* 视图模式 */
.md-workspace[data-view="edit-only"] .md-pre { display: none; }
.md-workspace[data-view="edit-only"] .md-src { flex: 1 1 100%; }
.md-workspace[data-view="pre-only"] .md-src { display: none; }
.md-workspace[data-view="pre-only"] .md-pre { flex: 1 1 100%; }
.md-workspace[data-view="pre-only"] .md-pre .post-content { max-width: 900px; }

/* ===== 提示浮层 ===== */
.md-tip {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 18px;
  border-radius: 999px;
  font-size: 0.83rem;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.2s;
}
.md-tip[hidden] { opacity: 0; }
.md-tip.ok   { background: #16a34a; color: #fff; }
.md-tip.err  { background: #dc2626; color: #fff; }

/* ===== 移动端 ===== */
@media (max-width: 640px) {
  .md-toolbar { gap: 0; }
  .md-toolbar-sep { margin: 0 3px; }
  /* 窄屏不再整组隐藏，改为横向滚动，保证排版按钮依然可用。
     min-width:0 是必须的：flex 子项的默认最小尺寸等于内容宽度，
     不置 0 的话按钮组不会收缩，会把工具条整个撑出屏幕。 */
  .md-toolbar-center {
    justify-content: flex-start;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .md-toolbar-center::-webkit-scrollbar { display: none; }
  /* 设置面板竖排：横向布局的两个属性在竖排下语义会变，必须一并改掉——
     1) align-items: flex-end 在竖排时是把字段挤到右侧并按内容宽度收缩，
        改成 stretch 才会撑满整行；
     2) .md-set-field-wide 的 flex: 1 1 200px 在竖排时 200px 变成了「高」，
        每个宽字段被拉成 200px 高，行距看起来就是错位。 */
  .md-set-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .md-set-field,
  .md-set-field-wide { flex: 0 0 auto; width: 100%; min-width: 0; }
  .md-settings-inner { padding: 12px 14px; }
  .md-settings:not([hidden]) { max-height: 62vh; }
  .md-cover-row input { min-width: 0; }
  /* 表单输入同理：字号小于 16px 时 iOS 聚焦会放大整页，看着就像布局错位；
     同时把高度提到 38px 方便手指点按 */
  .md-set-field input,
  .md-set-field select { font-size: 16px; height: 38px; }
  .md-set-field label { font-size: 0.8rem; }
  /* 封面行的按钮与输入框等高，否则看起来一高一低像错位 */
  .md-cover-row .md-btn { height: 38px; }
  .md-workspace { flex-direction: column; }
  .md-src { flex: 1 1 50%; border-right: none; border-bottom: 1px solid var(--border); }
  .md-workspace[data-view="edit-only"] .md-src { flex: 1 1 100%; }
  .md-workspace[data-view="pre-only"] .md-pre { flex: 1 1 100%; }
  .md-btn-publish span { display: none; }
  /* 窄屏把左右留白收窄，尽量多给正文一点宽度 */
  .md-src textarea,
  .md-pre .post-content { padding-left: 14px; padding-right: 14px; }
  /* iOS 会在字号小于 16px 的输入框聚焦时自动放大整页，看起来就像布局错位。
     编辑框、行号列、隐形测量层必须一起改字号，否则行号会与正文错开。 */
  .md-src textarea,
  .md-line-nums,
  .md-measure { font-size: 16px; }
  /* 行号列在窄屏收窄，少占一点正文宽度；宽度仍需容得下 3~4 位行号 */
  .md-line-nums { width: 38px; min-width: 38px; margin-right: 8px; padding-right: 6px; }
  .md-draft { flex-wrap: wrap; row-gap: 6px; }
  .md-draft-text { flex: 1 1 100%; }
  /* viewport-fit=cover 下避开刘海、圆角与底部指示条，
     否则工具条会被状态栏压住、底部面板被指示条盖住。 */
  .editor-shell {
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
  }
  .md-tip { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- 阅读模式 ---------- */
/* 由文章页「阅读模式」按钮切换（body.reading-mode）：只保留标题与正文，
   页头 / 页脚 / 侧栏 / 目录 / 元信息 / 标签 / 评论列表 / 发表评论表单 /
   相关文章 / 上下篇导航全部隐藏；正文铺满整个页面（去掉卡片边框与容器留白）。
   操作按钮容器改为固定右上角，长文中随时可退出；Esc 同效。 */
body.reading-mode .site-header,
body.reading-mode .site-footer,
body.reading-mode .toc-mobile,
body.reading-mode .sidebar,
body.reading-mode .post-header .post-meta,
body.reading-mode .post-header .tag-list,
body.reading-mode .post-nav,
body.reading-mode .related,
body.reading-mode .comments,
body.reading-mode .comment-form-card,
body.reading-mode .reading-progress { display: none; }
body.reading-mode .layout { display: block; }
/* 铺满整页：去掉容器两侧留白与最大宽度限制（.container 自带 padding 与 --maxw） */
body.reading-mode main.container { padding: 0; max-width: none; }
body.reading-mode .post-body {
  min-height: 100vh;
  padding: clamp(20px, 4vw, 56px);
  border: none;
  border-radius: 0;
  box-shadow: none;
}
body.reading-mode .post-content {
  font-size: 1.06rem;
  line-height: 1.85;
}
body.reading-mode .post-header-actions {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 50;
  margin: 0;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

/* ---------- 阅读进度 / 返回顶部 / 灯箱 ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 40;
  background: var(--primary);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

.to-top {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: clamp(14px, 3vw, 28px);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 25;
}
.to-top:hover { border-color: var(--primary); color: var(--primary); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: clamp(12px, 4vw, 48px);
  background: rgba(12, 14, 20, 0.86);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
body.lightbox-open { overflow: hidden; }

/* ---------- 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0 clamp(28px, 5vw, 44px);
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
}
.site-footer p { margin: 2px 0; }

/* 自定义页脚（支持 HTML）：与默认页脚观感保持一致 */
.footer-html { line-height: 1.8; }
.footer-html p { margin: 2px 0; }
.footer-html > *:first-child { margin-top: 0; }
.footer-html > *:last-child { margin-bottom: 0; }
.footer-html a { color: inherit; text-decoration: underline; }
.footer-html a:hover { color: var(--primary); }
.footer-html img { vertical-align: middle; }

/* ---------- 宽屏：适度增加留白，充分利用横向空间 ---------- */
@media (min-width: 1400px) {
  .post-list { gap: 20px; }
  .post-card h2 { font-size: 1.36rem; }
  .post-content { font-size: 1.06rem; }
}

/* ---------- 移动端 ---------- */
@media (max-width: 999px) {
  /* 长文目录改到正文顶部，避免掉到页面最底 */
  .toc-mobile { display: block; }
  .sidebar .toc { display: none; }
}

@media (max-width: 860px) {
  .header-inner { flex-wrap: wrap; gap: 8px 10px; }
  .brand { font-size: 1rem; }
  /* 移动端不放置内联搜索框：改用搜索图标进入搜索页，页眉只保留品牌、账号与主题按钮 */
  .search-form { display: none; }
  .search-link { display: grid; }
  .header-actions { order: 2; flex: 0 0 auto; }
  /* 导航独占一行，横向滚动，避免与品牌挤在一起 */
  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    margin: 0 -2px;
    padding: 2px 2px 4px;
  }
  .nav a { padding: 6px 12px; }
  .nav::-webkit-scrollbar { display: none; }
}

@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .side-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .post-body { padding: 18px 16px; }
  .post-card { padding: 16px; }
  .post-card-cover { width: 104px; margin-left: 12px; }
  .pager { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .pager-group { width: 100%; justify-content: center; flex-wrap: wrap; }
  .pager-jump-group { order: -1; }
  .pager-info { order: -1; width: 100%; text-align: center; }
  .btn { padding: 8px 14px; }
  .archive-list li { flex-wrap: wrap; gap: 4px 10px; }
  .archive-list .date { min-width: 0; }
  .comment-head { gap: 6px; }
  /* 窄屏收窄每层缩进，把正文宽度尽量留给内容 */
  .comment-replies { padding-left: 10px; margin-left: 0; }
  .post-nav { grid-template-columns: minmax(0, 1fr); }
  .post-nav-item.next { text-align: left; }
  .post-nav-item.placeholder { display: none; }
  .related-list li { flex-wrap: wrap; gap: 2px 10px; }
  .code-copy { opacity: 1; }
}

@media print {
  .site-header, .site-footer, .pager, .comments, .toc, .sidebar,
  .toc-mobile, .to-top, .reading-progress, .post-nav, .code-copy { display: none !important; }
  .post-body { border: none; box-shadow: none; padding: 0; }
  .layout { display: block; }
}
