:root {
  --ink: #001e2b;
  --ink-deep: #00131b;
  --muted: #9fb6c0;
  --accent: #72c9d8;
  --paper: #ffffff;
  --flip-ms: 820ms;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(120% 90% at 50% 0%, #06303f 0%, var(--ink) 46%, var(--ink-deep) 100%);
  color: #e8f1f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.reader {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.eyebrow {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.identity h1 {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
}

.quiet-button,
.icon-button,
.nav-button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.quiet-button:hover,
.icon-button:hover,
.nav-button:hover:not(:disabled) {
  background: rgba(114, 201, 216, 0.18);
  border-color: rgba(114, 201, 216, 0.5);
}

.icon-button {
  padding: 0.5rem 0.7rem;
}

.nav-button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 1.1rem 1rem;
}

.loading-panel {
  display: grid;
  place-items: center;
  max-width: 26rem;
  color: var(--muted);
  text-align: center;
}

.loading-mark {
  width: 2.4rem;
  height: 2.4rem;
  margin-bottom: 0.8rem;
  border: 3px solid rgba(114, 201, 216, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

.book-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

/* ---------- the book ---------- */

.book {
  position: relative;
  display: flex;
  perspective: 2600px;
  perspective-origin: 50% 45%;
  transition: transform var(--flip-ms) cubic-bezier(0.35, 0.02, 0.24, 1);
  filter: drop-shadow(0 26px 46px rgba(0, 0, 0, 0.55));
}

/* When the book is shut, slide it across so the cover sits centre-stage. */
.book.closed {
  transform: translateX(-25%);
}

.half {
  position: relative;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
}

.half.empty {
  background: transparent;
  box-shadow: none;
}

/* Gutter shading — the darkening every book has towards its spine. */
.half.left::after,
.half.right::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.half.left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.19), rgba(0, 0, 0, 0) 9%);
}

.half.right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.19), rgba(0, 0, 0, 0) 9%);
}

.half.empty::after {
  background: none;
}

.spine {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 100%;
  transform: translateX(-1px);
  background: rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.book.closed .spine {
  opacity: 0;
}

.half canvas,
.face canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- the turning leaf ---------- */

.leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  pointer-events: none;
  will-change: transform;
}

.leaf[hidden] {
  display: none;
}

.leaf.forward {
  left: 50%;
  transform-origin: left center;
}

.leaf.backward {
  left: 0;
  transform-origin: right center;
}

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  background: var(--paper);
}

.face.back {
  transform: rotateY(180deg);
}

/* Sweeping shadow that reads as the page catching the light mid-turn. */
.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.face.front .shade {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.05) 55%);
}

.face.back .shade {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.05) 55%);
}

/* ---------- click zones ---------- */

.turn-zone {
  position: absolute;
  top: 0;
  width: 22%;
  height: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 3;
}

.turn-zone.prev {
  left: 0;
}

.turn-zone.next {
  right: 0;
}

.turn-zone:disabled {
  cursor: default;
}

/* ---------- controls ---------- */

.controls {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  padding: 0.7rem 1.4rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.navigation {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.page-field input {
  width: 4.2rem;
  padding: 0.42rem 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: inherit;
  text-align: center;
}

.status-message,
.hint {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.hint {
  color: rgba(159, 182, 192, 0.62);
}

@media (max-width: 720px) {
  .identity h1 {
    font-size: 0.9rem;
  }
  .nav-copy {
    display: none;
  }
  .hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book,
  .leaf {
    transition-duration: 1ms !important;
  }
}

/* ---------- single-page mode ---------- */
/* One page at a time, still turning like a leaf. Keeps the landscape section
   readable, where a full spread squashes both pages. */

.book.single .half.left {
  display: none;
}

.book.single .half.right {
  width: 100%;
}

.book.single .half.right::after,
.book.single .spine {
  display: none;
}

.book.single .leaf {
  width: 100%;
  left: 0;
  transform-origin: left center;
}

.book.single .face.back {
  background: linear-gradient(to left, #f4f1ea, #fbfaf7 60%);
}

/* ---------- zoom ---------- */
/* Zooming re-renders the page from the PDF at the larger size rather than
   magnifying the bitmap, so the text stays sharp however close you get. */

.zoom-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: 1fr auto;
  background: rgba(0, 12, 18, 0.96);
}

.zoom-scroll {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 0.75rem;
  overscroll-behavior: contain;
  cursor: grab;
}

.zoom-scroll.dragging {
  cursor: grabbing;
}

.zoom-holder {
  display: block;
  margin: auto;
  background: #fff;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);
}

.zoom-holder canvas {
  display: block;
}

.zoom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.zoom-label {
  min-width: 3.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
}

.zoom-page {
  font-size: 0.78rem;
  color: rgba(159, 182, 192, 0.7);
}

.book-zoomable {
  cursor: zoom-in;
}
