/* ==========================================
   base.css — 全局基础样式、CSS 变量、字体
   ========================================== */

/* ---------- 爬虫 / 无 JS 环境：隐藏 Splash 遮罩 ---------- */
/* 搜索引擎和 Wayback Machine 等工具不执行 JS，
   Splash 覆盖层（z-index:10000）会挡住全部内容 */
noscript #splash { display: none !important; }

/* ---------- 置顶徽章 ---------- */
.pinned-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.4;
  color: #2563eb;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.18);
  white-space: nowrap;
  vertical-align: middle;
  margin-left: 6px;
}
/* 暗色模式：手动强制 */
:root[data-theme="dark"] .pinned-badge {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
}
/* 暗色模式：系统偏好（未手动设为 light 时） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pinned-badge {
    color: #60a5fa;
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.25);
  }
}

/* ---------- 文章标签（如：我的推特发文） ---------- */
.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
}
.post-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--color-accent, #2563eb);
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.18);
  white-space: nowrap;
  vertical-align: middle;
}
/* 列表卡片里标题旁的标签，左边距略收紧 */
.article-card-title .post-tag,
.recent-post-title .post-tag,
.archive-item-title .post-tag {
  margin-left: 6px;
  font-size: 0.7rem;
  padding: 1px 8px;
}
:root[data-theme="dark"] .post-tag {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .post-tag {
    color: #60a5fa;
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.25);
  }
}

/* ---------- @font-face：HarmonyOS Sans ---------- */
/* 优先本地字体（华为设备自带），否则回退到 PingFang SC / 微软雅黑 */
@font-face {
  font-family: 'HarmonyOS Sans';
  src: local('HarmonyOS Sans SC'), local('HarmonyOS Sans'),
       local('HarmonyOS Sans SC Regular'), local('HarmonyOS Sans Regular');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'HarmonyOS Sans';
  src: local('HarmonyOS Sans SC Medium'), local('HarmonyOS Sans Medium');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'HarmonyOS Sans';
  src: local('HarmonyOS Sans SC Bold'), local('HarmonyOS Sans Bold');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- CSS 变量（全局配色与尺寸） ---------- */
:root {
  /* 背景：纯白 / 表面色 */
  --color-bg: #FFFFFF;
  --color-surface: #FFFFFF;
  /* 文字：深灰（正文）/ 中灰（辅助信息）/ 近黑（标题） */
  --color-text: #1f2937;
  --color-text-secondary: #6b7280;
  --color-heading: #111827;
  /* 强调色：蓝色系（全站唯一彩色） */
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-accent-cool: #9ca3af;
  /* 边框 / 分割线 */
  --color-border: #e5e7eb;
  /* 代码 / 引用块背景 */
  --color-code-bg: #f3f4f6;
  --color-quote-bg: #f9fafb;
  /* 状态色：错误 / 成功 */
  --color-error: #dc2626;
  --color-success: #16a34a;
  /* 导航玻璃效果参数 */
  --glass-blur: 28px;
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --glass-highlight: rgba(255, 255, 255, 0.6);
  /* 圆角 */
  --radius-nav: 20px;
  --radius-card: 12px;
  /* 最大内容宽度 */
  --max-width: 720px;
  /* 字体 */
  --font-sans: "HarmonyOS Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Menlo,
    Monaco, Consolas, monospace;

}

/* ---------- 暗色模式（系统自动检测） ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #111111;
    --color-surface: #1a1a1a;
    --color-text: #d1d5db;
    --color-text-secondary: #9ca3af;
    --color-heading: #f9fafb;
    --color-accent: #60a5fa;
    --color-accent-hover: #93bbfd;
    --color-accent-cool: #6b7280;
    --color-border: #374151;
    --color-code-bg: #1f2937;
    --color-quote-bg: #1a1a1a;
    --color-error: #f87171;
    --color-success: #4ade80;
    --glass-blur: 28px;
    --glass-bg: rgba(17, 17, 17, 0.85);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.40), 0 1px 4px rgba(0, 0, 0, 0.30);
    --glass-highlight: rgba(255, 255, 255, 0.04);
  }
}

/* ---------- 暗色模式（手动强制） ---------- */
:root[data-theme="dark"] {
  --color-bg: #111111;
  --color-surface: #1a1a1a;
  --color-text: #d1d5db;
  --color-text-secondary: #9ca3af;
  --color-heading: #f9fafb;
  --color-accent: #60a5fa;
  --color-accent-hover: #93bbfd;
  --color-accent-cool: #6b7280;
  --color-border: #374151;
  --color-code-bg: #1f2937;
  --color-quote-bg: #1a1a1a;
  --color-error: #f87171;
  --color-success: #4ade80;
  --glass-blur: 28px;
  --glass-bg: rgba(17, 17, 17, 0.85);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.40), 0 1px 4px rgba(0, 0, 0, 0.30);
  --glass-highlight: rgba(255, 255, 255, 0.04);
}

