:root {
  --bg: #f4efe4;
  --bg-panel: #fbf8f0;
  --bg-card: #fffdf7;
  --text: #3d3327;
  --text-light: #8a7d68;
  --accent: #8f3b2d;
  --accent-soft: #c9a06c;
  --border: #e2d8c3;
  --ruby: #b0703c;
  --shadow: 0 2px 14px rgba(90, 70, 40, .12);
}
html[data-theme="dark"] {
  --bg: #1d1b18;
  --bg-panel: #26231f;
  --bg-card: #2d2a25;
  --text: #d8cfbf;
  --text-light: #8f8676;
  --accent: #d98e6a;
  --accent-soft: #7a6a4f;
  --border: #3d382f;
  --ruby: #c98d5e;
  --shadow: 0 2px 14px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC", "Source Han Serif SC", "STZhongsong", "SimSun", serif;
  transition: background .25s, color .25s;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.site-title { font-size: 20px; letter-spacing: 2px; font-weight: 700; }
.site-title a { color: var(--accent); text-decoration: none; }
.site-title .sub {
  font-size: 12px; color: var(--text-light);
  margin-left: 8px; letter-spacing: 4px; font-weight: 400;
}
.toolbar { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg {
  display: inline-flex; border: 1px solid var(--accent-soft); border-radius: 6px; overflow: hidden;
}
.seg button {
  border: none; background: transparent; color: var(--text);
  padding: 5px 12px; cursor: pointer; font-size: 13px;
  font-family: inherit;
}
.seg button.active { background: var(--accent); color: #fff; }
.tool-btn {
  border: 1px solid var(--accent-soft); background: transparent; color: var(--text);
  border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px;
  font-family: inherit;
}
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.icon-btn {
  display: none; border: 1px solid var(--border); background: transparent;
  color: var(--text); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 16px;
}

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky; top: 57px;
  height: calc(100vh - 57px); overflow-y: auto;
}
.sidebar-foot {
  margin-top: 30px; font-size: 12px; color: var(--text-light);
  line-height: 1.8; text-align: center;
}
.mask { display: none; }

/* ---------- 目录 ---------- */
.toc h2 { font-size: 14px; color: var(--text-light); margin: 4px 0 8px; letter-spacing: 3px; }
.toc details { margin-bottom: 10px; }
.toc summary {
  cursor: pointer; font-size: 16px; font-weight: 700; color: var(--text);
  padding: 8px 10px; border-radius: 6px; list-style: none;
  border: 1px solid var(--border); background: var(--bg-card);
}
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after { content: "▸"; float: right; color: var(--text-light); transition: transform .2s; }
.toc details[open] summary::after { transform: rotate(90deg); }
.toc summary .book-author { display: block; font-size: 12px; font-weight: 400; color: var(--text-light); margin-top: 3px; }
.toc ul { list-style: none; margin: 6px 0 0 6px; }
.toc li a {
  display: block; padding: 7px 12px; font-size: 14px;
  color: var(--text); text-decoration: none; border-radius: 6px;
}
.toc li a:hover { background: var(--bg-card); }
.toc li a.active { background: var(--accent); color: #fff; }

/* ---------- 正文 ---------- */
.reader { flex: 1; min-width: 0; padding: 34px 8% 60px; }
#article { max-width: 760px; margin: 0 auto; }
.home-hero { text-align: center; padding: 40px 0 10px; }
.home-hero h2 { font-size: 30px; letter-spacing: 8px; color: var(--accent); margin-bottom: 14px; }
.home-hero p { color: var(--text-light); line-height: 2; font-size: 15px; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 24px; }
.home-era { text-align: center; margin-top: 34px; }
.home-era h3 {
  font-size: 16px; letter-spacing: 6px; color: var(--text-light);
  font-weight: normal; margin-bottom: 4px;
}
.home-era h3::after {
  content: ""; display: block; width: 42px; height: 1px;
  background: var(--accent-soft); margin: 10px auto 0;
}
.home-cards a {
  display: block; padding: 24px 18px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 10px; text-decoration: none;
  color: var(--text); box-shadow: var(--shadow); transition: transform .15s;
}
.home-cards a:hover { transform: translateY(-3px); }
.home-cards .hc-title { font-size: 22px; color: var(--accent); letter-spacing: 3px; }
.home-cards .hc-author { font-size: 13px; color: var(--text-light); margin-top: 6px; }
.home-cards .hc-desc { font-size: 13px; color: var(--text-light); margin-top: 12px; line-height: 1.8; }

.chap-head { text-align: center; margin-bottom: 30px; }
.chap-head .chap-book { font-size: 14px; color: var(--text-light); letter-spacing: 4px; }
.chap-head h2 { font-size: 26px; margin: 12px 0 8px; letter-spacing: 2px; color: var(--text); }
.chap-head .chap-src { font-size: 13px; color: var(--text-light); }
.chap-intro {
  background: var(--bg-card); border-left: 3px solid var(--accent-soft);
  padding: 14px 18px; border-radius: 0 8px 8px 0;
  font-size: 14px; line-height: 2; color: var(--text-light); margin-bottom: 34px;
}
.chap-body { line-height: 2.3; }
.chap-body p { margin-bottom: 1.6em; font-size: var(--fs, 20px); text-align: justify; }
.chap-body ruby { ruby-align: center; }
.chap-body rt {
  font-size: .42em; color: var(--ruby);
  font-family: "Times New Roman", Georgia, serif;
  letter-spacing: .5px;
  user-select: none;
}
html[data-pinyin="off"] .chap-body rt { display: none; }
.chapter-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 50px; }
.chapter-nav a, .chapter-nav button {
  font-family: inherit; font-size: 14px; color: var(--accent);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px; cursor: pointer; text-decoration: none;
}
.chapter-nav button:disabled { opacity: .4; cursor: default; }

/* ---------- 全文目录 ---------- */
.idx-search {
  display: flex; gap: 10px; align-items: center; margin-bottom: 18px;
}
.idx-search input {
  flex: 1; font-family: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; outline: none;
}
.idx-search input:focus { border-color: var(--accent-soft); }
.idx-count { font-size: 13px; color: var(--text-light); white-space: nowrap; }
.idx-list {
  list-style: none; columns: 2; column-gap: 28px;
}
.idx-list li { break-inside: avoid; }
.idx-list li a {
  display: block; padding: 7px 10px; font-size: 14px;
  color: var(--text); text-decoration: none; border-radius: 6px;
  border-bottom: 1px dashed var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.idx-list li a:hover { background: var(--bg-card); color: var(--accent); }
.idx-list .idx-empty { color: var(--text-light); padding: 10px; font-size: 14px; }

/* ---------- 检索高亮 ---------- */
mark.hit {
  background: rgba(201, 160, 108, .45);
  color: inherit; padding: 0 1px; border-radius: 2px;
}
html[data-theme="dark"] mark.hit { background: rgba(217, 142, 106, .38); }

/* ---------- 首页检索框 ---------- */
.home-search { display: flex; gap: 10px; max-width: 520px; margin: 24px auto 0; }
.home-search input {
  flex: 1; font-family: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; outline: none;
}
.home-search input:focus { border-color: var(--accent-soft); }
.home-search button {
  font-family: inherit; font-size: 15px; color: #fff;
  background: var(--accent); border: none; border-radius: 8px;
  padding: 10px 22px; cursor: pointer; letter-spacing: 2px;
}

/* ---------- 全文检索页 ---------- */
.s-wrap { max-width: 860px; margin: 0 auto; padding: 34px 20px 60px; }
.s-hero { text-align: center; padding: 26px 0 4px; }
.s-hero h2 { font-size: 26px; letter-spacing: 6px; color: var(--accent); margin-bottom: 10px; }
.s-hero p { color: var(--text-light); font-size: 14px; }
.s-form { display: flex; gap: 10px; margin: 26px 0 10px; }
.s-form input {
  flex: 1; font-family: inherit; font-size: 16px; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px; outline: none;
}
.s-form input:focus { border-color: var(--accent-soft); }
.s-form button {
  font-family: inherit; font-size: 15px; color: #fff;
  background: var(--accent); border: none; border-radius: 8px;
  padding: 12px 26px; cursor: pointer; letter-spacing: 2px;
}
.s-form select {
  font-family: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 8px; outline: none;
}
.s-hint { font-size: 13px; color: var(--text-light); line-height: 1.8; }
.s-status { font-size: 14px; color: var(--text-light); margin: 20px 0 6px; }
.s-empty { color: var(--text-light); margin-top: 24px; font-size: 14px; }
.s-hit { margin-top: 20px; }
.s-hp { font-size: 15px; }
.s-hp .s-cat {
  display: inline-block; font-size: 12px; color: var(--accent);
  border: 1px solid var(--accent-soft); border-radius: 4px;
  padding: 1px 8px; margin-right: 10px; white-space: nowrap;
}
.s-hp a { color: var(--text); text-decoration: none; }
.s-hp a:hover { color: var(--accent); }
.s-hs {
  margin-top: 8px; font-size: 14px; line-height: 2; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px; text-align: justify;
}
.s-hs em { font-style: normal; color: var(--accent); font-weight: 700; }
.s-more { font-size: 12px; color: var(--text-light); padding: 8px 10px; }
.vol-back { margin-bottom: 22px; }
.vol-back button {
  font-family: inherit; font-size: 14px; color: var(--accent);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.vol-back button:hover { border-color: var(--accent-soft); }
.loading-tip {
  text-align: center; color: var(--text-light); padding: 60px 0; font-size: 15px;
}
@media (max-width: 700px) { .idx-list { columns: 1; } }
.page-foot { max-width: 760px; margin: 40px auto 0; text-align: center; font-size: 12px; color: var(--text-light); }

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .icon-btn { display: inline-block; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 100;
    height: 100vh; transform: translateX(-100%);
    transition: transform .25s;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  .mask.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
  .reader { padding: 24px 20px 50px; }
  .site-title .sub { display: none; }
  .toolbar { gap: 5px; }
  .seg button, .tool-btn { padding: 4px 8px; font-size: 12px; }
}
