/* ==========================================================================
 * 深夜怪谈档案馆 · 统一小说阅读器样式 (reader.css)
 * 支持「深夜暗档」(默认) / 「泛黄纸书」双主题 + 三档字号 + 双视口零溢出
 * ========================================================================== */

:root {
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --reader-max: 760px;
  --prose-size: 17px;
}

html[data-theme="dark"] {
  --bg-page: #0c0f13;
  --bg-card: #141920;
  --bg-topbar: rgba(12, 15, 19, 0.92);
  --bg-quote: rgba(217, 184, 124, 0.06);
  --bg-footnote: rgba(78, 201, 176, 0.06);
  --bg-btn: rgba(255, 255, 255, 0.05);
  --bg-btn-hover: rgba(255, 255, 255, 0.11);

  --border-subtle: rgba(217, 184, 124, 0.16);
  --border-strong: rgba(217, 184, 124, 0.36);
  --border-teal: rgba(78, 201, 176, 0.34);

  --text-primary: #e4ded1;
  --text-prose: #dcd5c7;
  --text-secondary: #a8a095;
  --text-muted: #787269;
  --accent: #d9b87c;
  --accent-contrast: #16120b;
  --accent-alt: #4ec9b0;
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, 0.45);
}

html[data-theme="paper"] {
  --bg-page: #efe6d2;
  --bg-card: #f7f0df;
  --bg-topbar: rgba(239, 230, 210, 0.94);
  --bg-quote: rgba(125, 90, 45, 0.08);
  --bg-footnote: rgba(45, 95, 84, 0.07);
  --bg-btn: rgba(36, 30, 24, 0.05);
  --bg-btn-hover: rgba(36, 30, 24, 0.11);

  --border-subtle: rgba(105, 78, 46, 0.18);
  --border-strong: rgba(105, 78, 46, 0.38);
  --border-teal: rgba(45, 95, 84, 0.32);

  --text-primary: #211b15;
  --text-prose: #2a221a;
  --text-secondary: #5c4f41;
  --text-muted: #7b6c5c;
  --accent: #7a5223;
  --accent-contrast: #fbf6eb;
  --accent-alt: #286255;
  --shadow-soft: 0 10px 26px rgba(64, 47, 25, 0.12);
}

html[data-font-size="sm"] {
  --prose-size: 15px;
}

html[data-font-size="md"] {
  --prose-size: 17px;
}

html[data-font-size="lg"] {
  --prose-size: 19.5px;
}

@media (min-width: 768px) {
  html[data-font-size="sm"] {
    --prose-size: 15.5px;
  }
  html[data-font-size="md"] {
    --prose-size: 18px;
  }
  html[data-font-size="lg"] {
    --prose-size: 20.5px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-text-size-adjust: 100%;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  overflow-x: clip;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

/* Sticky Compact Single-Line Topbar */
.reader-topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--bg-topbar);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.reader-topbar-inner {
  max-width: 1060px;
  margin: 0 auto;
  height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

@media (min-width: 768px) {
  .reader-topbar-inner {
    padding: 0 24px;
    gap: 12px;
  }
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .topbar-left,
  .topbar-right {
    gap: 8px;
  }
}

.topbar-center {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 768px) {
  .topbar-center {
    display: block;
  }
}

.label-full {
  display: none;
}

.label-short {
  display: inline;
}

@media (min-width: 768px) {
  .label-full {
    display: inline;
  }
  .label-short {
    display: none;
  }
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-btn);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.tool-btn:hover,
.tool-btn:focus-visible {
  background: var(--bg-btn-hover);
  border-color: var(--border-strong);
  outline: none;
}

.tool-btn-back {
  color: var(--accent);
}

.font-size-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-btn);
}

.size-btn {
  height: 30px;
  min-width: 28px;
  padding: 0 6px;
  border: 0;
  border-right: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.size-btn:last-child {
  border-right: 0;
}

.size-btn.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
}

@media (min-width: 768px) {
  .tool-btn {
    padding: 0 12px;
    font-size: 12.5px;
  }
  .size-btn {
    min-width: 34px;
    padding: 0 9px;
    font-size: 12px;
  }
}

