/* ============================================================
   OurStory · 阅读前台
   三主题（护眼 / 明亮 / 暗夜）+ 三档字号，全部由 CSS 变量驱动
   ============================================================ */

:root {
  color-scheme: light dark;

  /* —— 护眼（默认）—— */
  --bg: #f3ead4;
  --bg-grad: radial-gradient(130% 80% at 50% 0%, rgba(255, 255, 255, .5), transparent 60%);
  --surface: #fbf5e3;
  --surface-2: #f6eed6;
  --ink: #3b342a;
  --ink-soft: #6a604d;
  --muted: #9a8f76;
  --line: #e2d6b8;
  --line-soft: #ece2c8;
  --accent: #9a6b2f;
  --accent-ink: #7c5320;
  --accent-soft: rgba(154, 107, 47, .1);
  --selection: rgba(154, 107, 47, .2);
  --code-bg: rgba(0, 0, 0, .05);

  --font-size: 18px;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "STSong", "SimSun", serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Consolas, monospace;

  --radius: 10px;
  --reader-width: 720px;
  --sidebar-w: 300px;
  --toolbar-h: 56px;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-grad: radial-gradient(130% 80% at 50% 0%, #ffffff, transparent 60%);
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #23272e;
  --ink-soft: #555d6b;
  --muted: #8b94a3;
  --line: #e4e8ee;
  --line-soft: #eef1f5;
  --accent: #2f6b5f;
  --accent-ink: #245449;
  --accent-soft: rgba(47, 107, 95, .08);
  --selection: rgba(47, 107, 95, .16);
  --code-bg: rgba(15, 23, 42, .04);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16171b;
  --bg-grad: radial-gradient(130% 80% at 50% 0%, rgba(40, 42, 48, .6), transparent 60%);
  --surface: #1f2025;
  --surface-2: #26272d;
  --ink: #d8d4c8;
  --ink-soft: #a39d8e;
  --muted: #6c675d;
  --line: #31323a;
  --line-soft: #2a2b31;
  --accent: #c9a86a;
  --accent-ink: #d9bb7e;
  --accent-soft: rgba(201, 168, 106, .1);
  --selection: rgba(201, 168, 106, .2);
  --code-bg: rgba(255, 255, 255, .06);
}

[data-font="small"]  { --font-size: 16px; }
[data-font="medium"] { --font-size: 18px; }
[data-font="large"]  { --font-size: 20px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}

::selection { background: var(--selection); }

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

/* —— 顶部阅读进度条 —— */
.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 100;
  pointer-events: none;
  background: transparent;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  transition: width .1s linear;
}

/* —— 主布局 —— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* —— 侧栏 —— */
.library-panel {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  z-index: 50;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
}
.brand-name { font-weight: 700; letter-spacing: .02em; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.panel-close { display: none; }

.section-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.section-block.grow { flex: 1; min-height: 0; }
.section-title {
  margin: 0 0 4px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--muted);
}

.novel-list,
.chapter-tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  margin: 0 -6px;
  padding: 0 6px;
  overflow-y: auto;
}
.novel-list { gap: 8px; }

.novel-list::-webkit-scrollbar,
.chapter-tree::-webkit-scrollbar { width: 6px; }
.novel-list::-webkit-scrollbar-thumb,
.chapter-tree::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

/* —— 小说项 —— */
.novel-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 12px;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.novel-item:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}
.novel-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.novel-item-title { display: block; font-weight: 700; font-size: 14px; }
.novel-item-meta { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }

/* —— 卷组 —— */
.volume-group {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: transparent;
}
.volume-group + .volume-group { margin-top: 8px; }
.volume-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
}
.volume-title span:last-child {
  color: var(--muted);
  font-weight: 500;
}

