:root {
  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --font-body: "Noto Serif SC", "Songti SC", "STSong", "SimSun", "PingFang SC", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-b: 0px;
  --safe-t: 0px;
  --safe-b: constant(safe-area-inset-bottom);
  --safe-t: constant(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --r-bg: #f3efe6;
  --r-text: #2a241c;
  --r-muted: #7a7062;
  --r-line: rgba(42, 36, 28, 0.12);
  --r-panel: #ebe4d6;
  --r-accent: #9b3b2e;
  --r-bar: rgba(243, 239, 230, 0.96);
  --font-size: 18px;
  --line-height: 1.95;
}

[data-theme="night"] {
  --r-bg: #12161c;
  --r-text: #d7d2c8;
  --r-muted: #8a8478;
  --r-line: rgba(215, 210, 200, 0.12);
  --r-panel: #1a2028;
  --r-accent: #c86a55;
  --r-bar: rgba(18, 22, 28, 0.96);
}

[data-theme="amber"] {
  --r-bg: #e8d5a8;
  --r-text: #3a2a16;
  --r-muted: #7a6440;
  --r-line: rgba(58, 42, 22, 0.14);
  --r-panel: #ddc796;
  --r-accent: #8a3d22;
  --r-bar: rgba(232, 213, 168, 0.96);
}

[data-theme="sea"] {
  --r-bg: #0d1c24;
  --r-text: #d5e2e8;
  --r-muted: #7d96a3;
  --r-line: rgba(213, 226, 232, 0.12);
  --r-panel: #132832;
  --r-accent: #c45c4a;
  --r-bar: rgba(13, 28, 36, 0.96);
}

*,
*::before,
*::after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  background: #081018;
  color: #e8e2d6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.is-hidden {
  display: none !important;
}

/* ========== Intro ========== */
.intro {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100svh;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: end;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
  padding: 0;
  overflow: hidden;
  background: #040a10;
}

.intro__cover,
.intro__veil {
  pointer-events: none;
}

.intro__cover {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  overflow: hidden;
}

.intro__cover-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 28%;
  border: 0;
}

.intro__veil {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(4, 10, 16, 0.18) 0%, rgba(4, 10, 16, 0.08) 32%, rgba(4, 10, 16, 0.55) 62%, rgba(4, 10, 16, 0.92) 100%);
}

.intro__content {
  position: relative;
  z-index: 2;
  max-width: 480px;
  padding: 28px 28px 32px;
  padding-bottom: calc(32px + var(--safe-b));
}

.intro__brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: 48px;
  font-size: clamp(44px, 11vw, 68px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: 0.1em;
  color: #f2ebe0;
  text-shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
}

.intro__author {
  margin: 14px 0 0;
  font-size: 15px;
  letter-spacing: 0.28em;
  color: rgba(232, 226, 214, 0.78);
}

.intro__tagline {
  margin: 18px 0 0;
  max-width: 18em;
  font-size: 15px;
  line-height: 1.75;
  color: rgba(232, 226, 214, 0.78);
}

.intro__actions {
  margin-top: 28px;
}

.intro__actions .btn {
  display: inline-block;
  margin: 0 12px 12px 0;
  vertical-align: middle;
}

.intro__meta {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(232, 226, 214, 0.14);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: rgba(232, 226, 214, 0.48);
}

.btn {
  border: 0;
  cursor: pointer;
  padding: 14px 26px;
  border-radius: 2px;
  letter-spacing: 0.12em;
}

.btn:active {
  -webkit-transform: scale(0.98);
  transform: scale(0.98);
}

.btn--primary {
  background: #c45c4a;
  color: #fff8f4;
}

.btn--ghost {
  background: transparent;
  color: #e8e2d6;
  box-shadow: inset 0 0 0 1px rgba(232, 226, 214, 0.35);
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 80;
  display: none;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 24px;
  color: #e8e2d6;
}

.modal.is-open {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}

.modal__mask {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(4, 10, 16, 0.72);
}

.modal__panel,
.dialog__panel {
  position: relative;
  z-index: 1;
  width: 92%;
  max-width: 440px;
  background: linear-gradient(180deg, #13202a, #0d1620);
  border: 1px solid rgba(232, 226, 214, 0.1);
  padding: 22px 22px 20px;
  max-height: 80vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog__head,
.drawer__head {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  margin-bottom: 14px;
}

.dialog__head h2,
.drawer__head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.dialog__body {
  font-size: 15px;
  line-height: 1.9;
  color: rgba(232, 226, 214, 0.82);
  white-space: pre-line;
}

.dialog__body p {
  margin: 0 0 1em;
}

.dialog__tags {
  margin: 18px 0 8px;
}

.dialog__tags span {
  display: inline-block;
  margin: 0 10px 8px 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(232, 226, 214, 0.55);
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(196, 92, 74, 0.55);
}

.dialog__foot {
  margin-top: 22px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}

/* ========== Reader ========== */
.reader {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100svh;
  background: var(--r-bg);
  color: var(--r-text);
}

.reader__top {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 20;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  padding: 8px 10px;
  padding-top: calc(8px + var(--safe-t));
  background: var(--r-bar);
  border-bottom: 1px solid var(--r-line);
}

.reader__top .icon-btn {
  -webkit-flex: 0 0 44px;
  flex: 0 0 44px;
}

.reader__top-title {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  text-align: center;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--r-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader__page {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 22px 120px;
}

.chapter-head {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--r-line);
}

.chapter-head__num {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--r-accent);
}

.chapter-head__title {
  margin: 10px 0 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-size: clamp(28px, 7vw, 36px);
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.25;
}

.chapter-head__stats {
  margin: 14px 0 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--r-muted);
}

