/* Memolio book viewer — 5 Aug 2026 (session: example-book-refresh)
   Paired with js/book-viewer.js. Shared by index.html + de/index.html. */

.bv {
  position: fixed; inset: 0; z-index: 10000;   /* must clear .paper-grain, which sits at 9999 */
  background: rgba(38, 30, 22, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px 12px 8px;
}
.bv[hidden] { display: none; }

/* Two site-wide overlays fight a reading modal and both have to stand down while it is open:
   - header carries `backdrop-filter: blur(10px)`, which Chrome composites ABOVE later content
     regardless of z-index, so the nav bar floated over the darkened backdrop;
   - .paper-grain is a full-viewport `mix-blend-mode: multiply` layer at z-index 9999 that would
     otherwise tint the book pages a dirty brown.
   Both are restored the moment the viewer closes. */
body.bv-open header { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; z-index: 1 !important; }
body.bv-open .paper-grain { display: none !important; }

.bv-close {
  position: absolute; top: 14px; right: 18px;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.12); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer;
}
.bv-close:hover { background: rgba(255,255,255,0.22); }

.bv-stage {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 1180px; flex: 1 1 auto; min-height: 0;
}

/* The book itself. `perspective` on the parent is what makes the leaf turn read as 3D. */
.bv-book {
  position: relative;
  display: flex; align-items: stretch; justify-content: center;
  height: min(82vh, 760px);
  perspective: 2600px;
  flex: 0 1 auto;
}
.bv-side { position: relative; height: 100%; }
.bv-side img {
  display: block; height: 100%; width: auto; max-width: 100%;
  box-shadow: 0 18px 46px rgba(0,0,0,0.45);
  background: #F3E9D6;
}
/* the spine shadow — sells the gutter far more than any gradient on the page itself */
.bv-side-l img { border-radius: 3px 0 0 3px; }
.bv-side-r img { border-radius: 0 3px 3px 0; }
.bv-book::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 26px;
  transform: translateX(-50%); pointer-events: none; z-index: 3;
  background: linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,0.28) 45%, rgba(0,0,0,0.28) 55%, rgba(0,0,0,0) 100%);
}
.bv.bv-single .bv-side-r { display: none; }
.bv.bv-single .bv-book::after { display: none; }
.bv.bv-single .bv-side-l img { border-radius: 3px; }

/* The turning leaf sits over one half and rotates about the spine. */
.bv-leaf {
  position: absolute; top: 0; height: 100%; width: 50%;
  display: none; transform-style: preserve-3d; z-index: 4;
  transition: transform 620ms cubic-bezier(.35,.02,.28,1);
}
.bv-leaf-right { left: 50%; transform-origin: left center; transform: rotateY(0deg); }
.bv-leaf-left  { left: 0;   transform-origin: right center; transform: rotateY(0deg); }
.bv-leaf-right.bv-turn-f { transform: rotateY(-178deg); }
.bv-leaf-left.bv-turn-b  { transform: rotateY(178deg); }
.bv.bv-single .bv-leaf { width: 100%; left: 0; }
.bv.bv-single .bv-leaf-right { transform-origin: left center; }

.bv-face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; }
.bv-face img { display: block; height: 100%; width: 100%; object-fit: contain; background: #F3E9D6; }
.bv-face-f { box-shadow: 0 18px 46px rgba(0,0,0,0.45); }
.bv-face-b { transform: rotateY(180deg); }

.bv-arrow {
  flex: 0 0 auto;
  width: 52px; height: 52px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.14); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer;
}
.bv-arrow:hover:not(:disabled) { background: rgba(255,255,255,0.26); }
.bv-arrow:disabled { opacity: 0.25; cursor: default; }

.bv-counter {
  margin: 12px 0 0; color: rgba(255,255,255,0.82);
  font-family: 'Quicksand', sans-serif; font-size: 0.86rem; letter-spacing: 0.02em;
}

@media (max-width: 767px) {
  .bv { padding: 12px 6px 6px; }
  /* 23 Aug 2026 (session: mobile-device-sweep): the arrows used to sit BESIDE the page and
     clamp its width while `height:100%` pinned its height — every page rendered ~0.48 aspect
     instead of 0.71 on phones (MASTER_ISSUES BOOKVIEWER-MOBILE-SQUASH). Overlay the arrows and
     cap the book height by the width actually available so the A4 aspect (1:1.414) always fits. */
  .bv-book { height: min(74vh, 640px, calc((100vw - 24px) * 1.414)); }
  .bv-stage { position: relative; gap: 4px; }
  .bv-arrow {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 6;
    width: 44px; height: 44px; font-size: 26px;
    background: rgba(38, 30, 22, 0.45);
  }
  .bv-prev { left: 4px; }
  .bv-next { right: 4px; }
}

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