.viewer-page {
  height: 100vh; height: 100dvh; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  background: radial-gradient(1400px 800px at 50% 40%, #155e5b 0%, #0c3f3d 55%, #082c2b 100%);
  color: #fff; overscroll-behavior: none;
}

/* Top bar */
.vbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--teal); box-shadow: 0 2px 12px rgba(0,0,0,.18); position: relative; z-index: 5; }
.vbar-logo { display: flex; align-items: center; flex: none; min-width: 0; }
.vbar, .vfoot, .stage { min-width: 0; }
.vbar-logo img { height: 36px; width: auto; display: block; }
.vbar-title { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vbar-actions { display: flex; gap: 2px; flex: none; }

.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; border: 0;
  background: transparent; color: inherit; cursor: pointer; text-decoration: none; }
@media (hover: hover) { .icon-btn:hover { background: rgba(255,255,255,.14); } }
.icon-btn:active { background: rgba(255,255,255,.2); }
.icon-btn:focus-visible { outline: 2px solid var(--lime); outline-offset: 1px; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.active { background: rgba(255,255,255,.2); }
.icon-btn .off { display: none; }
.icon-btn.muted .on { display: none; }
.icon-btn.muted .off { display: inline; }
.icon-btn.muted { opacity: .75; }

/* Stage + book */
.stage { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.book { position: absolute; left: 50%; top: 50%; transform: translate(calc(-50% + var(--shift, 0px)), -50%); perspective: 2600px;
  transition: transform .6s cubic-bezier(.45,.05,.35,1), opacity .16s ease, scale .16s ease; }
.book.switching { opacity: 0; scale: .97; }
.slot { position: absolute; top: 0; height: 100%; background: transparent; }
.slot.has-page { background: #fff; box-shadow: 0 18px 50px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.25); }
.slot img, .face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; -webkit-user-drag: none; }
.spread .slot-left.has-page::after, .spread .slot-right.has-page::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40px; pointer-events: none;
}
.spread .slot-left.has-page::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.18), rgba(0,0,0,0)); }
.spread .slot-right.has-page::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,.2), rgba(0,0,0,0)); }

.sheet { position: absolute; top: 0; height: 100%; transform-style: preserve-3d; transform-origin: left center; z-index: 3; will-change: transform; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fff; overflow: hidden; }
.face-back { transform: rotateY(180deg); }
.face-back.blank { background: linear-gradient(to left, #f3f3f1, #e9e9e6); }
.face .shade { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.face-front .shade { background: linear-gradient(to left, rgba(0,0,0,.28), rgba(0,0,0,0) 60%); }
.face-back .shade { background: linear-gradient(to right, rgba(0,0,0,.28), rgba(0,0,0,0) 60%); }

.ph { position: absolute; inset: 0; display: grid; place-items: center; background: #fff; }
.ph-cover { background: #fff center / 100% 100% no-repeat; }
.ph-cover::after { display: none; }
.ph::after { content: ""; width: 28px; height: 28px; border-radius: 50%; border: 3px solid #d7e4e3; border-top-color: var(--teal); animation: spin .9s linear infinite; }

/* Side navigation */
.nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.1); color: #fff; cursor: pointer; display: grid; place-items: center; z-index: 4; transition: background .15s, opacity .15s; }
.nav:hover { background: rgba(255,255,255,.22); }
.nav:disabled { opacity: 0; pointer-events: none; }
.nav svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-prev { left: 12px; }
.nav-next { right: 12px; }

/* Footer */
.vfoot { display: flex; align-items: center; gap: 14px; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
#scrub { flex: 1; accent-color: var(--lime); height: 24px; cursor: pointer; }
.pageno { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-size: 14px; color: rgba(255,255,255,.85); }
.pageno input { width: 48px; text-align: center; padding: 4px 6px; border-radius: 6px; border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.2); color: #fff; }

/* Loading (with the cover shown while the file downloads) */
.loading .preview { max-width: calc(100% - 168px); max-height: calc(100% - 40px); box-shadow: 0 18px 50px rgba(0,0,0,.35); background: #fff; }
.loading.with-preview { place-content: center; }
.loading.with-preview .progress, .loading.with-preview p { position: absolute; left: 50%; transform: translateX(-50%); }
.loading.with-preview .progress { bottom: 34px; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.loading.with-preview p { bottom: 6px; margin: 0; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.6); white-space: nowrap; }
@media (max-width: 699px) { .loading .preview { max-width: calc(100% - 24px); max-height: calc(100% - 16px); } }
.progress { width: min(240px, 60vw); height: 4px; border-radius: 4px; background: rgba(255,255,255,.18); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--lime); transition: width .2s; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; color: rgba(255,255,255,.85); }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--lime); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Thumbnails panel */
.thumbs { position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); background: #fff; color: var(--ink); z-index: 20;
  box-shadow: -10px 0 40px rgba(0,0,0,.3); display: flex; flex-direction: column; }
.thumbs-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.thumbs-grid { flex: 1; overflow: auto; padding: 14px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; align-content: start; }
.thumb { border: 0; padding: 0; background: none; cursor: pointer; display: grid; gap: 4px; text-align: center; font-size: 12px; color: var(--muted); }
.thumb-img { position: relative; width: 100%; background: #f1f4f4; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.15); outline: 3px solid transparent; }
.thumb-img img { position: absolute; inset: 0; width: 100%; height: 100%; }
.thumb.current .thumb-img { outline-color: var(--teal); }
@media (hover: hover) { .thumb:hover .thumb-img { outline-color: var(--teal-light); } }

/* Zoom: the book sits in a layer that is scaled with a transform */
.zoomlayer { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.zoomlayer.anim { transition: transform .28s cubic-bezier(.2,.7,.2,1); }
.stage.zoomed { cursor: grab; }
.stage.zoomed.panning { cursor: grabbing; }
.stage.zoomed .nav { opacity: 0; pointer-events: none; }
.zoombar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 2px;
  padding: 4px; border-radius: 12px; background: rgba(8,44,43,.82); backdrop-filter: blur(6px); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.zoombar span { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); background: #fff; color: var(--ink); padding: 10px 16px;
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.3); font-size: 14px; z-index: 30; }
.noscript { text-align: center; padding: 40px 16px; }
.noscript a { color: var(--lime); }

@media (max-width: 640px) {
  .vbar { gap: 8px; padding-left: 8px; padding-right: 4px; }
  .vbar-logo img { height: 28px; max-width: 96px; object-fit: contain; }
  .vfoot { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .vbar-title { font-size: 14px; }
  .icon-btn { width: 36px; height: 36px; }
  .hide-sm { display: none; }
  .nav { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none !important; }
}