.chapter-body p {
  margin: 0 0 1.15em;
  font-size: var(--font-size);
  line-height: var(--line-height);
  text-align: justify;
  text-indent: 2em;
  letter-spacing: 0.02em;
}

.chapter-nav {
  margin-top: 40px;
  overflow: hidden;
}

.nav-btn {
  float: left;
  width: 48%;
  border: 1px solid var(--r-line);
  background: transparent;
  color: var(--r-text);
  padding: 14px 12px;
  cursor: pointer;
  letter-spacing: 0.12em;
}

.nav-btn + .nav-btn {
  float: right;
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.reader__bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  overflow: hidden;
  padding: 8px 8px;
  padding-bottom: calc(8px + var(--safe-b));
  background: var(--r-bar);
  border-top: 1px solid var(--r-line);
}

.bar-btn {
  float: left;
  width: 25%;
  border: 0;
  background: transparent;
  color: var(--r-text);
  padding: 12px 4px;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.1em;
  opacity: 0.8;
}

.bar-btn.is-active {
  opacity: 1;
  color: var(--r-accent);
}

/* ========== Drawers ========== */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: none;
}

.drawer.is-open {
  display: block;
}

.drawer__mask {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.42);
}

.drawer__panel {
  position: absolute;
  background: var(--r-panel);
  color: var(--r-text);
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
}

.drawer__panel--left {
  top: 0;
  bottom: 0;
  left: 0;
  width: 86%;
  max-width: 340px;
  padding-top: calc(12px + var(--safe-t));
  padding-bottom: calc(16px + var(--safe-b));
}

.drawer__panel--bottom {
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78vh;
  padding: 16px 18px;
  padding-bottom: calc(18px + var(--safe-b));
  border-radius: 16px 16px 0 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.drawer__head {
  padding: 0 16px 8px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.toc-list li button {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--r-line);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 16px 18px;
  cursor: pointer;
  display: block;
}

.toc-list li button.is-current {
  background: rgba(196, 92, 74, 0.12);
}

.toc-list .toc-num,
.toc-list .toc-title,
.toc-list .toc-words {
  display: block;
}

.toc-list .toc-num {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--r-muted);
}

.toc-list .toc-title {
  margin-top: 4px;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.toc-list .toc-words {
  margin-top: 4px;
  font-size: 11px;
  color: var(--r-muted);
}

.settings-block + .settings-block {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--r-line);
}

.settings-label {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--r-muted);
}

.theme-grid {
  overflow: hidden;
}

.theme-swatch {
  float: left;
  width: 23%;
  margin-right: 2.666%;
  border: 1px solid var(--r-line);
  background: transparent;
  color: inherit;
  padding: 10px 4px;
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.theme-swatch:nth-child(4n) {
  margin-right: 0;
}

.theme-swatch.is-active {
  border-color: var(--r-accent);
  color: var(--r-accent);
}

.swatch {
  display: block;
  width: 28px;
  height: 28px;
  margin: 0 auto 8px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.swatch--paper { background: #f3efe6; }
.swatch--night { background: #12161c; }
.swatch--amber { background: #e8d5a8; }
.swatch--sea { background: #0d1c24; }

.font-control {
  overflow: hidden;
}

.font-step {
  float: left;
  width: 44px;
  border: 1px solid var(--r-line);
  background: transparent;
  color: inherit;
  height: 40px;
  cursor: pointer;
}

#font-range {
  float: left;
  width: calc(100% - 100px);
  margin: 10px 6px 0;
  height: 20px;
}

.font-preview {
  clear: both;
  margin: 14px 0 0;
  font-size: var(--font-size);
  line-height: 1.8;
  color: var(--r-muted);
}

.progress-card {
  font-size: 14px;
  line-height: 1.8;
  color: var(--r-text);
}

.progress-card strong {
  color: var(--r-accent);
  font-weight: 600;
}

.progress-bar {
  margin: 12px 0 4px;
  height: 4px;
  background: var(--r-line);
  overflow: hidden;
}

.progress-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--r-accent);
}

.jump-row {
  margin-top: 16px;
}

.jump-row label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--r-muted);
}

.jump-row select {
  width: 100%;
  border: 1px solid var(--r-line);
  background: var(--r-bg);
  color: inherit;
  padding: 12px 10px;
  border-radius: 0;
}

@media (min-width: 768px) {
  .intro__cover-img {
    object-position: center 22%;
  }

  .intro__content {
    max-width: 520px;
    padding: 40px 10vw 48px;
    padding-bottom: calc(48px + var(--safe-b));
  }

  .reader__page {
    padding: 40px 32px 140px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    -webkit-animation: none !important;
    animation: none !important;
    -webkit-transition: none !important;
    transition: none !important;
  }
}
