/* Online reader: a full-screen page-turner, laid out like a reading app. */
:root {
  --reader-bg: #e8edf6;
  --reader-ink: #16181d;
  --reader-accent: #1e63c9;
  --reader-yellow: #ffd400;
}

html, body { height: 100%; }
.reader-body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--reader-bg);
  color: var(--reader-ink);
  font-family: "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
.reader-body:fullscreen { background: #d9e0ec; }

/* ----- top bar ----- */
.reader-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 2px solid var(--reader-ink);
}
.reader-back { color: var(--reader-ink); font-weight: 700; text-decoration: none; white-space: nowrap; }
.reader-back:hover { color: var(--reader-accent); }
.reader-title { margin: 0; font-weight: 700; flex: 1; text-align: center; }
.reader-count { margin: 0; font-variant-numeric: tabular-nums; min-width: 6em; text-align: right; }
.reader-full {
  font: inherit;
  font-weight: 700;
  padding: 6px 12px;
  border: 2px solid var(--reader-ink);
  border-radius: 8px;
  background: var(--reader-yellow);
  color: var(--reader-ink);
  cursor: pointer;
  white-space: nowrap;
}

/* ----- stage with the two turn buttons ----- */
.reader-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
}

.turn {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--reader-ink);
  background: var(--reader-yellow);
  color: var(--reader-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.turn svg { width: 36px; height: 36px; }
.turn:hover:not(:disabled) { background: #fff; transform: scale(1.06); }
.turn:active:not(:disabled) { transform: scale(0.94); }
.turn:disabled { opacity: 0.35; cursor: default; }
.turn:focus-visible, .reader-full:focus-visible, .reader-back:focus-visible {
  outline: 3px solid var(--reader-accent);
  outline-offset: 3px;
}

/* ----- the page ----- */
.book-frame {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.page-box {
  position: relative;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 148 / 210;
  max-width: 100%;
  perspective: 1600px;
  background: #fff;
  border: 2px solid var(--reader-ink);
  border-radius: 4px;
  overflow: hidden;
}
.page-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* The page that turns. Its front face is the page it leaves; its back face is the page it reveals. */
.leaf {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform 0.7s cubic-bezier(0.45, 0.05, 0.25, 1);
  display: none;
  pointer-events: none;
}
.leaf.is-visible { display: block; }
.leaf .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fff;
}
.leaf .face img { width: 100%; height: 100%; object-fit: contain; display: block; }
.leaf .back { transform: rotateY(180deg); }
/* a soft fold line as the page turns */
.leaf::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(22, 24, 29, 0.18), rgba(22, 24, 29, 0));
  opacity: 0;
  transition: opacity 0.7s ease;
  pointer-events: none;
}
.leaf.is-turning::after { opacity: 1; }

.reader-foot {
  margin: 0;
  padding: 6px 12px 10px;
  text-align: center;
  font-size: 0.9rem;
  color: #4b5366;
}
.reader-foot p { margin: 0; }
kbd {
  font-family: Consolas, monospace;
  border: 1px solid #9aa3b5;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  background: #fff;
}

/* ----- small screens: buttons sit under the page, so the page gets the full width ----- */
@media (max-width: 640px) {
  .reader-bar { flex-wrap: wrap; gap: 6px; }
  .reader-title { order: 3; flex-basis: 100%; font-size: 0.95rem; }
  .reader-stage { gap: 4px; padding: 6px; }
  .turn { width: 48px; height: 48px; }
  .turn svg { width: 26px; height: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .leaf, .leaf::after { transition: none; }
}
