:root {
  --bg-0: #060c1b;
  --bg-1: #0c1734;
  --bg-2: #1a2f62;
  --accent: #7ea6f0;
  --accent-strong: #5b8be0;
  --brand: #628cd2;
  --ink: #e9eef9;
  --muted: #8d9bbb;
  --line: rgba(255, 255, 255, 0.09);
  --glass: rgba(18, 30, 62, 0.62);
  --glass-hi: rgba(255, 255, 255, 0.06);
  --radius: 18px;
  --top-h: 64px;
  --dock-h: 116px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(60% 55% at 50% 42%, rgba(98, 140, 210, 0.32), transparent 70%),
    radial-gradient(40% 40% at 85% 10%, rgba(126, 166, 240, 0.12), transparent 70%),
    radial-gradient(45% 45% at 10% 95%, rgba(232, 82, 30, 0.07), transparent 70%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}

.loader.done { opacity: 0; visibility: hidden; }

.loader-logo {
  width: min(220px, 56vw);
  padding: 14px 20px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: rise 0.9s var(--ease) both;
}

.loader-bar {
  width: 180px;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.loader-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 0.3s var(--ease);
}

.loader-text { font-size: 12px; letter-spacing: 0.3em; color: var(--muted); }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.topbar {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 36px;
  height: 36px;
  padding: 5px;
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.brand-text { display: grid; line-height: 1.25; }
.brand-text strong { font-size: 15px; font-weight: 600; letter-spacing: 0.06em; }
.brand-text span { font-size: 10px; letter-spacing: 0.24em; color: var(--muted); }

.chapter {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.chapter b {
  font-weight: 700;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #0b1530;
  background: var(--accent);
  font-variant-numeric: tabular-nums;
}

.chapter span { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.chapter i { font-style: normal; opacity: 0.5; }

.stage {
  position: fixed;
  z-index: 1;
  left: 0;
  right: 0;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  bottom: calc(var(--dock-h) + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}

.book-wrap {
  position: relative;
  opacity: 0;
  transform: translateY(18px) scale(0.98);
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease), translate var(--shift-dur, 0.6s) cubic-bezier(0.45, 0, 0.25, 1);
}

.ready .book-wrap { opacity: 1; transform: none; }

#book { min-width: 0 !important; min-height: 0 !important; }
#book .stf__wrapper { height: 100%; }

.book-floor {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -26px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.55), transparent);
  filter: blur(8px);
  pointer-events: none;
  transition: left 0.5s var(--ease), right 0.5s var(--ease);
}

.page {
  background: #fff center / cover no-repeat;
  overflow: hidden;
}

.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.page img.loaded { opacity: 1; }

.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stf__wrapper.--landscape .page.--left::after {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.06) 4%, transparent 10%);
}

.stf__wrapper.--landscape .page.--right::after {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2), rgba(255, 255, 255, 0.08) 2%, transparent 8%);
}

.stf__wrapper.--portrait .page::after {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.12), transparent 4%);
}

.side-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass-hi);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: background 0.25s, transform 0.25s var(--ease), opacity 0.25s;
}

.side-nav svg { width: 24px; height: 24px; }
.side-nav.prev { left: max(20px, env(safe-area-inset-left)); }
.side-nav.next { right: max(20px, env(safe-area-inset-right)); }
.side-nav:hover { background: rgba(255, 255, 255, 0.14); transform: scale(1.06); }
.side-nav:disabled { opacity: 0; pointer-events: none; }

.hint {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.6s;
  pointer-events: none;
}

.hint.show { opacity: 0.9; }

.dock {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 24px));
  padding: 10px 14px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.dock-row { display: flex; align-items: center; gap: 4px; }
.tool-row { justify-content: space-between; padding-top: 6px; border-top: 1px solid var(--line); }

.icon-btn {
  position: relative;
  flex: none;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.icon-btn em { font-style: normal; font-size: 13px; color: var(--muted); transition: color 0.2s; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.icon-btn:hover em { color: var(--ink); }
.icon-btn.on { color: var(--accent); }
.icon-btn.on em { color: var(--accent); }
.icon-btn:disabled { opacity: 0.3; pointer-events: none; }

@media (hover: hover) {
  .scrub-row .icon-btn[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 9px;
    border-radius: 7px;
    font-size: 12px;
    white-space: nowrap;
    background: rgba(5, 10, 24, 0.92);
    pointer-events: none;
  }
}

.scrubber { position: relative; flex: 1; height: 38px; display: flex; align-items: center; padding: 0 8px; }

#scrub {
  --p: 0%;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#scrub::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--p), rgba(255, 255, 255, 0.14) var(--p));
}

#scrub::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); }
#scrub::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }

#scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(126, 166, 240, 0.35), 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--ease);
}

#scrub::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(126, 166, 240, 0.35);
}

#scrub:active::-webkit-slider-thumb { transform: scale(1.2); }

.scrub-preview {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 0;
  width: 112px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(5, 10, 24, 0.94);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease);
}