/* ---------- 暗色模式下全局元素样式调整 ---------- */
/* 合并选择器：当系统偏好暗色 或 手动设置暗色时应用 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .article-card {
    background: var(--color-surface);
    border-color: rgba(255, 255, 255, 0.06);
  }
  :root:not([data-theme="light"]) .article-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
  }
  :root:not([data-theme="light"]) .nav-btn:hover,
  :root:not([data-theme="light"]) .nav-search-btn:hover,
  :root:not([data-theme="light"]) .social-icon:hover {
    background: rgba(255, 255, 255, 0.04);
  }
  :root:not([data-theme="light"]) .nav-btn.active {
    background: rgba(96, 165, 250, 0.12);
    color: var(--color-accent);
  }
  :root:not([data-theme="light"]) .nav-search-wrapper.expanded .nav-search-input {
    background: rgba(255, 255, 255, 0.04);
  }
  :root:not([data-theme="light"]) .search-result-item:hover {
    background: rgba(255, 255, 255, 0.04);
  }
  :root:not([data-theme="light"]) .archive-item:hover,
  :root:not([data-theme="light"]) .recent-post-item:hover {
    background: rgba(255, 255, 255, 0.03);
  }
  :root:not([data-theme="light"]) .recent-post-item {
    border-bottom-color: rgba(255, 255, 255, 0.06);
  }
  :root:not([data-theme="light"]) .archive-year {
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }
  :root:not([data-theme="light"]) .search-empty {
    color: var(--color-text-secondary);
  }
  :root:not([data-theme="light"]) ::-webkit-scrollbar-thumb {
    background: #555;
  }
  :root:not([data-theme="light"]) ::-webkit-scrollbar-track {
    background: transparent;
  }
  :root:not([data-theme="light"]) ::selection {
    color: #111111;
    background: var(--color-accent);
  }
  /* 暗色模式：社交图标提亮 */
  :root:not([data-theme="light"]) .social-icon img {
    filter: brightness(0) invert(1);
    opacity: 0.75;
  }
  :root:not([data-theme="light"]) .social-icon:hover img {
    opacity: 1;
  }
}

/* 手动暗色模式下的同样样式 */
:root[data-theme="dark"] .social-icon img {
  filter: brightness(0) invert(1);
  opacity: 0.75;
}
:root[data-theme="dark"] .social-icon:hover img {
  opacity: 1;
}
:root[data-theme="dark"] .article-card {
  background: var(--color-surface);
  border-color: rgba(255, 255, 255, 0.06);
}
:root[data-theme="dark"] .article-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
}
:root[data-theme="dark"] .nav-btn:hover,
:root[data-theme="dark"] .nav-search-btn:hover,
:root[data-theme="dark"] .social-icon:hover {
  background: rgba(255, 255, 255, 0.04);
}
:root[data-theme="dark"] .nav-btn.active {
  background: rgba(96, 165, 250, 0.12);
  color: var(--color-accent);
}
:root[data-theme="dark"] .nav-search-wrapper.expanded .nav-search-input {
  background: rgba(255, 255, 255, 0.04);
}
:root[data-theme="dark"] .search-result-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
:root[data-theme="dark"] .archive-item:hover,
:root[data-theme="dark"] .recent-post-item:hover {
  background: rgba(255, 255, 255, 0.03);
}
:root[data-theme="dark"] .recent-post-item {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}
:root[data-theme="dark"] .archive-year {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
:root[data-theme="dark"] .search-empty {
  color: var(--color-text-secondary);
}
:root[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #555;
}
:root[data-theme="dark"] ::-webkit-scrollbar-track {
  background: transparent;
}
:root[data-theme="dark"] ::selection {
  color: #1A1A1C;
  background: var(--color-accent);
}

/* ---------- 全局重置 ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ---------- 无障碍：跳过导航链接 ---------- */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 9999;
  padding: 10px 20px;
  background: var(--color-text);
  color: var(--color-bg);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 16px;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 为固定导航栏预留滚动空间，锚点跳转时标题不被遮挡 */
  scroll-padding-top: 100px;
  /* 防止 100vw / 宽内容导致整页横向滚动 */
  overflow-x: clip;
}

