:root {
  --font-scale: 1;
  --bg: #f8f5ef;
  --paper: #fffdf8;
  --text: #24211d;
  --muted: #71695f;
  --line: #e7ded2;
  --accent: #8f3d2f;
  --button: #f1e8dc;
  --shadow: 0 20px 50px rgba(49, 36, 24, 0.08);
}

body[data-theme="dark"] {
  --bg: #171717;
  --paper: #202020;
  --text: #ebe2d5;
  --muted: #aaa095;
  --line: #33302c;
  --accent: #d38372;
  --button: #2b2926;
  --shadow: none;
}

body[data-theme="green"] {
  --bg: #dfe9d8;
  --paper: #edf4e8;
  --text: #1a2e1a;
  --muted: #4a6348;
  --line: #b8ccb2;
  --accent: #2f6b32;
  --button: #d4e6cc;
  --shadow: 0 16px 40px rgba(30, 56, 28, 0.08);
}

body[data-theme="paper"] {
  --bg: #ddd0b8;
  --paper: #f2e6cf;
  --text: #3a2c1c;
  --muted: #6f5a42;
  --line: #cdb895;
  --accent: #8a4f24;
  --button: #e8d7b8;
  --shadow: 0 16px 40px rgba(74, 52, 24, 0.1);
}

body[data-theme="gray"] {
  --bg: #d8d8d8;
  --paper: #ececec;
  --text: #242424;
  --muted: #555555;
  --line: #bdbdbd;
  --accent: #4a4a4a;
  --button: #d2d2d2;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC", "Songti SC", "SimSun", "Microsoft YaHei", serif;
  line-height: 1.9;
}

body[data-font="hei"] {
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
}

body[data-font="kai"] {
  font-family: "KaiTi", "STKaiti", "Kaiti SC", "Noto Serif SC", serif;
}

body[data-font="fang"] {
  font-family: "FangSong", "STFangsong", "FangSong_GB2312", "Noto Serif SC", serif;
}

body.cover-active .topbar,
body.cover-active .progress,
body.cover-active .layout {
  display: none !important;
}

body.cover-active {
  overflow: hidden;
}

.cover-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  min-height: 100vh;
  display: none;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 18%, rgba(143, 61, 47, 0.2), transparent 34%),
    linear-gradient(135deg, #11100f, #27221d 54%, #0f0f0e);
}

body.cover-active .cover-screen {
  display: grid;
}

.cover-shell {
  width: min(420px, 88vw);
}

.cover-card {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  background: #151412;
}

