/* ===== 红楼梦阅读器 · 样式 ===== */

:root {
  --font-size: 20px;
  --font-serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", "Source Han Serif SC", "Georgia", serif;
  --font-ui: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --line-height: 2;
  --col-gap: 56px;
  --accent: #9e2b25;
  --accent-soft: #c0504a;
}

/* 主题：宣纸 */
body[data-theme="paper"] {
  --bg: #f5efe1;
  --bg-panel: #fbf7ee;
  --bg-bars: #efe6d3;
  --text: #2e2a24;
  --text-soft: #6b6252;
  --border: #ded2b8;
  --shadow: rgba(80, 60, 30, .16);
}
/* 主题：米黄 */
body[data-theme="sepia"] {
  --bg: #e8dcc0;
  --bg-panel: #f1e7cf;
  --bg-bars: #ddcfae;
  --text: #3c3223;
  --text-soft: #6f6142;
  --border: #cdbd95;
  --shadow: rgba(80, 60, 30, .18);
}
/* 主题：夜读 */
body[data-theme="night"] {
  --bg: #16181d;
  --bg-panel: #1e2128;
  --bg-bars: #1a1d22;
  --text: #c9ccd1;
  --text-soft: #8a9099;
  --border: #2e333c;
  --shadow: rgba(0, 0, 0, .5);
  --accent: #d0605a;
  --accent-soft: #e0857f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== 顶部栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 52px;
  padding: 0 12px;
  background: var(--bg-bars);
  border-bottom: 1px solid var(--border);
  z-index: 40;
  flex: 0 0 auto;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 4px; }
.brand { font-family: var(--font-serif); font-size: 20px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.brand-sub { font-size: 11px; color: var(--text-soft); writing-mode: horizontal-tb; margin-left: 2px; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.topbar-center {
  flex: 1;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.icon-btn:hover { background: var(--border); }
.icon-btn.small { width: 30px; height: 30px; font-size: 14px; }
.icon-btn svg { display: block; }
.mark-toggle.active { color: var(--accent); }
.mark-toggle.active .ic-bookmark { fill: var(--accent); }

/* ===== 阅读区 ===== */
.reader {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 34px 60px;
}
.article {
  height: 100%;
  column-gap: var(--col-gap);
  column-fill: auto;
  font-family: var(--font-serif);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text);
  text-align: justify;
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}
.article p {
  margin: 0 0 .9em 0;
  text-indent: 2em;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.article p.heading-line {
  text-indent: 0;
  text-align: center;
  font-size: 1.28em;
  font-weight: 700;
  margin: 0 0 1.2em 0;
  color: var(--accent);
  letter-spacing: 1px;
}
.chapter-opening {
  text-align: center;
  margin: 0 0 1.4em 0;
}
.chapter-opening .co-vol {
  font-size: .95em;
  color: var(--text-soft);
  letter-spacing: 3px;
}
.chapter-opening .co-title {
  font-size: 1.35em;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.5;
  margin-top: .3em;
}
.article .co-divider {
  width: 60%;
  margin: 0 auto 1.6em auto;
  border: 0;
  border-top: 1px solid var(--border);
}
mark.hit {
  background: rgba(220, 170, 60, .55);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
mark.hit.current { background: var(--accent); color: #fff; }

/* ===== 侧边目录 ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 300px;
  max-width: 84vw;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 18px var(--shadow);
  transform: translateX(-105%);
  transition: transform .28s ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sidebar-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-serif);
  font-size: 17px;
  letter-spacing: 2px;
  color: var(--accent);
  flex: 0 0 auto;
}
.toc { overflow-y: auto; padding: 6px 0 24px; flex: 1 1 auto; }
.toc-item {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 9px 16px;
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text);
  border-left: 3px solid transparent;
  line-height: 1.5;
}
.toc-item:hover { background: var(--bg-bars); }
.toc-item.active { border-left-color: var(--accent); color: var(--accent); background: var(--bg-bars); }
.toc-item .toc-vol { flex: 0 0 auto; color: var(--text-soft); font-size: 13px; }
.toc-item.active .toc-vol { color: var(--accent); }

/* ===== 面板（书签 / 查找）===== */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 92vw;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 18px var(--shadow);
  transform: translateX(105%);
  transition: transform .28s ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel-body { overflow-y: auto; padding: 10px 14px 24px; flex: 1 1 auto; }
.panel-head span { font-family: var(--font-serif); }

.search-box { display: flex; gap: 8px; padding: 12px 14px 6px; }
.search-box input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent-soft); }
.primary-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 0 16px;
  height: 38px;
  font-size: 15px;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-soft); }
.search-meta { padding: 4px 16px; font-size: 13px; color: var(--text-soft); min-height: 18px; }

.result, .mark-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  background: var(--bg);
  transition: border-color .15s, transform .1s;
}
.result:hover, .mark-card:hover { border-color: var(--accent-soft); }
.result .r-head, .mark-card .m-head {
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.result .r-body { font-family: var(--font-serif); font-size: 15px; line-height: 1.7; }
.result mark { background: rgba(220, 170, 60, .55); color: inherit; }
.mark-card .m-body { font-family: var(--font-serif); font-size: 14px; line-height: 1.7; color: var(--text); }
.mark-card .m-del {
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
}
.mark-card .m-del:hover { color: var(--accent); background: var(--bg-bars); }
.empty-tip { text-align: center; color: var(--text-soft); font-size: 14px; padding: 30px 10px; }

.mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 50;
}
.mask.show { opacity: 1; pointer-events: auto; }

/* ===== 底部翻页栏 ===== */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 50px;
  padding: 0 10px;
  background: var(--bg-bars);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 40;
}
.nav-btn {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 8px;
  height: 36px;
  padding: 0 12px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.nav-btn:hover { background: var(--border); }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
  min-width: 150px;
  justify-content: center;
  flex-wrap: nowrap;
  overflow: hidden;
}
.page-info .dot { opacity: .5; }
#chapterIndicator { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

/* ===== 翻页热区 ===== */
.tap-zone {
  position: fixed;
  top: 52px;
  bottom: 50px;
  width: 16%;
  z-index: 20;
  cursor: pointer;
  opacity: 0;
}
.tap-left { left: 0; }
.tap-right { right: 0; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%) translateY(12px);
  background: rgba(30, 26, 20, .9);
  color: #f5efe1;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 90;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 响应式 ===== */
@media (max-width: 720px) {
  .viewport { padding: 20px 22px; }
  .brand-sub { display: none; }
  .nav-btn { padding: 0 8px; font-size: 13px; }
  .page-info { min-width: 90px; }
  #chapterIndicator { max-width: 90px; }
  .topbar-center { display: none; }
  .tap-zone { width: 22%; }
  .panel, .sidebar { width: 88vw; }
}
