/* ============================================================
   Catalog (StPageFlip flipbook)
   - #book is the flip engine parent container (stretch mode)
   - Do NOT add perspective to .book-viewport (engine has its own 3D)
   ============================================================ */

/* Page (HTML mode): real <img> DOM, browser renders by DPR natively */
#book .page { margin: 0; background: #e9ebee; overflow: hidden; }
#book .page > img.catalog-page-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0;                         /* 未加载完成前隐藏，避免裂图/空白闪烁 */
  transition: opacity .45s ease;
}
#book .page > img.catalog-page-img.loaded { opacity: 1; }
/* Cover/back hard pages: add thickness shadow */
#book .page[data-density="hard"] { box-shadow: 0 6px 20px rgba(0,0,0,.12); }

/* Spine shadow (desktop dual-page only) */
.catalog-book::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 12px;
  margin-left: -6px;
  background: linear-gradient(90deg, 
    transparent 0%,
    rgba(0,0,0,.03) 20%,
    rgba(0,0,0,.06) 40%,
    rgba(0,0,0,.08) 50%,
    rgba(0,0,0,.06) 60%,
    rgba(0,0,0,.03) 80%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity .3s;
}
.catalog-book.stf__parent::before { opacity: 1; }

/* Mobile single-page: hide spine shadow */
@media (max-width: 767px) {
  .catalog-book::before,
  .catalog-book.stf__parent::before { opacity: 0 !important; display: none !important; }
}

/* Fullscreen image zoom viewer (single page, double-tap to open) */
.imgzoom { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.92); touch-action: none; }
.imgzoom[hidden] { display: none; }
.imgzoom-backdrop { position: absolute; inset: 0; }
.imgzoom-img { max-width: 100%; max-height: 100%; transform-origin: center center; will-change: transform; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
.imgzoom-close { position: absolute; top: 16px; right: 16px; z-index: 2; width: 44px; height: 44px; border: none; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; font-size: 24px; line-height: 1; cursor: pointer; }
.imgzoom-close:hover { background: rgba(255,255,255,.3); }
.imgzoom-hint { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,.7); font-size: 13px; pointer-events: none; }

.page-main--bare { min-height: 100vh; }

.catalog-stage {
  position: relative;
  padding: 32px 0 56px;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg) 0%, var(--bg-secondary) 100%);
  min-height: 100vh;
  overflow: hidden;
}

.catalog-topbar {
  max-width: 1000px;
  margin: 0 auto 14px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 14px;
}
.catalog-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 6px 18px var(--shadow-color);
  transition: transform .2s, background .2s, box-shadow .2s;
}
.catalog-back:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 10px 24px var(--shadow-color); }
.catalog-back svg { width: 18px; height: 18px; }
.catalog-pageinfo { font-variant-numeric: tabular-nums; }
.catalog-cur { color: var(--primary); font-weight: 700; font-size: 18px; }
.catalog-sep { color: var(--text-muted); margin: 0 4px; }

/* Chapter quick jump select */
.chapter-jump {
  height: 36px;
  padding: 0 28px 0 12px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 6px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .2s, box-shadow .2s;
}
.chapter-jump:hover { border-color: var(--primary); }
.chapter-jump:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(231,76,60,.12); }
.chapter-jump option { font-size: 14px; }

/* Flip engine parent: width determines book size (stretch auto-fit) */
.book-viewport {
  position: relative;
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px 0 30px;
  min-height: 620px;
  /* 水平手势交给翻页引擎(JS)，垂直滚动保留给页面；防 iOS 橡皮筋双触发 */
  touch-action: pan-y;
}
.catalog-book {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}
.catalog-book canvas { display: block; }

/* Caption bar below the book */
.catalog-caption {
  max-width: 1000px;
  margin: 14px auto 0;
  padding: 0 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  min-height: 20px;
}