.cover-image {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.cover-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.cover-actions a {
  display: block;
  border: 1px solid rgba(238, 230, 216, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  background: rgba(241, 232, 220, 0.12);
  color: #f0e9dc;
  font: inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.cover-actions a:first-child {
  background: #8f3d2f;
  border-color: #a84a3a;
  color: #fff7ee;
}

.topbar {
  position: fixed;
  top: 12px;
  left: 50%;
  right: auto;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(920px, calc(100vw - 32px));
  padding: 18px 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.back-link {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}
.back-link:hover {
  color: var(--accent);
}

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tools button,
.tools a {
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 20;
  background: transparent;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.layout {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.layout .toc {
  display: none;
}

.toc-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(15, 14, 12, 0.42);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.toc-backdrop:not([hidden]) {
  display: block;
}

body.toc-panel-open .toc {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 30;
  width: min(320px, 88vw);
  max-height: 100vh;
  margin: 0;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 0;
  border-left: none;
  border-top: none;
  border-bottom: none;
  background: var(--paper);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
  touch-action: pan-y;
}

.toc {
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toc h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.toc a {
  display: block;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.45;
}

.toc a.section-link {
  color: var(--text);
  font-weight: 700;
}

.toc a.chapter-link {
  padding-left: 10px;
  font-size: 13px;
}

.toc a:hover {
  color: var(--accent);
}

.reader {
  min-width: 0;
  padding: 44px 58px 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  -webkit-user-select: none;
  user-select: none;
}

body[data-mode="page"] {
  overflow: hidden;
}

body[data-mode="page"] .layout {
  height: 100vh;
  overflow: hidden;
}

body[data-mode="page"] .reading-column {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

body[data-mode="page"] .reader {
  width: min(920px, calc(100vw - 32px));
  height: calc(100vh - 24px);
  margin: 12px auto;
  overflow: hidden;
  padding: clamp(28px, 5vw, 58px);
  border-radius: 8px;
}

body[data-mode="page"].chrome-hidden .reader {
  height: calc(100vh - 24px);
  box-shadow: none;
}

body[data-mode="scroll"] .reading-column {
  min-height: 100vh;
  padding: 88px 0 56px;
}

body[data-mode="scroll"].chrome-hidden .reading-column {
  padding-top: 16px;
}

body[data-mode="scroll"] .reader {
  width: min(920px, calc(100vw - 32px));
  margin: 0 auto;
  padding: clamp(28px, 5vw, 58px) clamp(28px, 5vw, 58px) 72px;
  border-radius: 8px;
}

body[data-mode="scroll"].chrome-hidden .reader {
  box-shadow: none;
}

.reader.paged-reader {
  touch-action: pan-y;
}

.reading-column {
  min-width: 0;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

body[data-mode="page"] .pager {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 12;
  width: min(420px, calc(100vw - 32px));
  margin: 0;
  transform: translateX(-50%);
}

.pager[hidden] {
  display: none;
}

.pager button {
  min-width: 86px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--button);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager span {
  min-width: 76px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.page-continuation {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: calc(14px * var(--font-scale));
}

.book-title {
  margin: 0 0 8px;
  text-align: center;
  font-size: calc(34px * var(--font-scale));
  font-weight: 700;
}

.byline {
  margin: 0 0 38px;
  text-align: center;
  color: var(--muted);
  font-size: calc(15px * var(--font-scale));
}

.reader h2 {
  margin: 56px 0 24px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: calc(24px * var(--font-scale));
  line-height: 1.4;
}

.reader h3 {
  margin: 46px 0 20px;
  font-size: calc(22px * var(--font-scale));
  line-height: 1.45;
}


.reader p {
  margin: 0 0 1.05em;
  font-size: calc(18px * var(--font-scale));
  text-align: left;
  text-indent: 2em;
  word-break: break-word;
}

.reader p.paragraph-continued {
  margin-bottom: 0;
}

.reader strong {
  font-weight: 700;
}

.reader code {
  padding: 0 0.25em;
  border-radius: 4px;
  background: var(--button);
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 0.92em;
}

body.chrome-hidden .topbar,
body.chrome-hidden .pager {
  display: none;
}

body.chrome-hidden:not(.toc-panel-open) .toc {
  display: none;
}

.loading {
  color: var(--muted);
}

@media (max-width: 860px) {
  .cover-screen {
    padding: 22px;
  }

  .cover-shell {
    width: min(360px, 86vw);
  }

  .topbar {
    top: 8px;
    width: calc(100vw - 16px);
    align-items: flex-start;
    padding: 12px 16px;
  }

  body[data-mode="scroll"] .reading-column {
    padding-top: 76px;
    padding-bottom: 40px;
  }

  body[data-mode="scroll"].chrome-hidden .reading-column {
    padding-top: 8px;
  }

  .reading-column,
  .reader {
    touch-action: manipulation;
  }

  body[data-mode="scroll"] .reader,
  body[data-mode="scroll"].chrome-hidden .reader {
    width: 100vw;
    margin: 0;
    padding: 28px 18px 48px;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .reader h2 {
    margin-top: 32px;
  }

  .reader h3 {
    margin-top: 28px;
  }

  body[data-mode="page"] .reader {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 30px 22px;
    border-color: transparent;
    border-radius: 0;
  }

  body[data-mode="page"].chrome-hidden .reader {
    height: 100vh;
  }

  body[data-mode="page"] .pager {
    bottom: 12px;
    width: calc(100vw - 24px);
    padding: 10px;
  }

  .pager button {
    min-width: 78px;
    padding: 8px 10px;
  }

  .book-title {
    font-size: calc(28px * var(--font-scale));
  }

  .reader p {
    font-size: calc(17px * var(--font-scale));
    text-align: left;
  }
}
