:root {
  --tax-blue: #0f4f8f;
  --tax-blue-3: #54a6d8;
  --muted: #65758a;
  --shadow: 0 24px 72px rgba(16, 49, 88, 0.22);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1d2a3a;
  background: linear-gradient(135deg, #eaf3fb 0%, #f5f9fd 48%, #edf5ff 100%);
  overflow: hidden;
}

button { font: inherit; border: 0; cursor: pointer; }

.ebook-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

/* Sidebar TOC */
.toc-panel {
  position: fixed; inset: 0 auto 0 0; width: min(82vw, 310px);
  padding: 22px;
  background: rgba(248,251,255,0.92);
  backdrop-filter: blur(16px);
  border-right: 1px solid rgba(255,255,255,0.7);
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 10;
  overflow-y: auto;
  transform: translateX(-105%);
  transition: transform .25s ease;
  box-shadow: 20px 0 40px rgba(0,0,0,.18);
}
.toc-panel.open { transform: translateX(0); }
.toc-brand strong { display: block; font-size: 16px; }
.toc-brand small { color: var(--muted); font-size: 12px; }

#tocList { display: grid; gap: 2px; overflow-y: auto; align-content: start; }
.toc-item {
  border-bottom: 1px solid rgba(15,79,143,.12);
  width: 100%; text-align: left;
  padding: 6px 12px; border-radius: 6px;
  background: transparent; color: #39414d;
  font-size: 13px; line-height: 1.35;
  transition: background .15s ease;
}
.toc-item.active, .toc-item:hover { background: #e9f4ff; color: var(--tax-blue); }

.toc-section {
  font-weight: 700;
  font-size: 15px;
  color: #1d2a3a;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(15,79,143,.15);
}

.toc-cover {
  font-weight: 600;
  color: var(--tax-blue);
  border-bottom: 1px solid rgba(15,79,143,.15);
}

.toc-section:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}


/* Reader */
.reader { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; height: 100vh; }
.reader-topbar, .reader-footer {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px;
}
.book-title { flex: 1; min-width: 0; }
.book-title strong { display: block; font-size: 17px; }
.book-title small { color: var(--muted); font-size: 12px; }

.icon-btn { width: 42px; height: 42px; border-radius: 8px; display: none; place-items: center; padding: 10px; background: #fff; box-shadow: 0 10px 28px rgba(42,39,34,0.12); }
.icon-btn span { display: block; width: 18px; height: 2px; margin: 3px 0; background: #1d2a3a; }
.pill-btn { border-radius: 999px; padding: 10px 16px; color: var(--tax-blue); background: #fff; box-shadow: 0 10px 28px rgba(42,39,34,0.12); }
.round-btn { width: 48px; height: 48px; border-radius: 50%; font-size: 30px; line-height: 1; color: var(--tax-blue); background: #fff; box-shadow: 0 10px 28px rgba(42,39,34,0.12); }

/* Stage */
.stage-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 24px 18px;
}
.book-stage {
  width: min(74vw, 860px);
  height: min(82vh, 1020px);
  position: relative;
  perspective: 1400px;
}

/* Pages */
.page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform-origin: center center;
  transform: translate3d(40px, 0, 0) scale(.97) rotateY(-8deg);
  opacity: 0;
  pointer-events: none;
  transition: transform .24s cubic-bezier(.2,.8,.2,1), opacity .18s ease;
  backface-visibility: hidden;
  will-change: transform, opacity;
  background: #fff;
}
.page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.page.active {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1) rotateY(0deg);
  pointer-events: auto;
  z-index: 3;
}
.page.prev {
  opacity: 0;
  transform: translate3d(-46px, 0, 0) rotateY(18deg) scale(.985);
  z-index: 2;
}
.page.next {
  opacity: 0;
  transform: translate3d(46px, 0, 0) rotateY(-14deg) scale(.985);
  z-index: 1;
}

/* Flip animation */
.page.flip-out-forward, .page.flip-out-backward {
  opacity: 1; z-index: 6; pointer-events: none; box-shadow: 0 20px 48px rgba(16,49,88,.22);
}
.page.flip-out-forward {
  transform-origin: left center;
  animation: pageFlipForward .52s cubic-bezier(.22,.72,.16,1) forwards;
}
.page.flip-out-backward {
  transform-origin: right center;
  animation: pageFlipBackward .52s cubic-bezier(.22,.72,.16,1) forwards;
}
.page.page-reveal { z-index: 2; animation: pageReveal .36s ease-out both; }

@keyframes pageFlipForward {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotateY(0deg) scale(1); }
  52% { opacity: .92; transform: translate3d(-28px, 0, 26px) rotateY(-22deg) scale(.995); }
  100% { opacity: 0; transform: translate3d(-84px, 0, 0) rotateY(-46deg) scale(.985); }
}
@keyframes pageFlipBackward {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotateY(0deg) scale(1); }
  52% { opacity: .92; transform: translate3d(28px, 0, 26px) rotateY(22deg) scale(.995); }
  100% { opacity: 0; transform: translate3d(84px, 0, 0) rotateY(46deg) scale(.985); }
}
@keyframes pageReveal {
  0% { opacity: .18; transform: translate3d(18px, 0, 0) scale(.992); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

.book-spine {
  position: absolute; inset: 18px auto 18px 50%; width: 10px;
  transform: translateX(-50%); border-radius: 999px;
  background: rgba(15,79,143,.1); z-index: 4; pointer-events: none;
}

.turn-zone {
  position: absolute; top: 8px; bottom: 18px; width: 21%;
  background: transparent; z-index: 4;
}
.turn-zone.left { left: 24px; }
.turn-zone.right { right: 24px; }

.progress { flex: 1; display: flex; align-items: center; gap: 12px; }
.progress-line { flex: 1; height: 6px; border-radius: 999px; background: rgba(255,255,255,.75); overflow: hidden; }
.progress-line span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--tax-blue), var(--tax-blue-3)); transition: width .35s ease; }
.progress-text { color: var(--muted); font-weight: 700; min-width: 54px; }

@media (max-width: 920px) {
  body { overflow: hidden; }
  .ebook-shell { grid-template-columns: 1fr; }
  .toc-panel {
    position: fixed; inset: 0 auto 0 0; width: min(82vw, 310px);
    transform: translateX(-105%); transition: transform .25s ease;
    box-shadow: 20px 0 40px rgba(0,0,0,.18);
  }
  .icon-btn { display: block; }
  .reader-topbar { padding: 12px 14px; }
  .stage-wrap { padding: 0 12px 10px; overflow: hidden; }
  .book-stage { width: 100%; max-width: 430px; height: calc(100vh - 136px); overflow: hidden; }
  .book-spine { display: none; }
  .turn-zone { display: none; }
  .reader-footer { padding: 10px 14px 14px; }
}

/* Loading overlay */
.loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #eaf3fb 0%, #f5f9fd 48%, #edf5ff 100%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .4s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-card {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.loading-card strong {
  font-size: 18px; color: var(--tax-blue);
}
.loading-card small {
  color: var(--muted); font-size: 12px;
}
.loading-bar {
  width: 200px; height: 6px; border-radius: 999px;
  background: rgba(15,79,143,.12); overflow: hidden;
}
.loading-bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--tax-blue), var(--tax-blue-3));
  transition: width .2s ease;
}
