*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: #3a3a3a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, sans-serif;
}

/* ── Toolbar ── */
#toolbar {
  flex-shrink: 0;
  height: 48px;
  background: #1e1e1e;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: 10;
  border-bottom: 1px solid #444;
}

#toolbar button {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 6px;
  background: #3a3a3a;
  color: #eee;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s;
}
#toolbar button:hover  { background: #555; }
#toolbar button:active { background: #4a9eff; }

#zoomLabel {
  min-width: 46px;
  text-align: center;
  color: #aaa;
  font-size: 0.82rem;
}

/* ── 頁碼顯示區 ── */
#pageIndicator {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.82rem;
}

#pageInput {
  width: 6ch;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 4px;
  color: #eee;
  font-size: 0.82rem;
  font-family: inherit;
  text-align: center;
  padding: 2px 4px;
  outline: none;
  transition: border-color 0.15s;
}
#pageInput:focus { border-color: #4a9eff; background: #1a1a1a; }

.page-slash { color: #555; }
#pageTotal  { color: #888; min-width: 2ch; }

/* ── Toolbar 分隔線 ── */
.toolbar-sep {
  width: 1px;
  height: 22px;
  background: #555;
  margin: 0 4px;
  flex-shrink: 0;
}

/* ── Stage ── */
#stage {
  flex: 1;
  overflow: auto;      /* 放大後可捲動 */
  padding: 16px;
  display: grid;
  place-items: center; /* 正常尺寸時置中；overflow: auto 捲動時也正確 */
  cursor: pointer;     /* 書本外側可點擊翻頁 */
}

/* 書本本身不是點擊翻頁區 */
#spread { cursor: default; }

/* ── Nav buttons：固定在畫面最左 / 最右，垂直置中 ── */
.nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 72px;
  border: none;
  border-radius: 0 6px 6px 0;
  background: rgba(255,255,255,0.10);
  color: #fff;
  font-size: 5em;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#prevBtn { left:  0; border-radius: 0 6px 6px 0; }
#nextBtn { right: 0; border-radius: 6px 0 0 6px; }
.nav-btn:hover    { background: rgba(255,255,255,0.28); }
.nav-btn:disabled { opacity: 0.18; cursor: default; }

/* ── Spread（書本展開區） ── */
#spread {
  position: relative;
  display: flex;
  flex-shrink: 0;
  box-shadow: 0 24px 64px rgba(0,0,0,0.65);
  /* perspective 放在 spread，兩頁共用同一視點，旋轉才自然 */
  perspective: 2500px;
  perspective-origin: center center;
}

/* 書脊細線（雙頁模式） */
#spread::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.15);
  z-index: 15;
  pointer-events: none;
}
#spread.single-page::before { display: none; }

canvas { display: block; background: #fff; }

#bgLeft  { border-right: none; }

/* ── 單頁模式 ── */
#spread.single-page #bgRight { display: none; }

/* ── 翻頁葉片 ── */
#flipper {
  position: absolute;
  top: 0;
  display: none;
  z-index: 30;
}

#flipperInner {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

#flipFront,
#flipBack {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

#flipBack {
  transform: rotateY(180deg);
}

/* ── Loading Overlay ── */
#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#loadingOverlay span {
  color: #eee;
  font-size: 1rem;
  letter-spacing: 0.05em;
}