/* Flip nav buttons */
.book-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .92);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  z-index: 50;
  opacity: .3;
  transition: transform .2s, background .2s, color .2s, opacity .2s;
}
.book-nav:not(:disabled):hover { background: var(--primary); color: #fff; opacity: .3; transform: translateY(-50%) scale(1.06); }
.book-nav.prev { left: 6px; }
.book-nav.next { right: 6px; }
.book-nav:disabled { opacity: .3; cursor: not-allowed; background: rgba(255, 255, 255, .92); color: var(--primary); transform: translateY(-50%); }

/* Hint / empty state */
.catalog-hint {
  text-align: center;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 13px;
  transition: opacity .8s;
}
.catalog-hint.faded { opacity: 0; }
.catalog-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 60px 20px;
}

/* Small screen tweaks */
@media (max-width: 767px) {
  .book-nav { width: 44px; height: 44px; }
  .book-nav.prev { left: 2px; }
  .book-nav.next { right: 2px; }
}

/* ---- Spread zoom button (PC + mobile) ---- */
.catalog-zoom-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 60;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,.92);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  opacity: .4;
  transition: opacity .2s, transform .2s, background .2s, color .2s;
}
.catalog-zoom-btn:hover { opacity: 1; background: var(--primary); color: #fff; transform: scale(1.08); }
.catalog-zoom-btn svg { width: 20px; height: 20px; }
/* Mobile: smaller button, lower opacity */
@media (max-width: 767px) {
  .catalog-zoom-btn {
    width: 34px; height: 34px;
    top: 8px; right: 8px;
    opacity: .5;
  }
  .catalog-zoom-btn svg { width: 18px; height: 18px; }
}

/* ---- Spread zoom viewer (fullscreen, dual-page on PC / single on mobile) ---- */
.spread-zoom {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.94);
  touch-action: none;
}
.spread-zoom[hidden] { display: none; }
.spread-zoom-inner {
  display: flex;
  max-width: 96vw; max-height: 94vh;
  gap: 2px;
  background: #1a1a1a;
  padding: 4px;
  border-radius: 4px;
  will-change: transform;
  transform-origin: center center;
}
.spread-zoom-inner img {
  height: 88vh; max-width: 48vw;
  object-fit: contain;
  display: block;
  -webkit-user-select: none; user-select: none; -webkit-user-drag: none;
}
/* Mobile: single image, full width */
@media (max-width: 767px) {
  .spread-zoom-inner {
    flex-direction: column;
    gap: 0;
    padding: 2px;
  }
  .spread-zoom-inner img {
    height: auto; max-height: 85vh; max-width: 95vw;
    width: auto;
  }
}
.spread-zoom-close {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; font-size: 24px; line-height: 1; cursor: pointer;
}
.spread-zoom-close:hover { background: rgba(255,255,255,.3); }
.spread-zoom-hint {
  position: absolute; bottom: 18px; left: 0; right: 0; text-align: center;
  color: rgba(255,255,255,.7); font-size: 13px; pointer-events: none;
}

/* ---- Loading screen ---- */
#catalogLoading {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #fff;
  transition: opacity .45s ease;
}
#catalogLoading.out { opacity: 0; pointer-events: none; }

.catalog-loading-logo {
  font-size: 18px; font-weight: 700; color: var(--primary,#e74c3c);
  letter-spacing: 2px; margin-bottom: 36px;
}
.catalog-loading-logo span { color: #333; }

/* Book outline placeholder animation */
.catalog-loading-book {
  width: 100px; height: 138px; position: relative; margin-bottom: 36px;
  border: 2px solid #e0e0e0; border-radius: 3px;
  overflow: hidden; background: #fafafa;
}
.catalog-loading-book::after {
  content: ''; position: absolute;
  width: 30%; height: 100%; top: 0; right: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
  animation: loadingSweep 1.5s ease-in-out infinite;
}
@keyframes loadingSweep {
  0%   { transform: translateX(-200%); }
  100% { transform: translateX(400%); }
}

/* Progress bar */
.catalog-progress-wrap { width: 180px; }
.catalog-progress-label {
  font-size: 12px; color: #999; margin-bottom: 8px;
  display: flex; justify-content: space-between;
}
.catalog-progress-bar {
  height: 4px; background: #eee; border-radius: 2px; overflow: hidden;
}
.catalog-progress-fill {
  height: 100%; background: var(--primary,#e74c3c);
  border-radius: 2px; width: 0%; transition: width .25s ease;
}
