/* --- [RWD] 手機直拿防呆遮罩 --- */
#orientation-warning {
  display: none;
}

@media (orientation: portrait) and (max-width: 768px) {
  body:not(.dismiss-warning) #orientation-warning {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 62, 80, 0.98);
    z-index: 9999;
    color: white;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
  }

  .warning-icon {
    font-size: 60px;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
  }

  .warning-text {
    font-size: 20px;
    line-height: 1.6;
    font-weight: bold;
    margin-bottom: 30px;
  }

  .dismiss-warning-btn {
    background: transparent;
    color: #fff;
    border: 2px solid #fff;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .dismiss-warning-btn:hover {
    background: #fff;
    color: #2c3e50;
  }

  body:not(.dismiss-warning) .interactive-area,
  body:not(.dismiss-warning) .book-info,
  body:not(.dismiss-warning) .dialect-tabs,
  body:not(.dismiss-warning) .global-play-btn {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

@keyframes rotatePhone {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(-90deg);
  }

  100% {
    transform: rotate(-90deg);
  }
}

/* --- Switcher 開關樣式 (無邊框版) --- */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0;
}

.toggle-switch:hover {
  opacity: 0.8;
}

.toggle-switch input {
  display: none;
}

.slider {
  position: relative;
  width: 36px;
  height: 20px;
  background-color: #bdc3c7;
  border-radius: 20px;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .4s;
}

.ebook-page input:checked + .slider {
  background-color: #2F7AFF;
}

.ebook-page input:checked + .slider:before {
  transform: translateX(16px);
}

.toggle-label {
  font-weight: bold;
  color: #34495e;
  user-select: none;
  white-space: nowrap;
  font-size: 16px;
}

@media (max-width: 900px) {
  .icon-btn {
    font-size: 16px;
    padding: 6px 10px;
  }

  .interactive-area {
    padding-top: 100px;
  }
}

/* --- 書本側邊換頁箭頭 --- */
.side-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: #5A3214;
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.side-nav-btn:hover:not(:disabled) {
  background: #5A3214e6;
  transform: translateY(-50%) scale(1.1);
}

.side-nav-btn:disabled {
  opacity: 0;
  pointer-events: none;
}

.side-prev {
  left: -60px;
}

.side-next {
  right: -60px;
}

@media (max-width: 1050px) {
  .side-prev {
    left: 0px;
  }

  .side-next {
    right: 0px;
  }
}

/* --- 放大與拖曳外掛容器 --- */
#zoom-wrapper {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  transition: transform 0.3s ease;
  position: relative;
}

#zoom-wrapper.is-zoomed {
  cursor: grab;
}

#zoom-wrapper.is-zoomed:active {
  cursor: grabbing;
}

/* 放大時關閉翻頁點擊 (屏蔽內部 DOM 事件) */
.is-zoomed #flipbook {
  pointer-events: none;
}

#flipbook {
  aspect-ratio: 1440 / 994;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  position: relative;
}

/* 書本整體立體投射陰影（單頁置中或雙頁展開皆自動成型） */
#flipbook-dom, .stf__parent {
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.12)) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.06));
}

.page {
  background-color: #fff;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.page.--left {
  box-shadow: inset -10px 0 20px rgba(0, 0, 0, 0.1);
}

.page.--right {
  box-shadow: inset 10px 0 20px rgba(0, 0, 0, 0.1);
}

/* 改為 img 標籤渲染支援 */
.page-content-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* 封面與封底（單頁置中）：四邊淡灰邊界線 */
.page-content-wrapper.is-single {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* 內頁跨頁：書脊中縫那一側不畫框 */
.page.--left .page-content-wrapper.is-spread {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-right: none;
}

.page.--right .page-content-wrapper.is-spread {
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-left: none;
}

.page-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

/* 新增翻頁時的 Loading 圖示 (放在背景圖底層) */
.page-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border: 4px solid rgba(0, 0, 0, 0.05);
  border-top: 4px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 1;
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }

  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* 確保背景圖層級高於 Loader，當圖片下載完成後會自然覆蓋它 */
.page-bg {
  z-index: 2;
}

.text-bg {
  z-index: 3;
}

.page-number {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #000;
  text-shadow: 0 1px 3px #fffc;
  font-family: monospace;
  z-index: 5;
}

/* --- 面板專用播放按鈕 (原底部按鈕整合至上方) --- */
.global-play-btn {
  padding: 5px 12px;
  font-size: 16px;
  border-radius: 20px;
  font-weight: bold;
  background: #27ae60;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.global-play-btn.disabled,
.global-play-btn:disabled {
  background: #bdc3c7;
  color: #ecf0f1;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

.global-play-btn:not(:disabled):hover {
  background: #219a52;
}

.global-play-btn.playing {
  background: #e74c3c;
  animation: pulse 2s infinite;
}

.global-play-btn.playing:hover {
  background: #c0392b;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(231, 76, 60, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
  }
}

.global-play-btn>i {
  width: 20px;
}

#toast-message {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(44, 62, 80, 0.95);
  color: white;
  padding: 15px 25px;
  border-radius: 10px;
  z-index: 2000;
  transition: all 0.3s ease;
  opacity: 0;
  pointer-events: none;
  white-space: pre-line;
  text-align: center;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  font-size: 14px;
  line-height: 1.4;
}

#toast-message.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}