:root {
  --paper: #f6f1e6;
  --paper-2: #fbf8f1;
  --ink: #2b2620;
  --ink-2: #5d554a;
  --ink-3: #8d8479;
  --line: #ded5c3;
  --line-2: #eae3d5;
  --accent: #8a5a2b;
  --accent-soft: #f0e2cf;
  --night-paper: #1a1a1c;
  --night-paper-2: #232326;
  --night-ink: #cfc9c0;
  --night-ink-2: #9a948a;
  --night-line: #33322f;
  --shadow: 0 10px 34px rgba(60, 46, 28, .14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Songti SC", "SimSun", "Source Han Serif SC", "Noto Serif CJK SC", "STSong", Georgia, serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body.night {
  background: var(--night-paper);
  color: var(--night-ink);
}

a { color: inherit; text-decoration: none; }

/* ============ 首页 ============ */
.home {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 20px 40px;
  background:
    radial-gradient(120% 80% at 50% -10%, #fffdf8 0%, transparent 60%),
    var(--paper);
}

body.night .home {
  background: radial-gradient(120% 80% at 50% -10%, #26262a 0%, transparent 60%), var(--night-paper);
}

.home-inner { width: 100%; max-width: 620px; }

.seal {
  width: 62px; height: 62px;
  margin: 0 auto 22px;
  display: grid; place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  font-size: 26px;
  letter-spacing: 2px;
  line-height: 1;
  opacity: .85;
}

.book-title {
  text-align: center;
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 700;
  letter-spacing: 10px;
  margin: 0 0 12px;
  text-indent: 10px;
}

.book-sub {
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
  letter-spacing: 3px;
  margin: 0 0 40px;
}

.book-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 26px 26px;
  box-shadow: var(--shadow);
}

body.night .book-card {
  background: var(--night-paper-2);
  border-color: var(--night-line);
}

.book-meta {
  display: flex;
  gap: 26px;
  justify-content: center;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px dashed var(--line);
}

body.night .book-meta { border-color: var(--night-line); }

.meta-item { text-align: center; }

.meta-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.meta-lab {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 2px;
  margin-top: 4px;
}

.book-desc {
  font-size: 15px;
  line-height: 2;
  color: var(--ink-2);
  margin: 0 0 24px;
  text-align: justify;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  letter-spacing: 4px;
  cursor: pointer;
  transition: filter .2s;
  font-family: inherit;
}

.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.progress-line {
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
  min-height: 18px;
}

.vol-list { margin-top: 26px; }

.vol-head {
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 4px;
  margin: 0 0 10px;
  text-align: center;
}

.vol-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 4px;
  border-bottom: 1px dotted var(--line);
  font-size: 14px;
  cursor: pointer;
}

body.night .vol-row { border-color: var(--night-line); }
.vol-row:last-child { border-bottom: none; }
.vol-row:hover .vol-name { color: var(--accent); }
.vol-name { font-weight: 600; }
.vol-tip { font-size: 12px; color: var(--ink-3); }

.foot-tip {
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 30px;
  line-height: 1.9;
}

/* ============ 阅读器 ============ */
.reader { display: flex; flex-direction: column; height: 100%; }

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(251, 248, 241, .92);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line-2);
  position: sticky;
  top: 0;
  z-index: 20;
}

body.night .topbar {
  background: rgba(35, 35, 38, .92);
  border-color: var(--night-line);
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
}

body.night .icon-btn {
  background: var(--night-paper-2);
  border-color: var(--night-line);
  color: var(--night-ink-2);
}

.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.on { color: #fff; background: var(--accent); border-color: var(--accent); }

.toc-toggle { display: inline-block; }

.chapter-tag {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 16, .42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s;
  z-index: 28;
}

body.night .scrim { background: rgba(0, 0, 0, .55); }

.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(320px, 84vw);
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  transform: translateX(-102%);
  transition: transform .26s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

body.night .drawer {
  background: var(--night-paper-2);
  border-color: var(--night-line);
}

.drawer.open { transform: none; }

.drawer-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

body.night .drawer-head { border-color: var(--night-line); }

.drawer-title { font-size: 17px; font-weight: 700; letter-spacing: 2px; }
.drawer-close { cursor: pointer; font-size: 20px; line-height: 1; color: var(--ink-3); }

.drawer-scroll { overflow-y: auto; padding: 8px 10px 30px; flex: 1; }

.vol-group { margin-bottom: 4px; }

.vol-label {
  padding: 12px 10px 6px;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 2px;
  font-weight: 600;
}

.ch-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.55;
}

