* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0; padding: 0;
  font-family: "微軟正黑體", Arial, sans-serif;
  background: #fefefe;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  height: 100vh;
}
h2 {
  margin: 10px 0 10px 0;
  flex-shrink: 0;
}
#mainContainer {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 100vw;
  align-items: center;
  justify-content: flex-start;
  position: relative; 
  padding: 0 10px 10px 10px;
  box-sizing: border-box;
}
#bookContainer {
  position: relative;
  width: 100%;
  max-width: 1600px;
  padding: 0 15vw;
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f5f5;
  overflow: hidden;
  transform-origin: center center;
  user-select: none;
  cursor: default;
  touch-action: none;
  transition: padding-bottom 0.3s ease;
}
#book {
  display: flex;
  gap: 2px;
  height: 100%;
  max-height: 100%;
  width: 90vw;
  max-width: 1600px;
  border: 1px solid rgba(0,0,0,0.15);
  box-shadow: 0 3px 12px rgba(0,0,0,0.1);
  background: white;
  position: relative;
  overflow: hidden;
  transition: transform 0.4s ease;
  perspective: 2500px;
}
#book::after {
  content: "";
  position: absolute;
  top: 15px;
  bottom: 15px;
  left: 50%;
  width: 2px;
  background-color: rgba(0,0,0,0.1);
  transform: translateX(-50%);
  z-index: 5;
  transition: opacity 0.3s;
}
.page {
  flex: 1 1 50%;
  height: 100%;
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1.414;
  transition: flex 0.3s, opacity 0.3s;
}
.page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease;
  will-change: opacity;
}

/* --- 3D 翻頁動畫 CSS --- */
.turning-page {
  position: absolute;
  top: 0;
  height: 100%;
  transform-style: preserve-3d;
  z-index: 10;
}
.turning-page .page-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: white;
}
.turning-page .page-face img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.turning-page .back {
  transform: rotateY(180deg);
}
.anim-flip-next {
  transform-origin: left center;
  animation: flip-next 0.8s forwards ease-in-out;
}
@keyframes flip-next {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-180deg); }
}
.anim-flip-prev {
  transform-origin: right center;
  animation: flip-prev 0.8s forwards ease-in-out;
}
@keyframes flip-prev {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(180deg); }
}

.anim-close-prev {
  transform-origin: left center; 
  animation: close-prev 0.8s forwards ease-in-out;
}
@keyframes close-prev {
  from { transform: rotateY(-180deg); }
  to { transform: rotateY(0deg); }
}

/* --- 控制項樣式 --- */
#footer-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  flex-shrink: 0;
}
#controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 400px;
}
button {
  padding: 10px 28px;
  font-size: 16px;
  border-radius: 6px;
  border: none;
  background-color: #0078d4;
  color: white;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.3s ease;
  min-width: 100px;
  flex-grow: 1;
  text-align: center;
}
button:disabled {
  background: #ccc;
  cursor: not-allowed;
}
#page-info {
  font-weight: 600;
  font-size: 18px;
  text-align: center;
  color: #333;
}
#credit-info {
  color: gray;
}

/* --- 小螢幕響應式設計 --- */
@media (max-width: 600px) {
  #bookContainer {
    padding: 0 5vw;
  }
  #book {
    width: 100vw;
    border: none;
    box-shadow: none;
    background: transparent;
  }
  #book.single-page-mode #rightPage {
      flex: 0 0 0;
      opacity: 0;
  }
  #book.single-page-mode #leftPage {
      flex: 1 1 100%;
  }
  #book.single-page-mode::after {
      opacity: 0;
  }

  #footer-controls {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      padding: 10px 15px 15px 15px;
      background-color: rgba(0, 0, 0, 0.7);
      z-index: 20;
      gap: 10px;
      border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  #controls {
    max-width: none;
    gap: 10px;
  }
  button {
    min-width: 45%;
  }
  #page-info, #credit-info {
      color: rgba(255, 255, 255, 0.9);
  }
}