:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: #d7d9d8;
  color: #1e2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.78), transparent 34%),
    linear-gradient(135deg, #c4c9c6 0%, #eef0ec 48%, #b9bfbc 100%);
  user-select: none;
}

.stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 12px max(66px, env(safe-area-inset-bottom)) 12px;
}

.book-viewport {
  position: relative;
  width: min(94vw, 900px);
  height: min(calc((94vw / 2) * 1.499), calc(100vh - 104px), 760px);
  overflow: visible;
}

.book-shell {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 22px 30px rgba(35, 38, 38, 0.3));
}

.book-shell::before {
  content: "";
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: -16px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.32), transparent 72%);
  filter: blur(5px);
}

.book {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.book[data-flip-state="user_fold"] {
  cursor: grabbing;
}

.turn-page-wrapper,
.turn-page {
  overflow: hidden;
}

.book-page {
  background: #fffdf7;
  overflow: hidden;
  cursor: grab;
}

.book-page.--even .book-page-inner {
  box-shadow:
    inset -18px 0 30px rgba(0, 0, 0, 0.1),
    inset 0 0 0 1px rgba(20, 20, 20, 0.08);
}

.book-page.--odd .book-page-inner {
  box-shadow:
    inset 18px 0 30px rgba(0, 0, 0, 0.09),
    inset 0 0 0 1px rgba(20, 20, 20, 0.08);
}

.book-page-inner {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16), transparent 15%, transparent 85%, rgba(0, 0, 0, 0.06)),
    repeating-linear-gradient(90deg, rgba(80, 70, 56, 0.022) 0, rgba(80, 70, 56, 0.022) 1px, transparent 1px, transparent 9px),
    #fffdf7;
}

.book-page-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 45%, rgba(80, 65, 45, 0.06));
}

.page-content {
  position: relative;
  z-index: 2;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(26px, 5.4vw, 54px) clamp(22px, 4.6vw, 44px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 249, 240, 0.92)),
    repeating-linear-gradient(0deg, transparent 0, transparent 35px, rgba(88, 62, 45, 0.07) 36px);
}

.page-kicker {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: clamp(12px, 1.7vw, 14px);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-content h2 {
  margin: 0;
  font-size: clamp(28px, 4.4vw, 52px);
  line-height: 1.08;
  letter-spacing: 0;
}

.page-body {
  margin: 24px 0 0;
  font-size: clamp(15px, 2vw, 20px);
  line-height: 1.8;
  color: #4b5553;
}

.page-list {
  display: grid;
  gap: 12px;
  margin: 32px 0 0;
  padding: 0;
  list-style: none;
}

.page-list li {
  position: relative;
  padding: 13px 14px 13px 22px;
  border-left: 4px solid var(--accent);
  background: rgba(255, 255, 255, 0.72);
  color: #24302f;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.45;
}

.page-badge {
  margin-top: auto;
  align-self: flex-end;
  min-width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-weight: 800;
}

.page-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  z-index: 4;
  display: none;
  text-align: center;
  color: rgba(30, 38, 38, 0.42);
  font-size: 12px;
}

.page-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.page-html {
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.toc-button,
.page-meter,
.nav-button {
  position: fixed;
  z-index: 20;
  border: 0;
  color: #fff;
  background: rgba(28, 31, 31, 0.84);
  box-shadow: 0 6px 18px rgba(20, 20, 20, 0.18);
}

.toc-button {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  height: 42px;
  padding: 0 18px;
  border-radius: 4px;
}

.page-meter {
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  min-width: 72px;
  height: 36px;
  display: grid;
  grid-auto-flow: column;
  place-content: center;
  gap: 2px;
  border-radius: 18px;
  font-size: 14px;
}

.page-actions {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  gap: 10px;
}

.nav-button {
  position: static;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 31px;
  line-height: 1;
}

.nav-button:disabled {
  opacity: 0.35;
}

.toc-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.toc-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.toc-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(72vh, 560px);
  padding: 0 18px max(18px, env(safe-area-inset-bottom));
  background: #f8f8f5;
  border-radius: 8px 8px 0 0;
  transform: translateY(102%);
  transition: transform 0.24s ease;
  box-shadow: 0 -14px 34px rgba(0, 0, 0, 0.25);
}

.toc-panel.is-open .toc-backdrop {
  opacity: 1;
}

.toc-panel.is-open .toc-sheet {
  transform: translateY(0);
}

.toc-header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-header h1 {
  margin: 0;
  font-size: 20px;
}

.close-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #e7e7e1;
  color: #202423;
  font-size: 26px;
  line-height: 1;
}

.toc-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
  overflow: auto;
  max-height: calc(min(72vh, 560px) - 76px);
}

.toc-list button {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: #ffffff;
  color: #202423;
  text-align: left;
}

.toc-list button small {
  flex: 0 0 auto;
  color: #747a78;
}

.toc-list button.is-current {
  color: #fff;
  background: #a72d2a;
}

.toc-list button.is-current small {
  color: rgba(255, 255, 255, 0.76);
}

@media (min-width: 760px) {
  .toc-sheet {
    left: 50%;
    right: auto;
    width: min(440px, calc(100vw - 32px));
    transform: translate(-50%, 102%);
  }

  .toc-panel.is-open .toc-sheet {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 759px) {
  .stage {
    overflow: hidden;
    place-items: center start;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: 0;
  }

  .book-viewport {
    overflow: hidden;
  }

  .book-shell {
    width: 100%;
    height: 100%;
  }

  .page-content {
    padding: clamp(24px, 8vw, 40px) clamp(20px, 7vw, 34px);
  }
}

@media (max-width: 360px) {
  .toc-button {
    padding: 0 14px;
  }

  .nav-button {
    width: 38px;
    height: 38px;
  }
}