.ch-item:hover { background: var(--accent-soft); }
.ch-item.active { background: var(--accent); color: #fff; }
.ch-item.active .ch-w { color: rgba(255, 255, 255, .72); }

.ch-no { flex: 0 0 auto; color: var(--ink-3); font-size: 12px; }
.ch-w { margin-left: auto; font-size: 11px; color: var(--ink-3); font-family: system-ui, sans-serif; }
.ch-item.read .ch-no::after { content: "·"; }

/* 正文区 */
.stage { flex: 1; overflow-y: auto; position: relative; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 34px 22px 46vh;
}

.volume-head {
  text-align: center;
  margin: 8px 0 30px;
}

.volume-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 8px;
  text-indent: 8px;
  margin: 0 0 10px;
}

.volume-epi {
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 2px;
}

.chapter-head { text-align: center; margin-bottom: 30px; }

.chapter-no {
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 6px;
  margin-bottom: 10px;
}

.chapter-name {
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 700;
  letter-spacing: 4px;
  margin: 0;
  text-indent: 4px;
}

.chapter-body p {
  margin: 0 0 1.15em;
  text-align: justify;
  text-indent: 2em;
  line-height: var(--lh, 2);
  font-size: var(--fs, 18px);
  letter-spacing: .02em;
}

.reader.night .chapter-body p { color: var(--night-ink); }

.reader.night .volume-title,
.reader.night .chapter-name { color: var(--night-ink); }

.reader.night .chapter-no,
.reader.night .volume-epi { color: var(--night-ink-2); }

/* 章末 */
.chapter-end {
  text-align: center;
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 8px;
  margin: 46px 0 26px;
  text-indent: 8px;
}

.nav-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.nav-row .btn { width: auto; flex: 1; }

.read-progress {
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 16px;
  font-family: system-ui, sans-serif;
}

.settings-pop {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: min(260px, calc(100vw - 24px));
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  z-index: 25;
  display: none;
}

body.night .settings-pop {
  background: var(--night-paper-2);
  border-color: var(--night-line);
}

.settings-pop.show { display: block; }

.sets-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-2);
}

.sets-row:last-child { margin-bottom: 0; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }

body.night .seg { border-color: var(--night-line); }

.seg button {
  border: none;
  background: transparent;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-2);
  font-family: inherit;
}

body.night .seg button { color: var(--night-ink-2); }
.seg button.on { background: var(--accent); color: #fff; }

@media (max-width: 560px) {
  .chapter-tag { font-size: 12px; }
  .page { padding: 26px 16px 46vh; }
  .settings-pop { left: 12px; width: auto; }
}

@media (min-width: 561px) {
  .drawer { width: 330px; }
  .chapter-tag { font-size: 14px; }
}


/* ============ 口令门禁 ============ */
html.locked body > *:not(#gate) { visibility: hidden; }

#gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 80% at 50% -10%, #fffdf8 0%, transparent 60%),
    var(--paper);
}

.gate-card { width: min(360px, 86vw); text-align: center; }

.gate-seal {
  width: 62px; height: 62px;
  margin: 0 auto 22px;
  display: grid; place-items: center;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  font-size: 26px;
  line-height: 1;
  opacity: .85;
}

.gate-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 8px;
  text-indent: 8px;
  margin: 0 0 10px;
}

.gate-sub {
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 3px;
  margin: 0 0 26px;
}

.gate-input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
  text-align: center;
  letter-spacing: 6px;
  outline: none;
}

.gate-input:focus { border-color: var(--accent); }

#gate-btn { margin-top: 12px; }

.gate-err {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 13px;
  color: #b4462f;
  letter-spacing: 1px;
}

.gate-note {
  margin: 22px 0 0;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.9;
}

.shake { animation: gate-shake .4s; }

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
