:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #fcfdfa;
  --surface-soft: #f0f2ec;
  --ink: #263a32;
  --ink-body: #232c28;
  --muted: #5e6a59;
  --line: #e1e6dc;
  --forest: #244d3d;
  --accent-bg: #e7efdf;
  --accent-border: #cad8be;
  --shadow: 0 12px 32px rgba(28, 46, 36, 0.05);
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "PingFang SC", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --body-size: 18px;
  --body-line: 2.02;
}

html[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f2ead8;
  --surface: #faf4e6;
  --surface-soft: #eae0ca;
  --ink: #362c20;
  --ink-body: #32281c;
  --muted: #6e604c;
  --line: #dfd3bc;
  --forest: #5b4528;
  --accent-bg: #ebe0c9;
  --accent-border: #cbb996;
  --shadow: 0 12px 32px rgba(64, 46, 20, 0.06);
}

html[data-theme="night"] {
  color-scheme: dark;
  --bg: #131816;
  --surface: #1a211e;
  --surface-soft: #1f2824;
  --ink: #dce4de;
  --ink-body: #cdd7d0;
  --muted: #8b9a90;
  --line: #29352f;
  --forest: #95be9e;
  --accent-bg: #25342c;
  --accent-border: #3a5245;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

html[data-font="sm"] { --body-size: 16px; --body-line: 1.95; }
html[data-font="md"] { --body-size: 18px; --body-line: 2.02; }
html[data-font="lg"] { --body-size: 21px; --body-line: 2.08; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #44806b; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  transform: translateY(-160%);
  z-index: 120;
  padding: 10px 16px;
  background: var(--forest);
  color: #fff;
  border-radius: 8px;
}
.skip-link:focus { transform: none; }

.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 60;
  background: transparent;
  pointer-events: none;
}
.reading-progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--forest);
  transition: width 0.08s linear;
}

.novel-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  width: min(100% - 32px, 980px);
  margin: 0 auto;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 0;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.brand-mark {
  display: grid;
  place-content: center;
  position: relative;
  width: 31px;
  height: 31px;
  color: #f6f8e9;
  background: #244d3d;
  border-radius: 9px;
  font: 600 19px/1 Georgia, serif;
  letter-spacing: -1.5px;
}
.brand-mark > span {
  position: absolute;
  right: 4px;
  bottom: 3px;
  color: #d7e7ac;
  font-size: 18px;
}
.brand-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.header-sep { color: var(--muted); opacity: 0.55; }
.header-section { font-size: 13px; color: var(--muted); }

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ctrl-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}
.ctrl-group .ctrl-btn {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 5px 10px;
}
.ctrl-group .ctrl-btn + .ctrl-btn {
  border-left: 1px solid var(--line);
}
.ctrl-btn:hover {
  background: var(--surface-soft);
}
.ctrl-btn[aria-pressed="true"] {
  background: var(--accent-bg);
  color: var(--forest);
  font-weight: 600;
}
.home-btn {
  color: var(--muted);
}
.home-btn:hover {
  color: var(--ink);
}

.reader-shell {
  width: min(100% - 32px, 820px);
  margin: 28px auto 56px;
}