.scrub-preview.show { opacity: 1; transform: translateX(-50%); }
.scrub-preview img { display: block; width: 100%; aspect-ratio: 2103 / 2200; border-radius: 6px; background: #fff; }
.scrub-preview span { display: block; margin-top: 5px; text-align: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.pager {
  flex: none;
  min-width: 78px;
  padding-left: 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pager b { font-size: 16px; font-weight: 600; }
.pager span { font-size: 12px; color: var(--muted); margin-left: 3px; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(3, 7, 18, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s, visibility 0.35s;
}

.scrim.show { opacity: 1; visibility: visible; }

.sheet {
  position: fixed;
  z-index: 30;
  top: 12px;
  bottom: 12px;
  left: 12px;
  width: min(380px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(10, 19, 42, 0.94);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  transform: translateX(calc(-100% - 24px));
  transition: transform 0.5s var(--ease);
}

.sheet.open { transform: none; }

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 18px 16px 26px;
}

.sheet-head h2, .overlay-head h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: 0.08em; }
.sheet-head p { margin: 4px 0 0; font-size: 11px; letter-spacing: 0.3em; color: var(--muted); }

.sheet-body { flex: 1; overflow-y: auto; padding: 0 12px 20px; overscroll-behavior: contain; }

.toc-single, .toc-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}

.toc-single:hover, .toc-item:hover { background: rgba(255, 255, 255, 0.06); }
.toc-single span, .toc-item span { flex: 1; font-size: 14px; }
.toc-single small, .toc-item small { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-single.active, .toc-item.active { background: rgba(126, 166, 240, 0.14); }
.toc-single.active span, .toc-item.active span, .toc-item.active small { color: var(--accent); }

.toc-group { margin-top: 14px; }

.toc-group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 14px 8px;
  border-top: 1px solid var(--line);
}

.toc-group-head b {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px var(--accent);
  font-variant-numeric: tabular-nums;
}

.toc-group-head div { display: grid; gap: 2px; }
.toc-group-head strong { font-size: 15px; font-weight: 600; }
.toc-group-head em { font-style: normal; font-size: 10px; letter-spacing: 0.18em; color: var(--muted); }

.toc-item { padding-left: 52px; }
.toc-item span { color: rgba(233, 238, 249, 0.82); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s var(--ease), visibility 0.35s;
}

.overlay.open { opacity: 1; visibility: visible; }

.grid-view {
  display: flex;
  flex-direction: column;
  background: rgba(6, 12, 27, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 24px 14px;
}

.overlay-head small { margin-left: 8px; font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.grid-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px calc(30px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 26px 18px;
  align-content: start;
  overscroll-behavior: contain;
}

.grid-cell {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: center;
  transform: translateY(14px);
  opacity: 0;
  transition: transform 0.5s var(--ease), opacity 0.5s var(--ease);
}

.grid-view.open .grid-cell { transform: none; opacity: 1; }

.grid-cell img {
  display: block;
  width: 100%;
  aspect-ratio: 2103 / 2200;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  outline: 2px solid transparent;
  outline-offset: 4px;
  transition: transform 0.3s var(--ease), outline-color 0.2s;
}

.grid-cell:hover img { transform: translateY(-4px); }
.grid-cell.active img { outline-color: var(--accent); }
.grid-cell span { display: block; margin-top: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid-cell.active span { color: var(--accent); }

.viewer { background: rgba(4, 8, 18, 0.97); }

.viewer-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.viewer-canvas.dragging { cursor: grabbing; }

.viewer-canvas img {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  will-change: transform;
}

.viewer-canvas img.anim { transition: transform 0.35s var(--ease); }

.viewer-bar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(10, 19, 42, 0.92);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  white-space: nowrap;
}

.viewer-bar .sep { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }
.viewer-page, .viewer-scale { min-width: 54px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: calc(20px + env(safe-area-inset-top));
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.95);
  color: #0b1530;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.4s var(--ease);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .side-nav { display: none; }
}

@media (max-width: 640px) {
  :root { --top-h: 56px; --dock-h: 128px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand-text strong { font-size: 14px; }
  .chapter .chapter-group, .chapter i { display: none; }
  .dock { bottom: calc(10px + env(safe-area-inset-bottom)); padding: 8px 8px 6px; }
  .scrub-row .icon-btn[data-act="first"], .scrub-row .icon-btn[data-act="last"] { display: none; }
  .tool-row { padding-top: 4px; }
  .tool-row .icon-btn { flex: 1; min-width: 0; height: 52px; padding: 0; flex-direction: column; gap: 3px; }
  .tool-row .icon-btn em { font-size: 10.5px; }
  .pager { min-width: 64px; padding-left: 4px; }
  .grid-body { grid-template-columns: repeat(3, 1fr); gap: 18px 12px; padding: 4px 16px 30px; }
  .sheet { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 78vh; transform: translateY(calc(100% + 24px)); }
  .sheet.open { transform: none; }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root { --top-h: 48px; --dock-h: 100px; }
  .dock { padding: 6px 10px; gap: 2px; }
  .tool-row .icon-btn em { display: none; }
  .tool-row .icon-btn { height: 34px; }
  .brand-text span { display: none; }
}

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