:root {
  color-scheme: dark;
  --stage-bg: #141414;
  --stage-bg-2: #1c1c1c;
  --page-bg: #f7f5f0;
  --accent: #e9321e;
  --ink: #f2f0ea;
  --ink-dim: #9a968c;
  --btn-bg: rgba(255, 255, 255, 0.08);
  --btn-bg-hover: rgba(233, 50, 30, 0.85);
}

/* Self-hosted (not Google Fonts CDN) — this page's CSP has no font-src for
   fonts.gstatic.com, deliberately kept tight since it's the PDF-serving
   surface. Same family as the rest of the site (Noto Serif), latin +
   latin-ext subsets only — plenty for the short UI strings here. */
@font-face {
  font-family: "Noto Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/noto-serif-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Noto Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/noto-serif-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--stage-bg);
  font-family: "Noto Serif", Georgia, "Times New Roman", serif;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, var(--stage-bg-2) 0%, var(--stage-bg) 72%);
  padding: 16px;
}

/* --- loading (overlays the book so PageFlip still measures a laid-out,
   visible container when it initializes underneath) --- */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--ink-dim);
  background: var(--stage-bg);
  z-index: 10;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

#loading-text {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

/* --- book area --- */
#book-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: calc(100% - 40px);
}

/* #zoomViewport is the fixed, unmoving "window" — it clips (overflow:hidden)
   and never itself transforms. #zoomStage sits inside it and carries the
   pan/zoom transform. #book is StPageFlip's own element and NEVER gets a
   transform from this code — StPageFlip uses that property internally for
   its own flip animation, and writing to it externally (even an identity
   translate/scale) was silently breaking drag-to-flip after any zoom
   interaction, found via headless-browser testing. */
#zoomViewport {
  position: relative;
  overflow: hidden;
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.55));
  touch-action: none;
  /* #book is styled by StPageFlip as width:100% (clamped by its own
     min/max-width) — that only resolves correctly against a definite
     container width, so this flex item needs one too, not a shrink-to-fit
     auto width (the default, which collapses the 100% child to nothing). */
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#zoomStage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 0 0;
  will-change: transform;
}

#zoomCatcher {
  position: absolute;
  inset: 0;
  pointer-events: none;
  cursor: grab;
  touch-action: none;
}

#zoomViewport.is-zoomed #zoomCatcher {
  pointer-events: auto;
}

#zoomCatcher:active {
  cursor: grabbing;
}

#book .book-page {
  background: var(--page-bg);
}

.page-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--page-bg);
}

.page-inner canvas {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.page-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

/* --- nav buttons --- */
.nav-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--btn-bg);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover,
.nav-btn:focus-visible {
  background: var(--btn-bg-hover);
}

.nav-btn:active { transform: scale(0.94); }

.nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-btn[disabled] {
  opacity: 0.25;
  cursor: default;
  background: var(--btn-bg);
}

.nav-prev svg { margin-right: 1px; }
.nav-next svg { margin-left: 1px; }

@media (max-width: 640px) {
  .nav-btn { width: 36px; height: 36px; }
  #book-wrap { gap: 4px; }
}

/* --- page indicator --- */
#indicator {
  margin-top: 10px;
  color: var(--ink-dim);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* --- zoom controls --- */
#zoomControls {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 6;
}

.zoom-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--btn-bg);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.zoom-btn:hover,
.zoom-btn:focus-visible {
  background: var(--btn-bg-hover);
}

.zoom-btn:active { transform: scale(0.94); }

.zoom-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  #zoomControls { right: 10px; bottom: 10px; }
  .zoom-btn { width: 30px; height: 30px; }
}
