/* Book Viewer — the shared read-only book component (docs/BOOK-VIEWER-
   PLAN.md, simplified from mock C3: stage + filmstrip, no side panel).
   Used by the user app and by admin. Colors ride on the host page's
   tokens with fallbacks so admin needs no extra setup. */

.bv{--bv-ink:var(--ink,#1f2933); --bv-mut:var(--mut,#7b8794);
  --bv-line:var(--line,#e4e7eb); --bv-acc:var(--acc,#1f2a44);
  --bv-accsoft:var(--accsoft,#e9ecf3); --bv-card:var(--card,#fff);
  --bv-stagebg:#efece7;
  border:1px solid var(--bv-line); border-radius:12px; overflow:hidden;
  background:var(--bv-card); display:flex; flex-direction:column;
  font-size:14px; color:var(--bv-ink)}

/* ---- stage ---- */
.bv-stage{position:relative; background:var(--bv-stagebg); overflow:hidden;
  height:520px; cursor:grab; touch-action:none}
.bv-stage.bv-panning{cursor:grabbing}
.bv-canvas{position:absolute; left:50%; top:50%; transform-origin:center}
.bv-pgstage{display:flex; filter:drop-shadow(0 12px 22px rgba(31,41,51,.22))}
.bv-clip{overflow:hidden; flex:none; position:relative}
.bv-clip + .bv-clip{border-left:1px solid rgba(31,41,51,.15)}
.bv-void{flex:none}
.bv-frame{display:block; border:0; background:#fff}
/* the stage's pages are iframes: a finger (or mouse) landing on one would
   be the iframe's, not the stage's — no swipe, no pan. The pages are
   pictures here; all input belongs to the stage. */
.bv-stage .bv-frame{pointer-events:none}
.bv-clip .bv-frame{position:absolute; top:0; left:0}
.bv-arrow{position:absolute; top:50%; transform:translateY(-50%); z-index:5;
  width:40px; height:40px; border-radius:50%; border:1px solid var(--bv-line);
  background:var(--bv-card); color:var(--bv-ink); font-size:17px;
  box-shadow:0 2px 8px rgba(31,41,51,.12)}
.bv-arrow:hover{background:var(--bv-accsoft)}
.bv-arrow:disabled{opacity:.25; cursor:default}
.bv-arrow.bv-l{left:12px}.bv-arrow.bv-r{right:12px}
.bv-zoom{position:absolute; right:12px; top:12px; display:flex; gap:6px; z-index:5}
/* phones: the zoom cluster moves to the bottom-right corner (the page
   label holds bottom-left) instead of sitting on the cover */
@media (max-width:640px){
  .bv-zoom{top:auto; bottom:10px; right:10px; gap:4px}
  .bv-zoom .bv-zc{width:30px; height:30px; font-size:13px}
}
.bv-zc{width:34px; height:34px; border-radius:8px; border:1px solid var(--bv-line);
  background:var(--bv-card); color:var(--bv-ink); font-size:15px;
  box-shadow:0 2px 6px rgba(31,41,51,.1)}
.bv-zc:hover{background:var(--bv-accsoft)}
.bv-label{position:absolute; left:12px; bottom:10px; z-index:5; font-size:12.5px;
  color:var(--bv-mut); background:rgba(255,255,255,.85); padding:3px 10px;
  border-radius:999px}
.bv-label b{color:var(--bv-ink); font-weight:600}

/* a deliberate blank page wears a quiet watermark (issue #4): the same
   markup scales down into the filmstrip miniatures, so empty paper never
   reads as a failed render */
.bv-blankmark{position:absolute; inset:0; display:flex; align-items:center;
  justify-content:center; font-size:12px; letter-spacing:.4em;
  text-indent:.4em; text-transform:uppercase; color:rgba(31,41,51,.26);
  pointer-events:none; user-select:none}

/* ---- filmstrip: true miniatures of the very sheets on the stage ---- */
.bv-strip{display:flex; gap:8px; padding:10px 12px; overflow-x:auto;
  border-top:1px solid var(--bv-line); background:#f6f4f1;
  align-items:flex-end}
.bv-thumb{flex:0 0 auto; border:2px solid transparent; border-radius:6px;
  padding:3px; background:none; text-align:center}
.bv-thumb[aria-current="true"]{border-color:var(--bv-acc); background:var(--bv-card)}
.bv-tframe{display:block; position:relative; overflow:hidden}
.bv-mini{position:absolute; left:0; top:0; transform-origin:0 0;
  pointer-events:none}
.bv-mini .bv-clip, .bv-mini > .bv-pgstage > .bv-frame{
  box-shadow:0 1px 6px rgba(31,41,51,.25)}
.bv-mini .bv-pgstage{filter:none}
.bv-tlabel{display:block; font-size:10px; color:var(--bv-mut); padding-top:3px}
/* standalone cover miniature (BookViewer.coverThumb) */
.bv-coverthumb{border-radius:2px; box-shadow:0 1px 4px rgba(31,41,51,.3)}
.bv-thumb[aria-current="true"] .bv-tlabel{color:var(--bv-acc); font-weight:600}

/* ---- fullscreen: native element fullscreen or the fixed-overlay
   fallback (iOS Safari) — same class either way ---- */
.bv.bv-fs{position:fixed; inset:0; z-index:1000; border:0; border-radius:0;
  width:100%; height:100%}
.bv.bv-fs .bv-stage{height:auto; flex:1; min-height:0}
.bv-fslock{overflow:hidden}    /* on <html>: no page scroll behind */
/* native fullscreen sizes the element itself */
.bv:fullscreen{width:100%; height:100%}

/* ---- reading mode (full screen on a phone, book-viewer.js setReading):
   the book on a dark ground, nothing else; a swipe turns the page, a tap
   shows the one bar over the top edge ---- */
.bv-readbar{display:none}
.bv.bv-read .bv-strip, .bv.bv-read .bv-arrow, .bv.bv-read .bv-zoom,
.bv.bv-read .bv-label{display:none}
.bv.bv-read .bv-stage{background:#262b33; cursor:default}
.bv.bv-read .bv-pgstage{filter:drop-shadow(0 10px 24px rgba(0,0,0,.5))}
.bv.bv-read .bv-readbar{display:flex; position:absolute; left:0; right:0; top:0; z-index:6;
  align-items:center; gap:8px; color:#fff;
  padding:calc(10px + env(safe-area-inset-top, 0px)) 14px 22px;
  background:linear-gradient(rgba(20,24,30,.72), rgba(20,24,30,0));
  opacity:0; pointer-events:none; transition:opacity .25s}
.bv.bv-read .bv-readbar.bv-show{opacity:1; pointer-events:auto}
.bv-rlabel{flex:1; min-width:0; font-size:13px; white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis; color:rgba(255,255,255,.8); text-shadow:0 1px 2px rgba(0,0,0,.4)}
.bv-rlabel b{color:#fff; font-weight:600}
.bv-rmode, .bv-rclose{flex:none; height:32px; border-radius:999px; font:inherit; font-size:12.5px;
  font-weight:600; color:#fff; border:1px solid rgba(255,255,255,.45);
  background:rgba(20,24,30,.45); padding:0 12px; cursor:pointer}
.bv-rclose{width:32px; padding:0; font-size:15px}
@media (prefers-reduced-motion: reduce){ .bv.bv-read .bv-readbar{transition:none} }

@media (max-width: 860px){
  .bv-stage{height:390px}
  .bv-arrow{width:34px; height:34px}
  .bv-zc{width:31px; height:31px}
}
/* phones: the stage fits the screen. Portrait: what is left under the
   bars, the title and over the footer and the filmstrip (≈340px of
   chrome), never below 240. Landscape: the page height less the host's
   footer (--barh) — the bars above scroll away, the filmstrip is a
   scroll below. dvh first (Safari 15.4+), vh as the fallback. */
@media (max-width: 560px){
  .bv-stage{height:clamp(240px, calc(100vh - 340px), 390px);
    height:clamp(240px, calc(100dvh - 340px), 390px)}
}
@media (max-height: 500px){
  .bv-stage{height:calc(100vh - var(--barh, 64px) - 28px);
    height:calc(100dvh - var(--barh, 64px) - 28px)}
}