.read-progress-track {
  height: 2px;
  width: 100%;
  background: transparent;
}

.read-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-alt), var(--accent));
  transition: width 0.12s linear;
}

/* Main Reader Container */
.reader-main {
  padding: 20px 14px 56px;
}

@media (min-width: 768px) {
  .reader-main {
    padding: 32px 24px 72px;
  }
}

.reader-article {
  max-width: var(--reader-max);
  margin: 0 auto;
}

/* Book Header Card */
.book-header-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

@media (min-width: 640px) {
  .book-header-card {
    flex-direction: row;
    align-items: center;
    gap: 18px;
    padding: 18px 20px;
  }
}

.book-cover-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
}

@media (min-width: 640px) {
  .book-cover-thumb {
    width: 210px;
    flex-shrink: 0;
  }
}

.book-header-meta {
  min-width: 0;
  flex: 1 1 auto;
}

.book-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.book-tag {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg-btn);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.book-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: clamp(19px, 3vw, 24px);
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}

.book-subtitle {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--accent);
}

.book-info-line {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.book-blurb {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* Chapter Content */
.chapter-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 22px 18px 26px;
  box-shadow: var(--shadow-soft);
}

@media (min-width: 768px) {
  .chapter-container {
    padding: 36px 44px 40px;
  }
}

.chapter-eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--accent-alt);
}

.chapter-title {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-size: clamp(20px, 3.2vw, 26px);
  font-weight: 700;
  line-height: 1.38;
  color: var(--text-primary);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.chapter-epigraph {
  margin: 0 0 24px;
  padding: 12px 15px;
  border-left: 3px solid var(--accent);
  background: var(--bg-quote);
  border-radius: 0 8px 8px 0;
  font-family: var(--font-serif);
  font-size: calc(var(--prose-size) * 0.88);
  line-height: 1.75;
  color: var(--text-secondary);
  white-space: pre-line;
}

.chapter-prose {
  font-family: var(--font-serif);
  font-size: var(--prose-size);
  line-height: 1.85;
  color: var(--text-prose);
}

.chapter-prose p {
  margin: 0 0 1.05em;
  text-indent: 2em;
  text-align: justify;
  word-break: break-word;
}

.chapter-prose p.is-divider {
  text-indent: 0;
  text-align: center;
  letter-spacing: 0.4em;
  color: var(--text-muted);
  margin: 1.4em 0;
}

.chapter-prose p.is-log-line {
  text-indent: 0;
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 8px 12px;
  border-left: 2px solid var(--border-teal);
  background: var(--bg-footnote);
  border-radius: 4px;
}

.chapter-footnote {
  margin-top: 26px;
  padding: 13px 15px;
  border-radius: 8px;
  border: 1px solid var(--border-teal);
  background: var(--bg-footnote);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.chapter-footnote-label {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-alt);
}

/* Archival Illustration */
.novel-illustration {
  margin: 26px 0 6px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-page);
}

.novel-illustration img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
}

.novel-illustration figcaption {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.illustration-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
}

/* Bottom Chapter Pager */
.chapter-pager {
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.pager-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pager-btn:hover:not(:disabled) {
  background: var(--bg-btn-hover);
  border-color: var(--border-strong);
}

.pager-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.pager-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.pager-btn-primary:hover:not(:disabled) {
  opacity: 0.92;
  background: var(--accent);
}

.pager-status {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}

/* Slide-over Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.reader-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 90;
  width: min(360px, 88vw);
  background: var(--bg-card);
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.5);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
}

.drawer-close {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-btn);
  color: var(--text-primary);
  font-size: 15px;
}

.drawer-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-tab {
  height: 40px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

.drawer-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-quote);
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
}

.drawer-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.drawer-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.drawer-item:hover {
  border-color: var(--border-strong);
}

.drawer-item.is-active {
  border-color: var(--accent);
  background: var(--bg-quote);
}

.drawer-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.drawer-item-title {
  font-family: var(--font-serif);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
}

.drawer-ill-pill {
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-teal);
  color: var(--accent-alt);
  font-size: 10px;
}

.loading-state {
  color: var(--text-secondary);
  text-align: center;
  padding: 40px 0;
}
