/* ── 变量 ─────────────────────────────────────────── */
:root {
  --font-body: "Noto Serif SC", "Source Han Serif SC", "STSong", "Songti SC", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  --fs: 18px;
  --lh: 1.85;
  --content-w: 42em;
  --sidebar-w: 280px;

  --bg: #faf8f5;
  --bg-side: #f0ede8;
  --bg-card: #fff;
  --text: #2c2c2c;
  --text-muted: #777;
  --accent: #8b4513;
  --accent-light: #c8956a;
  --border: #ddd;
  --hl: #fff3cd;
  --annotated-bg: #fef9ef;
  --note-bg: #fffbe6;
  --note-border: #e8d9a0;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-side: #222;
  --bg-card: #2a2a2a;
  --text: #d4d0c8;
  --text-muted: #888;
  --accent: #d2a06d;
  --accent-light: #a07540;
  --border: #3a3a3a;
  --hl: #3d3520;
  --annotated-bg: #2a2518;
  --note-bg: #332e1a;
  --note-border: #5a4f2e;
}

/* ── 全局 ─────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: var(--fs); }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: var(--lh);
  min-height: 100vh;
}

/* ── 侧栏 ─────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
}

.sidebar-header {
  padding: 28px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.book-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}
.book-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.book-author {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: var(--font-ui);
}

/* 搜索 */
.search-box {
  padding: 12px 16px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-muted); }

.search-results {
  position: absolute;
  left: 16px; right: 16px; top: 52px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 300;
}
.search-results.hidden { display: none; }
.search-result {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font-ui);
  line-height: 1.5;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--hl); }
.search-result .ch-label {
  font-size: 0.72rem;
  color: var(--accent);
  display: block;
  margin-bottom: 2px;
}
.search-result mark {
  background: var(--hl);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}
.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font-ui);
}

/* 目录 */
#toc {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
#toc ul { list-style: none; }
#toc li a {
  display: block;
  padding: 8px 20px;
  font-size: 0.85rem;
  font-family: var(--font-ui);
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
#toc li a:hover {
  background: rgba(0,0,0,0.04);
}
#toc li.active a {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
  background: rgba(139,69,19,0.06);
}
#toc li.unavailable a {
  color: var(--text-muted);
  font-style: italic;
}
#toc li .ch-num {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 1px;
}

/* 侧栏底部工具 */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
}
.sidebar-footer button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.sidebar-footer button:hover { background: rgba(0,0,0,0.06); }
#font-size-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 20px;
  text-align: center;
}

/* ── 正文区 ────────────────────────────────────────── */
#content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

#reader {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 60px 32px 100px;
}

.chapter-title {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 2.5em;
  color: var(--text);
  letter-spacing: 0.05em;
}

#reader p {
  text-indent: 2em;
  margin-bottom: 1em;
  text-align: justify;
}

#reader p.editor-note {
  text-indent: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  background: var(--annotated-bg);
  padding: 10px 16px;
  border-radius: 6px;
  border-left: 3px solid var(--accent-light);
  margin-top: 2em;
}

/* 旁注 */
.annotated {
  border-bottom: 1px dashed var(--accent-light);
  cursor: help;
  position: relative;
}
.note-popup {
  position: absolute;
  left: 0; top: 100%;
  width: 280px;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-family: var(--font-ui);
  line-height: 1.6;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 100;
  display: none;
}
.note-popup.visible { display: block; }

/* 章节导航 */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 4em;
  padding-top: 2em;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
  padding: 8px 0;
}
.chapter-nav a:hover { text-decoration: underline; }

/* 占位页 */
.placeholder {
  text-align: center;
  padding: 4em 0;
  color: var(--text-muted);
  font-family: var(--font-ui);
}
.placeholder p { text-indent: 0; font-size: 1rem; }

/* 免责声明 / 关于页 */
.disclaimer {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--text);
}
.disclaimer p {
  text-indent: 0;
  margin-bottom: 1em;
}
.disclaimer h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 2em;
  margin-bottom: 0.6em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}
.disclaimer ul {
  padding-left: 1.5em;
  margin-bottom: 1em;
}
.disclaimer li {
  margin-bottom: 0.4em;
}
.disclaimer em {
  font-style: italic;
}
.disclaimer strong {
  color: var(--accent);
}
.disclaimer-action {
  text-align: center;
  margin-top: 3em;
  padding-top: 2em;
  border-top: 1px solid var(--border);
}
.disclaimer-action a {
  display: inline-block;
  padding: 12px 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  transition: opacity 0.15s;
}
.disclaimer-action a:hover { opacity: 0.85; }

/* 目录中的"关于本站" */
#toc li.toc-about {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}
#toc li.toc-about a {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 现代回响板块 */
.echo-block {
  margin-top: 3em;
  padding: 24px 28px;
  background: var(--annotated-bg);
  border: 1px solid var(--note-border);
  border-radius: 10px;
}
.echo-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.2em;
  padding-bottom: 0.5em;
  border-bottom: 1px solid var(--note-border);
  letter-spacing: 0.08em;
  font-family: var(--font-ui);
}
.echo-subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-family: var(--font-ui);
}
.echo-text {
  font-size: 0.88rem;
  font-family: var(--font-ui);
  line-height: 1.75;
  text-indent: 0;
  margin-bottom: 0.7em;
  color: var(--text);
}

/* 菜单按钮（移动端） */
.menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 150;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* 遮罩 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}
.overlay.hidden { display: none; }

/* ── 响应式 ────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    left: calc(-1 * var(--sidebar-w));
    transition: left 0.25s ease;
    box-shadow: none;
  }
  #sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  #content { margin-left: 0; }
  #reader { padding: 52px 20px 80px; }
  .menu-btn { display: block; }
  .chapter-title { font-size: 1.3rem; }

  /* 旁注在移动端改为全宽 */
  .note-popup {
    position: fixed;
    left: 16px; right: 16px;
    bottom: 16px; top: auto;
    width: auto;
  }
}

/* ── 滚动条 ────────────────────────────────────────── */
#toc::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
  width: 4px;
}
#toc::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
