/* =========================================================
 * 小说库 — 阅读样式
 * 设计目标:长时间阅读不疲劳,移动端友好
 * ========================================================= */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f6f1e7;            /* 米黄纸色 */
  --bg-card: #fbf7ee;
  --fg: #2b2b2b;
  --fg-muted: #6b6b6b;
  --fg-soft: #888;
  --border: #d9cfb9;
  --accent: #8b3a1f;        /* 朱砂红 */
  --accent-hover: #a64a2c;
  --link: #5d3a1f;
  --topbar-bg: rgba(246, 241, 231, 0.92);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --content-max: 720px;
  --serif:
    "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "SimSun",
    "STSong", "Hiragino Mincho ProN", "Times New Roman", serif;
  --sans:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #1a1614;
  --bg-card: #221d1a;
  --fg: #d9d2c5;
  --fg-muted: #9b948a;
  --fg-soft: #6e685f;
  --border: #3a342e;
  --accent: #c87a4f;
  --accent-hover: #d99269;
  --link: #c87a4f;
  --topbar-bg: rgba(26, 22, 20, 0.94);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.85;
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ---------- Top bar (shared across pages) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 14px;
}

.topbar a {
  color: var(--fg-muted);
}
.topbar a:hover {
  color: var(--accent);
  text-decoration: none;
}

.topbar .progress {
  color: var(--fg-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- Chapter page ---------- */
.chapter-page {
  padding-bottom: 80px;
}

.chapter-page article {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 24px 16px;
}

.chapter-page h1 {
  font-size: 1.6em;
  text-align: center;
  margin: 24px 0 32px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.02em;
}

.chapter-page .content {
  font-size: 1.05em;
  text-align: justify;
  text-justify: inter-ideograph;
  /* 段首两字符缩进 */
}

.chapter-page .content p {
  margin: 0 0 1.2em;
  text-indent: 2em;
  white-space: pre-wrap;
}

/* ---------- Chapter nav (prev / toc / next) ---------- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: var(--content-max);
  margin: 48px auto 0;
  padding: 16px 24px;
  font-family: var(--sans);
  font-size: 14px;
}

.chapter-nav a {
  flex: 1;
  padding: 10px 16px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--fg);
  transition: all 0.15s;
}

.chapter-nav a:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  text-decoration: none;
}

.chapter-nav a:first-child { text-align: left; }
.chapter-nav a:last-child  { text-align: right; }

/* ---------- Novel page (chapter list) ---------- */
.novel-page {
  padding-bottom: 80px;
}

.novel-info {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 24px 24px;
  text-align: center;
}

.novel-info h1 {
  font-size: 2.4em;
  margin: 0 0 12px;
  color: var(--accent);
  font-weight: 600;
}

.novel-info .meta {
  color: var(--fg-muted);
  font-family: var(--sans);
  font-size: 14px;
  margin: 0 0 24px;
}

.novel-info .meta span {
  margin: 0 12px;
  white-space: nowrap;
}

.novel-info .description {
  text-align: left;
  text-indent: 2em;
  font-size: 1em;
  line-height: 1.9;
  color: var(--fg-muted);
  margin: 0 0 28px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
}

.btn-primary {
  display: inline-block;
  padding: 10px 28px;
  background: var(--accent);
  color: #fff !important;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

/* ---------- Table of contents ---------- */
.toc {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px 24px;
}

.toc h2 {
  font-size: 1.3em;
  margin: 32px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.toc h2 .toc-meta {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-soft);
}

.chapter-search {
  display: block;
  width: 100%;
  margin: 12px 0 16px;
  padding: 10px 14px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--fg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}
.chapter-search:focus {
  border-color: var(--accent);
}
.chapter-search::placeholder {
  color: var(--fg-soft);
}

.no-results {
  font-family: var(--sans);
  text-align: center;
  color: var(--fg-muted);
  padding: 24px;
  margin: 0;
}

.chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  /* Compact 2-column on wide screens */
  columns: 1;
}

@media (min-width: 640px) {
  .chapter-list {
    columns: 2;
    column-gap: 16px;
  }
}

.chapter-list li {
  break-inside: avoid;
  margin: 0;
  padding: 0;
}

.chapter-list a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px dashed transparent;
  color: var(--fg);
  transition: all 0.15s;
}

.chapter-list a:hover {
  background: var(--bg-card);
  border-bottom-color: var(--border);
  text-decoration: none;
  color: var(--accent);
}

.chapter-list .num {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--fg-soft);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  flex-shrink: 0;
}

.chapter-list .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Library (xiaoshuo index) ---------- */
.library-page {
  padding-bottom: 80px;
}

.library-header {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 48px 24px 24px;
  text-align: center;
}

.library-header h1 {
  font-size: 2.4em;
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 600;
}

.library-header p {
  color: var(--fg-muted);
  font-family: var(--sans);
  font-size: 14px;
  margin: 0;
}

.novel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 16px 24px;
}

@media (min-width: 640px) {
  .novel-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.novel-card {
  display: flex;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  transition: all 0.15s;
}

.novel-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.novel-card .cover {
  width: 64px;
  height: 88px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  line-height: 1.1;
}

.novel-card .info {
  flex: 1;
  min-width: 0;
}

.novel-card .title {
  font-size: 1.15em;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--fg);
}

.novel-card .author {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--fg-muted);
  margin: 0 0 8px;
}

.novel-card .stats {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--fg-soft);
  margin: 0;
}

.novel-card .stats span {
  margin-right: 10px;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 20;
  font-family: var(--sans);
  transition: transform 0.15s;
}
.theme-toggle:hover {
  transform: scale(1.08);
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 480px) {
  body { font-size: 17px; }
  .chapter-page h1 { font-size: 1.4em; }
  .novel-info h1 { font-size: 2em; }
  .library-header h1 { font-size: 2em; }
  .topbar { padding: 10px 14px; font-size: 13px; }
  .chapter-page article { padding: 24px 18px 8px; }
  .toc { padding: 8px 18px; }
  .chapter-nav { padding: 16px 18px; }
  .novel-card { padding: 14px; }
  .novel-card .cover { width: 56px; height: 76px; font-size: 20px; }
}