/* ============================================
   reader.css · 5 本电子书共用阅读增强样式
   - 顶部进度条
   - 右上角控制（字号、夜间）
   - 章末"下一章"按钮
   - 目录高亮
   - 夜间模式配色
   ============================================ */

/* 顶部阅读进度条 */
#__reader_progress__ {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: #b03a28;
  z-index: 999;
  transition: width 0.12s ease-out;
  pointer-events: none;
}

/* 右上角控制 panel */
#__reader_ctrl__ {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 4px;
  background: rgba(245, 241, 232, 0.92);
  padding: 4px 6px;
  border: 1px solid #d4c8b0;
  border-radius: 4px;
  z-index: 990;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: "Songti SC", "STSong", "SimSun", serif;
}
/* 不支持 backdrop-filter 的环境（旧 Safari / 低端机）：直接上不透明背景 */
@supports not ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  #__reader_ctrl__ { background: rgba(245, 241, 232, 0.98); }
}
#__reader_ctrl__ button {
  background: transparent;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  color: #2c2620;
  font-family: inherit;
  border-radius: 3px;
  letter-spacing: 1px;
  min-width: 32px;
  transition: all 0.18s;
}
#__reader_ctrl__ button:hover {
  background: rgba(176, 58, 40, 0.1);
  color: #b03a28;
}
#__reader_ctrl__ button[data-action="font-down"] { font-size: 12px; }
#__reader_ctrl__ button[data-action="font-up"]   { font-size: 16px; }
#__reader_ctrl__ button[data-action="theme"]     { font-size: 16px; }

/* 字号通过 CSS var 控制 main 区域字号 */
:root {
  --reader-font-size: 18px;
}
main { font-size: var(--reader-font-size); }

/* 章末"下一章"按钮 */
.__chapter-next__ {
  display: block;
  text-align: right;
  margin: 48px 0 0;
  padding: 18px 24px;
  color: #b03a28;
  text-decoration: none;
  font-size: 15px;
  letter-spacing: 6px;
  border-top: 1px dashed #d4c8b0;
  transition: all 0.22s ease;
  font-family: "Songti SC", "STSong", serif;
}
.__chapter-next__:hover {
  background: rgba(176, 58, 40, 0.05);
  padding-right: 32px;
}

/* 目录智能高亮 */
aside ul li a.__active__ {
  background: rgba(176, 58, 40, 0.10) !important;
  color: #b03a28 !important;
  font-weight: 600;
}

/* ============ 夜间模式 ============ */
body[data-theme="dark"] {
  background: #1a1814 !important;
  background-image: none !important;
  color: #c4b8a0 !important;
}
body[data-theme="dark"] html,
body[data-theme="dark"] {
  background: #1a1814 !important;
}
body[data-theme="dark"] aside {
  background: rgba(36, 30, 24, 0.97) !important;
  border-right-color: #3a3328 !important;
  color: #c4b8a0 !important;
}
body[data-theme="dark"] aside h1,
body[data-theme="dark"] aside .subtitle,
body[data-theme="dark"] aside ul li a {
  color: #c4b8a0 !important;
}
body[data-theme="dark"] aside ul li a:hover {
  background: rgba(176, 58, 40, 0.15) !important;
  color: #d4806a !important;
}
body[data-theme="dark"] aside .toc-section-title,
body[data-theme="dark"] aside .back-home {
  color: #8a8175 !important;
}
body[data-theme="dark"] aside .back-home {
  border-bottom-color: #3a3328 !important;
}