body {
  font-family: var(--font-sans);
  font-weight: 400;
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: 1.8;
  min-height: 100vh;
  min-height: 100dvh;
  /* 为固定导航预留空间 */
  padding-top: 90px;
  padding-bottom: 80px;
  /* 刘海屏 / Home 指示条安全区 */
  padding-top: calc(90px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  /* 去掉移动端点击高亮蓝框 */
  -webkit-tap-highlight-color: transparent;
  /* 长文换行更稳，避免英文/URL 撑破布局 */
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ---------- 链接 ---------- */
a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

/* ---------- 加粗文字：蓝色强调 ---------- */
strong, b {
  color: var(--color-accent);
  font-weight: 700;
}

/* ---------- 标题 ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.35;
  color: var(--color-text);
  /* 锚点跳转时留出固定导航栏的空间，防止标题被遮挡 */
  scroll-margin-top: 100px;
}

/* h2 加粗到 700：极简风格下建立清晰的视觉层次 */
h2 { font-weight: 700; }
h3 { font-weight: 600; }

/* ---------- 段落 ---------- */
p {
  margin-bottom: 1rem;
}

/* ---------- 图片 ---------- */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ---------- 表格横向滚动容器（手机端防撑破） ---------- */
.table-scroll {
  width: 100%;
  margin: 24px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  /* 提示可横向滑动 */
  overscroll-behavior-x: contain;
}

.table-scroll table {
  margin: 0;
  min-width: 480px;
}

/* ---------- 表格（全局增强） ---------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 24px 0;
  font-size: 0.95rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(128, 128, 128, 0.2);
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(128, 128, 128, 0.12);
}

/* 表头高亮 */
thead th {
  background: rgba(128, 128, 128, 0.08);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text);
  border-bottom: 2px solid rgba(128, 128, 128, 0.2);
}

/* 斑马纹：隔行变色 */
tbody tr:nth-child(even) {
  background: rgba(128, 128, 128, 0.03);
}

tbody tr:hover {
  background: rgba(128, 128, 128, 0.06);
}

/* 最后一行无底部边框 */
tbody tr:last-child td {
  border-bottom: none;
}

/* 暗色模式表格适配 */
:root[data-theme="dark"] table {
  border-color: rgba(255, 255, 255, 0.08);
}
:root[data-theme="dark"] th,
:root[data-theme="dark"] td {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}
:root[data-theme="dark"] thead th {
  background: rgba(255, 255, 255, 0.04);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}
:root[data-theme="dark"] tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
:root[data-theme="dark"] tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) table {
    border-color: rgba(255, 255, 255, 0.08);
  }
  :root:not([data-theme="light"]) th,
  :root:not([data-theme="light"]) td {
    border-bottom-color: rgba(255, 255, 255, 0.06);
  }
  :root:not([data-theme="light"]) thead th {
    background: rgba(255, 255, 255, 0.04);
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }
  :root:not([data-theme="light"]) tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
  }
  :root:not([data-theme="light"]) tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
  }
}

/* ---------- 选中文字样式 ---------- */
::selection {
  background: var(--color-accent);
  color: var(--color-surface);
}

/* ---------- 滚动条（Webkit） ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-accent-cool);
  border-radius: 3px;
}

/* ========== 动效关键帧 ========== */

/* 淡入上浮 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 纯淡入 */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* 轻微上浮（页面容器入场） */
@keyframes contentEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 背景光斑缓慢漂移 */
@keyframes ambientFloat {
  0%   { transform: translate(0, 0) scale(1); }
  33%  { transform: translate(40px, -20px) scale(1.08); }
  66%  { transform: translate(-20px, 30px) scale(0.94); }
  100% { transform: translate(0, 0) scale(1); }
}

/* 导航栏入场 */
@keyframes navSlideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* 脉冲提示（搜索图标等） */
@keyframes subtlePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

