* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #222;
  overflow: hidden;
  touch-action: none;
}

.flipbook-wrapper {
  width: 95vw;
  max-width: 1200px;
  height: 85vh;
  background: #111;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  padding: 10px;
  color: #fff;
  position: relative;
}

.flipbook-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
}

.flipbook-header span {
  opacity: 0.8;
}

/* 首頁按鈕 */
.home-btn {
  background: rgba(68, 68, 68, 0.7);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  height: 40px;
  position: absolute;
  transition: all 0.3s ease;
  user-select: none;
  width: 40px;
  z-index: 10;
  bottom: 20px;
  left: 20px;
}

.home-btn:hover {
  background: rgba(102, 102, 102, 0.8);
  transform: scale(1.05);
}

.home-btn:active {
  transform: scale(0.95);
}

.flipbook-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
}

.book {
  flex: 1;
  height: 100%;
  background: linear-gradient(to right, #2a2a2a, #1a1a1a);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  perspective: 2500px;
  transform-style: preserve-3d;
  box-shadow: 
    inset 0 0 20px rgba(0, 0, 0, 0.5),
    0 10px 25px rgba(0, 0, 0, 0.5);
  transition: width 0.3s ease;
}

/* 單頁模式 */
.book.single-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.book.single-page .page-container {
  width: 100%;
  height: 100%;
}

/* 雙頁模式 */
.book.double-page {
  display: flex;
  justify-content: center;
  align-items: center;
}

.book.double-page .page-left, 
.book.double-page .page-right {
  width: 50%;
  height: 100%;
  position: relative;
  background: linear-gradient(to bottom, #fff 0%, #f9f9f9 100%);
}

.book.double-page .page-left {
  border-right: 1px solid #333;
  box-shadow: 
    inset -10px 0 20px rgba(0, 0, 0, 0.1),
    2px 0 5px rgba(0, 0, 0, 0.2);
}

.book.double-page .page-right {
  box-shadow: 
    inset 10px 0 20px rgba(0, 0, 0, 0.1);
}

.page-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center;
  backface-visibility: hidden;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
              opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              box-shadow 0.4s ease;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.page-container img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  background: #fff;
}

/* 當前頁顯示 */
.page-container.visible {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* 翻頁動畫 - 向左翻出 */
.page-container.flip-out-left {
  transform: rotateY(-25deg) translateX(-30%) scale(0.95);
  opacity: 0.3;
  z-index: 1;
  box-shadow: -15px 0 30px rgba(0, 0, 0, 0.4);
}

/* 翻頁動畫 - 向右翻出 */
.page-container.flip-out-right {
  transform: rotateY(25deg) translateX(30%) scale(0.95);
  opacity: 0.3;
  z-index: 1;
  box-shadow: 15px 0 30px rgba(0, 0, 0, 0.4);
}

/* 翻頁動畫 - 從左滑入 */
.page-container.slide-in-left {
  transform: translateX(-50%) rotateY(-10deg) scale(0.98);
  opacity: 0.5;
  box-shadow: -10px 0 20px rgba(0, 0, 0, 0.3);
}

/* 翻頁動畫 - 從右滑入 */
.page-container.slide-in-right {
  transform: translateX(50%) rotateY(10deg) scale(0.98);
  opacity: 0.5;
  box-shadow: 10px 0 20px rgba(0, 0, 0, 0.3);
}

/* 頁面縮放模式 */
.book.zoom-mode {
  overflow: visible;
}

.book.zoom-mode .page-container {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  transition: transform 0.3s ease-out;
  z-index: 5;
  cursor: zoom-out;
}

.book.zoom-mode .page-left .page-container,
.book.zoom-mode .page-right .page-container {
  position: absolute;
  inset: 0;
  transform-origin: center center;
}

.book .page-container {
  cursor: zoom-in;
}

/* 縮放狀態 */
.page-container.zoomed {
  transform: scale(1.8);
  z-index: 10;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
  transition: transform 0.3s ease-out;
}

.page-container.zoomed.dragging {
  transition: none; /* 拖動時禁用過渡效果，提高流暢性 */
  cursor: grabbing;
}

/* 拖動限制邊界效果 */
.page-container.zoomed.at-boundary {
  box-shadow: 0 0 40px rgba(255, 100, 100, 0.6); /* 邊界反饋 - 紅色光暈 */
}

/* 導航按鈕 */
.nav-btn {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: rgba(68, 68, 68, 0.7);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  user-select: none;
  z-index: 10;
}

.nav-btn:hover {
  background: rgba(102, 102, 102, 0.8);
  transform: scale(1.05);
}

.nav-btn:active {
  transform: scale(0.95);
}

.nav-btn[disabled] {
  opacity: 0.3;
  cursor: default;
  transform: scale(1);
}

#prevBtn {
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
}

#nextBtn {
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

/* 設置按鈕 */
.settings-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #444;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.settings-btn:hover {
  background: #666;
  transform: rotate(90deg);
}

/* 設置面板 */
.settings-panel {
  position: absolute;
  top: 50px;
  right: 20px;
  width: 250px;
  background: #333;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  z-index: 100;
  display: none;
}

.settings-panel.visible {
  display: block;
}

.settings-title {
  font-size: 16px;
  margin-bottom: 15px;
  border-bottom: 1px solid #555;
  padding-bottom: 8px;
}

.setting-item {
  margin-bottom: 12px;
}

.setting-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 20px;
  background: #555;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-switch.active {
  background: #4CAF50;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.3s;
}

.toggle-switch.active::after {
  left: 22px;
}

.flipbook-footer {
  margin-top: 8px;
  text-align: center;
  font-size: 13px;
  opacity: 0.8;
}

/* 響應式設計 */
@media (max-width: 768px) {
  .flipbook-wrapper {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    padding: 5px;
  }

  .nav-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  /* 豎屏模式：默認單頁 */
  @media (orientation: portrait) {
    .flipbook-wrapper {
      height: 95vh;
    }
  }

  /* 橫屏模式：雙頁 */
  @media (orientation: landscape) {
    .flipbook-wrapper {
      height: 90vh;
    }
  }
}