.chapter-row {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.chapter-row + .chapter-row { border-top: 1px solid var(--line-soft); }
.chapter-row:hover { background: var(--surface-2); color: var(--ink); }
.chapter-row.active {
  color: var(--accent-ink);
  background: var(--accent-soft);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

/* —— 阅读区 —— */
.reader-shell { min-width: 0; }

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  height: var(--toolbar-h);
  padding: 0 20px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.catalog-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 0 10px;
  font-size: 13px;
}
.catalog-toggle .label { font-size: 13px; }

.reader-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-group {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}
.tool-btn {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tool-btn:hover { color: var(--ink); }
.tool-btn.active {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* —— 书 / 正文容器 —— */
.book {
  max-width: var(--reader-width);
  margin: 0 auto;
  padding: 48px 28px 80px;
}

.book-header {
  margin-bottom: 40px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line-soft);
  text-align: center;
}
.eyebrow {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .18em;
  color: var(--accent);
  text-transform: uppercase;
}
.book-header h1 {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.3;
}
.book-subtitle {
  margin: 0 auto;
  max-width: 540px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}
.book-stats {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .04em;
}

/* —— 章节头部 —— */
.chapter-header { margin-bottom: 32px; }
.chapter-volume {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--accent);
}
.chapter-header h2 {
  margin: 0 0 16px;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: .02em;
}
.chapter-summary {
  margin: 0 0 12px;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink-soft);
}
.word-count {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* —— 正文 —— */
.chapter-body {
  font-family: var(--font-serif);
  font-size: var(--font-size);
  line-height: 1.9;
  color: var(--ink);
  letter-spacing: .02em;
  word-break: break-word;
}
.chapter-body p {
  margin: 0 0 1.05em;
  text-indent: 2em;
}
.chapter-body h2,
.chapter-body h3 {
  margin: 1.6em 0 .8em;
  font-family: var(--font-ui);
  text-indent: 0;
}
.chapter-body h2 { font-size: 1.2em; }
.chapter-body h3 { font-size: 1.08em; }
.chapter-body blockquote {
  margin: 1.4em 0;
  padding: 10px 18px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 6px 6px 0;
  color: var(--ink-soft);
  font-size: .94em;
  text-indent: 0;
}
.chapter-body pre {
  margin: 1.4em 0;
  padding: 14px 16px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow-x: auto;
  font-size: .88em;
  line-height: 1.6;
  text-indent: 0;
}
.chapter-body pre code {
  font-family: var(--font-mono);
  color: var(--ink-soft);
}
.chapter-body ul {
  margin: 1.2em 0;
  padding-left: 1.6em;
  text-indent: 0;
}
.chapter-body li {
  margin: .3em 0;
  line-height: 1.8;
}
.chapter-body strong {
  font-weight: 700;
}
.chapter-body hr {
  width: 80px;
  margin: 2.2em auto;
  border: 0;
}
.chapter-body hr::before {
  content: "❖";
  color: var(--muted);
  font-size: 14px;
}

.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
  text-indent: 0;
}

/* —— 章节导航 —— */
.chapter-nav {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--line-soft);
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  max-width: 200px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, transform .08s;
}
.nav-btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}
.nav-btn:active { transform: scale(.98); }
.nav-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.nav-btn:disabled:hover {
  border-color: var(--line);
  color: var(--ink);
}
.nav-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.nav-btn-primary:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: #fff;
}

/* —— 移动端抽屉遮罩 —— */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
  z-index: 45;
}
body.nav-open .scrim {
  opacity: 1;
  visibility: visible;
}

/* —— 响应式 —— */
@media (max-width: 960px) {
  :root { --sidebar-w: 264px; }
  .reader-tools { gap: 6px; }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }

  .reader-toolbar { justify-content: space-between; }
  .catalog-toggle { display: inline-flex; }

  .library-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .28s var(--ease);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .14);
  }
  body.nav-open .library-panel { transform: translateX(0); }
  .panel-close { display: inline-grid; }

  .tool-btn { padding: 5px 8px; font-size: 11px; }

  .book { padding: 28px 18px 56px; }
  .book-header h1 { font-size: 24px; }
  .chapter-header h2 { font-size: 20px; }

  .chapter-nav { gap: 8px; }
  .nav-btn { max-width: none; font-size: 13px; }
}
