/* ============================================================
   阅读体验增强：进度条 / 返回顶部 / 代码复制 / 灯箱 / 移动端目录
   通过 CSS 变量适配明暗两种主题
   ============================================================ */

:root {
  --enh-surface: #ffffff;
  --enh-surface-2: #f3f5f5;
  --enh-border: #e4e4e4;
  --enh-text: #404040;
  --enh-muted: #a3a3a3;
  --enh-brand: #0085a1;
  --enh-shadow: rgba(0, 0, 0, 0.2);
}
html[data-theme="dark"] {
  --enh-surface: #242628;
  --enh-surface-2: #2c2e30;
  --enh-border: #333638;
  --enh-text: #c9c9c9;
  --enh-muted: #8f9296;
  --enh-brand: #2fa4bd;
  --enh-shadow: rgba(0, 0, 0, 0.6);
}

/* --- 阅读进度条 --- */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--enh-brand);
  z-index: 1080;
  pointer-events: none;
  transition: width 0.1s linear;
}

/* --- 返回顶部 --- */
#back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 42px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  border-radius: 50%;
  background: var(--enh-surface);
  color: var(--enh-text);
  border: 1px solid var(--enh-border);
  box-shadow: 0 2px 8px var(--enh-shadow);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.25s ease;
  z-index: 1060;
  font-size: 18px;
}
#back-to-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
#back-to-top:hover {
  color: var(--enh-brand);
  border-color: var(--enh-brand);
}

/* --- 代码块：语言标签 + 复制按钮 --- */
.code-block {
  position: relative;
}
.code-block .code-lang {
  position: absolute;
  top: 6px;
  right: 52px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #7f8489;
  pointer-events: none;
  user-select: none;
}
.code-block .code-copy {
  position: absolute;
  top: 6px;
  right: 10px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #abb2bf;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.code-block:hover .code-copy {
  opacity: 1;
}
.code-block .code-copy:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
}
.code-block .code-copy.copied {
  color: #98c379;
  border-color: #98c379;
}
/* 无代码块内容时（空 highlight）不显示 */
.code-block.empty .code-copy,
.code-block.empty .code-lang {
  display: none;
}

/* --- 灯箱 --- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.lightbox-overlay.open {
  opacity: 1;
}
.lightbox-overlay img {
  max-width: 94vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  border-radius: 2px;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  transform: scale(0.96);
  transition: transform 0.2s ease;
}
.lightbox-overlay.open img {
  transform: scale(1);
}
.lightbox-overlay .lightbox-close {
  position: absolute;
  top: 14px;
  right: 20px;
  color: #fff;
  font-size: 30px;
  line-height: 1;
  opacity: 0.8;
}

/* --- 相关文章 --- */
.related-posts {
  margin-top: 40px;
  padding-top: 10px;
}
.related-posts h4.section-heading {
  font-size: 20px;
  margin: 20px 0;
  color: var(--enh-muted);
  letter-spacing: 1px;
}
.related-posts ul {
  list-style: none;
  padding-left: 0;
}
.related-posts li {
  padding: 8px 0;
  border-bottom: 1px dashed var(--enh-border);
}
.related-posts li a {
  color: var(--enh-text);
}
.related-posts li a:hover {
  color: var(--enh-brand);
  text-decoration: none;
}
.related-posts .related-date {
  float: right;
  font-size: 13px;
  color: var(--enh-muted);
}

/* --- 移动端目录（<1200px 桌面目录隐藏时） --- */
#mobile-catalog-fab {
  position: fixed;
  right: 24px;
  bottom: 78px;
  width: 42px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  border-radius: 50%;
  background: var(--enh-brand);
  color: #fff;
  box-shadow: 0 2px 10px var(--enh-shadow);
  cursor: pointer;
  z-index: 1060;
  display: none;
  font-size: 16px;
  user-select: none;
}
@media (max-width: 1199px) {
  #mobile-catalog-fab {
    display: block;
  }
  /* 有目录内容才显示按钮 */
  #mobile-catalog-fab.hidden-fab {
    display: none;
  }
}
#mobile-catalog-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(78vw, 320px);
  background: var(--enh-surface);
  box-shadow: -4px 0 16px var(--enh-shadow);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 1500;
  overflow: auto;
  padding: 20px 18px 40px;
}
#mobile-catalog-drawer.open {
  transform: translateX(0);
}
#mobile-catalog-drawer h5 {
  margin: 0 0 12px;
  color: var(--enh-muted);
  letter-spacing: 1px;
}
#mobile-catalog-drawer .catalog-body {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
#mobile-catalog-drawer .catalog-body li a {
  display: block;
  padding: 7px 10px;
  color: var(--enh-text);
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
}
#mobile-catalog-drawer .catalog-body li.h3_nav a {
  padding-left: 22px;
}
#mobile-catalog-drawer .catalog-body li.h4_nav a,
#mobile-catalog-drawer .catalog-body li.h5_nav a,
#mobile-catalog-drawer .catalog-body li.h6_nav a {
  padding-left: 34px;
  font-size: 13px;
}
#mobile-catalog-drawer .catalog-body li a.active {
  color: var(--enh-brand);
  background: var(--enh-surface-2);
}
#mobile-catalog-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1490;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease;
}
#mobile-catalog-mask.open {
  opacity: 1;
  visibility: visible;
}

/* --- 上一/下一篇卡片微调 --- */
.pager li > a > span {
  display: block;
  white-space: normal;
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
  margin-top: 6px;
  color: var(--enh-muted);
}
.pager li > a:hover > span,
.pager li > a:focus > span {
  color: rgba(255, 255, 255, 0.85);
}

/* --- 标题锚点跳转让出固定导航条的高度 --- */
.post-container h1,
.post-container h2,
.post-container h3,
.post-container h4,
.post-container h5,
.post-container h6 {
  scroll-margin-top: 64px;
}

/* --- 轻量 toast（SW 更新提示等） --- */
#hux-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 16px);
  background: #323232;
  color: #fff;
  padding: 10px 18px;
  border-radius: 4px;
  font-size: 14px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2100;
  display: flex;
  align-items: center;
  gap: 12px;
}
#hux-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#hux-toast button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  border-radius: 3px;
  padding: 2px 10px;
  font-size: 13px;
  cursor: pointer;
}
#hux-toast button:hover {
  border-color: #fff;
}
html[data-theme="dark"] #hux-toast {
  background: #2c2e30;
}
