/* ===================== 基础重置 ===================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: #1a1a1a;
  user-select: none;
  -webkit-user-select: none;
}

/* ===================== 画册舞台 ===================== */
.book-stage {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 2200px;
  perspective-origin: 50% 50%;
  background: radial-gradient(ellipse at center, #2d2d2d 0%, #1a1a1a 100%);
  overflow: hidden;
  position: relative;
}

/* ===================== 书的容器 ===================== */
.book {
  position: relative;
  width: var(--book-width, 920px);
  height: var(--book-height, 650px);
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 封面状态：书整体向左偏移，使右半页（封面）居中 */
.book.state-cover {
  transform: translateX(calc(var(--book-width, 920px) * -0.25));
}

/* 正常双页状态 */
.book.state-spread {
  transform: translateX(0);
}

/* 封底状态：书整体向右偏移，使左半页（封底）居中 */
.book.state-backcover {
  transform: translateX(calc(var(--book-width, 920px) * 0.25));
}

/* ===================== 单张纸（叶子） ===================== */
.sheet {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.85s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

/* 已翻转的纸：rotateY(-180deg) 翻到左边 */
.sheet.flipped {
  transform: rotateY(-180deg);
}

/* 正在翻转中的纸：确保在最上层 */
.sheet.flipping {
  z-index: 99999 !important;
}

/* ===================== 纸的正反两面 ===================== */
.face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.08);
}

/* 正面：默认朝前 */
.face.front {
  z-index: 2;
}

/* 背面：初始朝后，需要 rotateY(180deg) 才能在翻转后正确显示 */
.face.back {
  transform: rotateY(180deg);
  z-index: 1;
}

/* ===================== 页面图片 ===================== */
.face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
}

/* ===================== 书脊效果 ===================== */
.sheet::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(to right,
    rgba(0,0,0,0.15) 0%,
    rgba(0,0,0,0.05) 50%,
    rgba(255,255,255,0.1) 100%
  );
  z-index: 10;
  pointer-events: none;
}

/* ===================== 翻页时的动态阴影 ===================== */
.sheet .face.front::after,
.sheet .face.back::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity 0.85s ease;
}

.sheet .face.front::after {
  background: linear-gradient(to right,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0) 85%,
    rgba(0,0,0,0.1) 100%
  );
  opacity: 1;
}

.sheet.flipped .face.front::after {
  opacity: 0.6;
}

.sheet .face.back::after {
  background: linear-gradient(to left,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0) 85%,
    rgba(0,0,0,0.15) 100%
  );
  opacity: 0.7;
}

.sheet.flipped .face.back::after {
  opacity: 0;
}

/* ===================== 翻页按钮 ===================== */
.nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 0;
  margin: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  color: inherit;
  font: inherit;
}

.nav:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-50%) scale(1.08);
}

.nav:active {
  transform: translateY(-50%) scale(0.95);
}

.nav svg {
  width: 24px;
  height: 24px;
  stroke: rgba(255, 255, 255, 0.7);
  transition: stroke 0.3s ease;
}

.nav:hover svg {
  stroke: rgba(255, 255, 255, 0.95);
}

.prev-btn {
  left: 24px;
}

.next-btn {
  right: 24px;
}

.nav.disabled {
  opacity: 0.2;
  cursor: not-allowed;

}

/* ===================== 页码显示 ===================== */
.page-indicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 24px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  letter-spacing: 1px;
  z-index: 1000;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  white-space: nowrap;
}

/* ===================== Toast 提示 ===================== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  padding: 16px 40px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 16px;
  border-radius: 8px;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  letter-spacing: 1px;
}

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

/* ===================== 加载提示 ===================== */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  z-index: 100000;
  transition: opacity 0.5s ease;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

.loading p {
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  letter-spacing: 2px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===================== 响应式适配 ===================== */
@media (max-width: 1100px) {
  .book {
    --book-width: 700px;
    --book-height: 500px;
  }
}

@media (max-width: 800px) {
  .book {
    --book-width: 90vw;
    --book-height: calc(90vw * 0.7);
  }

  .nav {
    width: 44px;
    height: 44px;
  }

  .nav svg {
    width: 20px;
    height: 20px;
  }

  .prev-btn {
    left: 10px;
  }

  .next-btn {
    right: 10px;
  }

  .page-indicator {
    font-size: 12px;
    padding: 6px 16px;
  }
}

/* ===================== 减少动画偏好 ===================== */
@media (prefers-reduced-motion: reduce) {
  .sheet {
    transition: none;
  }

  .book {
    transition: none;
  }

  .sheet .face.front::after,
  .sheet .face.back::after {
    transition: none;
  }
}

/* ===================== 按钮位置调整 ===================== */
.book-stage .nav {
  position: absolute !important;
  top: auto !important;
  transform: none !important;
}

.book-stage .nav.prev-btn {
  left: calc(50% - 55px) !important;
  bottom: 10px !important;
  width: 44px !important;
  height: 44px !important;
  background: rgba(0,0,0,0.5) !important;
  border-radius: 50% !important;
  border: none !important;
  color: #fff !important;
  z-index: 9999 !important;
}

.book-stage .nav.next-btn {
  left: calc(50% + 15px) !important;
  bottom: 10px !important;
  width: 44px !important;
  height: 44px !important;
  background: rgba(0,0,0,0.5) !important;
  border-radius: 50% !important;
  border: none !important;
  color: #fff !important;
  z-index: 9999 !important;
}

@media (max-width: 768px) {
  .book-stage .nav.prev-btn {
    width: 40px !important;
    height: 40px !important;
    bottom: 8px !important;
    left: calc(50% - 50px) !important;
  }
  .book-stage .nav.next-btn {
    width: 40px !important;
    height: 40px !important;
    bottom: 8px !important;
    left: calc(50% + 10px) !important;
  }
}

/* 修复按钮被遮挡问题 */
.book-stage {
  pointer-events: none;
}

.book-stage .book,
.book-stage .sheet,
.book-stage .face {
  pointer-events: none;
}

.book-stage .nav {
  pointer-events: auto !important;
  z-index: 999999 !important;
}

.nav.disabled {
  pointer-events: auto !important;
}