.book-banner {
  padding: 22px 28px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.book-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.book-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--forest);
  font-size: 11px;
  font-weight: 600;
}
.book-sub {
  font: 11px/1.4 ui-monospace, Consolas, monospace;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.book-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.book-title-row h1 {
  font-family: var(--font-serif);
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.book-stats {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}
.book-banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.book-banner-copy {
  flex: 1 1 auto;
  min-width: 0;
}
.book-cover-btn {
  flex: 0 0 auto;
  width: 168px;
  aspect-ratio: 3 / 2;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-soft);
  box-shadow: 0 6px 18px rgba(28, 46, 36, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.book-cover-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(28, 46, 36, 0.14);
}
.book-cover-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-summary {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.75;
}
@media (max-width: 640px) {
  .book-banner-inner {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .book-cover-btn {
    width: 100%;
  }
}

.chapter-sheet {
  padding: clamp(28px, 5vw, 56px) clamp(22px, 6vw, 68px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chapter-head {
  padding-bottom: 26px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.chapter-label {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 8px;
}
.chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}
.chapter-meta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.chapter-plate {
  margin: 0 0 34px;
}
.chapter-plate-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-soft);
  cursor: zoom-in;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.chapter-plate-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.chapter-plate-btn img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}
.chapter-plate-caption {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
}
html[data-theme="night"] .chapter-plate-btn img,
html[data-theme="night"] .book-cover-btn img {
  filter: brightness(0.86) contrast(1.04);
}
.toc-item-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.toc-illu-badge {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--forest);
  font-size: 10px;
  line-height: 1.5;
}
.lightbox-dialog {
  width: min(94vw, 980px);
  max-height: 92vh;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}
.lightbox-dialog::backdrop {
  background: rgba(15, 22, 19, 0.72);
  backdrop-filter: blur(4px);
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
}
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 10px;
  object-fit: contain;
}
.lightbox-figure figcaption {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: center;
}

.chapter-body {
  font-family: var(--font-serif);
  font-size: var(--body-size);
  line-height: var(--body-line);
  color: var(--ink-body);
  letter-spacing: 0.02em;
}
.chapter-body p {
  margin-bottom: 1.15em;
  text-indent: 2em;
  text-align: justify;
  word-break: break-word;
}
.chapter-body p:last-child {
  margin-bottom: 0;
}
.scene-break {
  text-align: center;
  margin: 2em 0;
  color: var(--muted);
  letter-spacing: 0.4em;
  font-size: 14px;
  user-select: none;
}
.chapter-subhead {
  margin: 2em 0 1.1em;
  font-family: var(--font-sans);
  font-size: 0.86em;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--forest);
  text-indent: 0;
}
.chapter-subhead:first-child {
  margin-top: 0;
}
.chapter-quote {
  margin: 1.35em 0;
  padding: 0.85em 1.2em;
  border-left: 3px solid var(--accent-border);
  border-radius: 0 8px 8px 0;
  background: var(--surface-soft);
  font-size: 0.92em;
  line-height: 1.85;
}
.chapter-quote p {
  margin-bottom: 0.45em;
  text-indent: 0;
  text-align: left;
}
.chapter-quote p:last-child {
  margin-bottom: 0;
}
.chapter-body del {
  color: var(--muted);
  text-decoration-thickness: 1px;
}
.loading-tip {
  text-indent: 0 !important;
  text-align: center !important;
  color: var(--muted);
  padding: 40px 0;
  font-family: var(--font-sans);
  font-size: 14px;
}

.chapter-nav {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: stretch;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  text-align: left;
  transition: border-color 0.18s, background 0.18s;
}
.nav-btn:not(:disabled):hover {
  border-color: var(--accent-border);
  background: var(--accent-bg);
}
.nav-btn.next {
  text-align: right;
  align-items: flex-end;
}
.nav-btn.center {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
}
.nav-dir {
  font-size: 11px;
  color: var(--muted);
}
.nav-btn strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.novel-footer {
  width: min(100% - 32px, 820px);
  margin: 0 auto 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.novel-footer > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.novel-footer a:hover {
  color: var(--forest);
  text-decoration: underline;
}

.toc-dialog {
  width: min(460px, calc(100vw - 28px));
  max-height: min(76vh, 640px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.toc-dialog::backdrop {
  background: rgba(18, 28, 22, 0.45);
  backdrop-filter: blur(4px);
}
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.toc-head h2 { font-size: 16px; font-weight: 600; }
.toc-head p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.toc-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
}
.toc-close:hover { background: var(--surface-soft); }

.toc-books {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.toc-book-btn {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  white-space: nowrap;
}
.toc-book-btn[aria-pressed="true"] {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--forest);
  font-weight: 600;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 10px 12px 16px;
  overflow-y: auto;
  max-height: calc(76vh - 120px);
  display: grid;
  gap: 4px;
}
.toc-item-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  text-align: left;
}
.toc-item-btn:hover {
  background: var(--surface-soft);
}
.toc-item-btn[aria-current="true"] {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--forest);
  font-weight: 600;
}
.toc-item-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.toc-item-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.toc-item-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 680px) {
  .header-inner { padding: 10px 0; }
  .home-btn { display: none; }
  .book-banner { padding: 18px 20px; }
  .chapter-sheet { padding: 26px 20px 30px; border-radius: 12px; }
  .chapter-nav { grid-template-columns: 1fr 1fr; }
  .nav-btn.center { grid-column: 1 / -1; order: 3; justify-content: center; }
}

@media print {
  .novel-header, .chapter-nav, .novel-footer, .reading-progress { display: none; }
  .chapter-sheet { border: 0; box-shadow: none; padding: 0; }
}