body[data-theme="dark"] .book-title,
body[data-theme="dark"] article.chapter {
  border-bottom-color: #3a3328 !important;
}
body[data-theme="dark"] .book-title h1,
body[data-theme="dark"] .book-title .subtitle-line,
body[data-theme="dark"] .book-title .author,
body[data-theme="dark"] .book-title .cn-subtitle,
body[data-theme="dark"] .book-title .meta {
  color: #d4c8b0 !important;
}
body[data-theme="dark"] article.chapter h2 {
  color: #d4c8b0 !important;
  border-left-color: #c95040 !important;
}
body[data-theme="dark"] article.chapter h3 {
  color: #d4806a !important;
}
body[data-theme="dark"] article.chapter p,
body[data-theme="dark"] article.chapter strong,
body[data-theme="dark"] .text-block p {
  color: #c4b8a0 !important;
}
body[data-theme="dark"] article.chapter p:hover::before {
  color: #6a6358 !important;
}
body[data-theme="dark"] article.chapter hr::after {
  color: #6a6358 !important;
}
body[data-theme="dark"] article.chapter figure img {
  background: #fff;        /* 图片本身保留浅底 */
  border-color: #3a3328 !important;
  opacity: 0.85;
}
body[data-theme="dark"] article.chapter .chapter-num {
  color: #8a8175 !important;
}

body[data-theme="dark"] .cta,
body[data-theme="dark"] .reading-hint,
body[data-theme="dark"] .copyright-note {
  background: rgba(176, 58, 40, 0.08) !important;
  color: #c4b8a0 !important;
}
body[data-theme="dark"] .__chapter-next__ {
  color: #d4806a !important;
  border-top-color: #3a3328 !important;
}
body[data-theme="dark"] .__chapter-next__:hover {
  background: rgba(176, 58, 40, 0.12) !important;
}
body[data-theme="dark"] aside ul li a.__active__ {
  background: rgba(212, 128, 106, 0.18) !important;
  color: #d4806a !important;
}

body[data-theme="dark"] #__reader_progress__ {
  background: #d4806a;
}
body[data-theme="dark"] #__reader_ctrl__ {
  background: rgba(36, 30, 24, 0.95);
  border-color: #3a3328;
}
body[data-theme="dark"] #__reader_ctrl__ button {
  color: #c4b8a0;
}
body[data-theme="dark"] #__reader_ctrl__ button:hover {
  background: rgba(176, 58, 40, 0.2);
  color: #d4806a;
}

/* 移动端调整 */
@media (max-width: 900px) {
  #__reader_ctrl__ {
    top: 8px; right: 8px;
    padding: 2px 4px;
  }
  #__reader_ctrl__ button { padding: 5px 8px; min-width: 28px; }

  /* 目录抽屉：默认收起，点 #__toc_toggle__ 滑出 */
  aside {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 280px !important; max-width: 85vw;
    height: 100vh !important;
    padding: 56px 22px 32px !important;
    border-right: 1px solid var(--border) !important;
    border-bottom: none !important;
    background: rgba(245,241,232,0.98) !important;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 50;
    box-shadow: 4px 0 24px -10px rgba(0,0,0,0.25);
    overflow-y: auto;
  }
  body.__toc-open aside { transform: translateX(0); }
  /* 主内容不再被目录横幅顶下去 */
  main { margin-left: 0 !important; padding: 56px 22px 40px !important; }

  /* 左上角悬浮"目 录"按钮 */
  #__toc_toggle__ {
    position: fixed; top: 8px; left: 8px; z-index: 60;
    background: rgba(245,241,232,0.95);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 5px 12px; font-size: 13px; letter-spacing: 3px;
    color: var(--text); cursor: pointer;
    font-family: inherit; line-height: 1.6;
  }
  #__toc_toggle__:hover { background: var(--bg); }

  /* 抽屉背后的遮罩 */
  #__toc_backdrop__ {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,0.35);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
  }
  body.__toc-open #__toc_backdrop__ { opacity: 1; pointer-events: auto; }
}
/* 桌面端不显示这些移动端控件 */
@media (min-width: 901px) {
  #__toc_toggle__, #__toc_backdrop__ { display: none !important; }
}

/* 暗色模式下的移动端抽屉控件 */
body[data-theme="dark"] #__toc_toggle__ {
  background: rgba(36,30,24,0.95) !important;
  border-color: #3a3328 !important;
  color: #d4cdb8 !important;
}
body[data-theme="dark"] #__toc_toggle__:hover {
  background: rgba(50,42,34,0.95) !important;
}