/* ---------- 页面容器入场动画 ---------- */
.page-container {
  animation: contentEnter 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

/* ---------- 文章卡片交错入场 ---------- */
.article-list .article-card {
  opacity: 0;
  animation: fadeInUp 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.article-list .article-card:nth-child(1)  { animation-delay: 0.05s; }
.article-list .article-card:nth-child(2)  { animation-delay: 0.1s;  }
.article-list .article-card:nth-child(3)  { animation-delay: 0.15s; }
.article-list .article-card:nth-child(4)  { animation-delay: 0.2s;  }
.article-list .article-card:nth-child(5)  { animation-delay: 0.25s; }
.article-list .article-card:nth-child(6)  { animation-delay: 0.3s;  }
.article-list .article-card:nth-child(7)  { animation-delay: 0.35s; }
.article-list .article-card:nth-child(8)  { animation-delay: 0.4s;  }
.article-list .article-card:nth-child(9)  { animation-delay: 0.45s; }
.article-list .article-card:nth-child(10) { animation-delay: 0.5s;  }

/* 最近文章项入场 */
.recent-post-item {
  opacity: 0;
  animation: fadeInUp 0.4s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.recent-post-item:nth-child(1) { animation-delay: 0.05s; }
.recent-post-item:nth-child(2) { animation-delay: 0.12s; }
.recent-post-item:nth-child(3) { animation-delay: 0.19s; }
.recent-post-item:nth-child(4) { animation-delay: 0.26s; }
.recent-post-item:nth-child(5) { animation-delay: 0.33s; }

/* 归档项入场 */
.archive-item {
  opacity: 0;
  animation: fadeInUp 0.4s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}
.archive-item:nth-child(1)  { animation-delay: 0.04s; }
.archive-item:nth-child(2)  { animation-delay: 0.08s; }
.archive-item:nth-child(3)  { animation-delay: 0.12s; }
.archive-item:nth-child(4)  { animation-delay: 0.16s; }
.archive-item:nth-child(5)  { animation-delay: 0.20s; }
.archive-item:nth-child(6)  { animation-delay: 0.24s; }
.archive-item:nth-child(7)  { animation-delay: 0.28s; }
.archive-item:nth-child(8)  { animation-delay: 0.32s; }
.archive-item:nth-child(9)  { animation-delay: 0.36s; }
.archive-item:nth-child(10) { animation-delay: 0.40s; }

/* ========== 代码块增强样式（全局） ========== */
.code-block-wrapper {
  position: relative;
  margin: 20px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: #1E1E1E;
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-lang-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #9A9A9A;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-mono);
}
.code-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-family: var(--font-sans);
  color: #9A9A9A;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.code-copy-btn:hover {
  color: #E6E6E6;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}
.code-copy-btn.copied {
  color: #4CAF50;
  border-color: rgba(76, 175, 80, 0.4);
}
.code-block-wrapper pre {
  margin: 0;
  padding: 16px 20px;
  overflow-x: auto;
  background: transparent;
  border: none;
  border-radius: 0;
}
.code-block-wrapper pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 0.88rem;
  line-height: 1.65;
  color: #D4D4D4;
  font-family: var(--font-mono);
}
/* 语法高亮颜色 */
.syn-kw { color: #569CD6; }   /* 关键字 */
.syn-str { color: #CE9178; }  /* 字符串 */
.syn-cmt { color: #6A9955; font-style: italic; } /* 注释 */
.syn-num { color: #B5CEA8; }  /* 数字 */
.syn-fn { color: #DCDCAA; }   /* 函数名 */
.syn-prop { color: #9CDCFE; } /* 属性 */
.syn-type { color: #4EC9B0; } /* 类型 */

/* ========== TOC 目录样式（文章页使用） ========== */
.toc-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: block;
}
.toc-sticky {
  position: sticky;
  top: 110px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  padding-left: 16px;
  border-left: 2px solid rgba(0, 0, 0, 0.08);
}
.toc-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-list li { margin-bottom: 4px; }
.toc-list a {
  display: block;
  padding: 4px 0;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.2s ease, padding-left 0.2s ease;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-list a:hover,
.toc-list a.toc-active {
  color: var(--color-accent);
  padding-left: 6px;
}
.toc-h3 a {
  padding-left: 16px;
  font-size: 0.8rem;
}
.toc-h3 a:hover,
.toc-h3 a.toc-active {
  padding-left: 20px;
}

/* 暗色模式 TOC 边框 */
:root[data-theme="dark"] .toc-sticky {
  border-left-color: rgba(255, 255, 255, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toc-sticky {
    border-left-color: rgba(255, 255, 255, 0.08);
  }
}

/* 移动端 TOC：横向胶囊滑动 */
@media (max-width: 960px) {
  .toc-sidebar { width: 100%; margin-bottom: 20px; }
  .toc-sticky {
    position: static;
    max-height: none;
    border-left: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    padding: 0 0 12px;
  }
  .toc-list {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 6px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .toc-list::-webkit-scrollbar { display: none; }
  .toc-list li {
    margin-bottom: 0;
    flex: 0 0 auto;
    scroll-snap-align: start;
  }
  .toc-list a {
    padding: 7px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 999px;
    font-size: 0.8rem;
    white-space: nowrap;
    /* 触控热区更易点 */
    min-height: 34px;
    display: flex;
    align-items: center;
  }
  .toc-list a:hover,
  .toc-list a.toc-active {
    padding-left: 12px;
    background: rgba(37, 99, 235, 0.1);
  }
  .toc-h3 a { padding-left: 12px; font-size: 0.76rem; }
  .toc-h3 a:hover,
  .toc-h3 a.toc-active { padding-left: 12px; }
}

/* ---------- 阅读进度条（文章页顶部细线） ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1100;
  height: 2px;
  width: 0;
  background: var(--color-accent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.reading-progress.visible {
  opacity: 1;
}

/* ---------- 回到顶部按钮（长文/手机端） ---------- */
.back-to-top {
  position: fixed;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 900;
  width: 42px;
  height: 42px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  color: var(--color-accent);
  border-color: rgba(37, 99, 235, 0.35);
}

.back-to-top:active {
  transform: scale(0.94);
}

.back-to-top svg {
  width: 18px;
  height: 18px;
}

/* 减少动画偏好适配 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
