*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;background:#07142a;overscroll-behavior:none}
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:#eaf4f4;overflow:hidden;-webkit-text-size-adjust:100%}
/* fixed to the whole screen so the gradient + snow also cover the iPhone notch / home-bar area
   and don't leave gaps when the mobile address bar shows or hides */
.app{position:fixed;inset:0;display:flex;flex-direction:column;overflow:hidden;
  padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:radial-gradient(ellipse at 50% 110%,rgba(120,180,200,.35),transparent 60%),linear-gradient(180deg,#07142a 0%,#0f2f48 55%,#1a4a5e 100%)}
.snow{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:1}
.topbar,.stage,.thumbs,.controls{position:relative;z-index:2}
.topbar{padding:16px 24px 4px;text-align:center}
.topbar h1{font-size:15px;font-weight:500;letter-spacing:.08em;text-transform:uppercase;color:#f3dfa8;text-shadow:0 0 12px rgba(243,223,168,.35)}

/* ---------- stage (margins live here) ---------- */
.stage{position:relative;flex:1;min-height:0;display:flex;align-items:center;justify-content:center;overflow:hidden;padding:32px 96px}
.pan{width:100%;height:100%;display:flex;align-items:center;justify-content:center;transform-origin:center center;will-change:transform;transition:transform .35s cubic-bezier(.3,.7,.3,1)}
.pan.dragging{cursor:grabbing;transition:none}
.pan.zoomed{cursor:grab}
.pan.zoomed #book{pointer-events:none}

/* ---------- the book (pure CSS 3D) ---------- */
#book{position:relative;flex:none;transition:transform 1s cubic-bezier(.645,.045,.355,1);will-change:transform;cursor:pointer;user-select:none;-webkit-user-select:none;touch-action:pan-y}
#book.no-anim,#book.no-anim *{transition:none!important}
.leaf{position:absolute;top:0;left:50%;width:var(--pw);height:var(--ph);transform-origin:left center;transform-style:preserve-3d;
  transition:transform 1s cubic-bezier(.645,.045,.355,1);will-change:transform}
.leaf.flipped{transform:rotateY(-180deg)}
.face{position:absolute;inset:0;overflow:hidden;backface-visibility:hidden;-webkit-backface-visibility:hidden;background:#0b2f33}
.face.back{transform:rotateY(180deg)}
.face img{display:block;width:100%;height:100%;object-fit:cover;pointer-events:none;-webkit-user-drag:none}
.face.blank{background:#0e3a3f}

/* single-page view (<= 991px) */
/* the page turns over its left edge like a real sheet: it lifts, shows its paper back,
   swings off to the left and then fades out so it doesn't sit beside the book */
/* in one-page view nothing may show left of the page's spine edge: turned pages
   (and pages swinging back in) used to flash in the left margin */
#book.single{clip-path:inset(-60% -60% -60% 0)}
#book.single .leaf{left:0;transition:transform .8s cubic-bezier(.645,.045,.355,1),opacity 0s}
#book.single .leaf.flipped{transform:rotateY(-180deg);opacity:0;pointer-events:none;
  transition:transform .8s cubic-bezier(.645,.045,.355,1),opacity .15s linear .62s}
#book.single .face.front::before{display:none}
#book.single .face.back{background:linear-gradient(to left,#d9d2c3,#efe9dc 12%,#f6f1e6)}
#book.single .face.back::before{background:linear-gradient(to left,rgba(0,0,0,.28),rgba(0,0,0,0) 10%)}
/* soft shadow the lifting page casts on the page underneath */
#book.single .leaf .face.front{box-shadow:0 10px 24px -8px rgba(0,0,0,.4)}

/* spine shading */
.face::before{content:"";position:absolute;inset:0;pointer-events:none;z-index:2}
.face.front::before{background:linear-gradient(to right,rgba(0,0,0,.32),rgba(0,0,0,0) 7%)}
.face.back::before{background:linear-gradient(to left,rgba(0,0,0,.32),rgba(0,0,0,0) 7%)}
/* soft shadow under the book edges */
.leaf .face.front{box-shadow:0 14px 30px -10px rgba(0,0,0,.35)}
.leaf.flipped .face.front{box-shadow:none}

/* dynamic shade while turning (in sync with the 1s rotation) */
.shade{position:absolute;inset:0;background:#000;opacity:0;pointer-events:none;z-index:3}
.face.back .shade{opacity:.5}
.leaf.flipped .face.front .shade{opacity:.5;transition:opacity .5s ease-in}
.leaf:not(.flipped) .face.front .shade{opacity:0;transition:opacity .5s ease-out .5s}
.leaf.flipped .face.back .shade{opacity:0;transition:opacity .5s ease-out .5s}
.leaf:not(.flipped) .face.back .shade{opacity:.5;transition:opacity .5s ease-in}

/* corner peel on hover: the folded-back flap of the page corner */
.curl{position:absolute;left:0;top:0;width:0;height:0;z-index:100000;pointer-events:none;
  filter:drop-shadow(0 0 6px rgba(0,0,0,.45));
  transition:left .18s ease-out,top .18s ease-out,width .18s ease-out,height .18s ease-out}
.curl.instant{transition:none}
.curl .flap{width:100%;height:100%}
.curl.br .flap{clip-path:polygon(100% 0,0 100%,0 0);background:linear-gradient(to top left,#9e978a 50%,#ddd6c8 56%,#fbf8f1 78%,#e4ddcf 100%)}
.curl.tr .flap{clip-path:polygon(0 0,100% 100%,0 100%);background:linear-gradient(to bottom left,#9e978a 50%,#ddd6c8 56%,#fbf8f1 78%,#e4ddcf 100%)}
.curl.bl .flap{clip-path:polygon(0 0,100% 0,100% 100%);background:linear-gradient(to top right,#9e978a 50%,#ddd6c8 56%,#fbf8f1 78%,#e4ddcf 100%)}
.curl.tl .flap{clip-path:polygon(100% 0,100% 100%,0 100%);background:linear-gradient(to bottom right,#9e978a 50%,#ddd6c8 56%,#fbf8f1 78%,#e4ddcf 100%)}

.side-btn{position:absolute;top:50%;transform:translateY(-50%);z-index:5;width:44px;height:64px;border:0;border-radius:8px;
  background:rgba(255,255,255,.12);color:#fff;font-size:22px;cursor:pointer;transition:.2s}
.side-btn:hover{background:rgba(230,194,122,.5)}
.side-btn.left{left:12px}.side-btn.right{right:12px}
.side-btn:disabled{opacity:.25;cursor:default}

.loader{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#0a1a2c;z-index:20;transition:opacity .25s}
.loader.hide{opacity:0;pointer-events:none}
.spin{width:28px;height:28px;border:3px solid rgba(255,255,255,.18);border-top-color:#f3dfa8;border-radius:50%;animation:sp .7s linear infinite}
@keyframes sp{to{transform:rotate(360deg)}}
.face img{background:#0e3a3f}

.controls{margin-top:8px;display:flex;align-items:center;justify-content:center;gap:6px;padding:10px;background:rgba(7,20,42,.55);-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);border-top:1px solid rgba(255,255,255,.12);flex-wrap:wrap}
.controls button{width:38px;height:38px;border:0;border-radius:8px;background:rgba(255,255,255,.12);color:#fff;font-size:16px;cursor:pointer;transition:.2s}
.controls button:hover:not(:disabled){background:rgba(230,194,122,.55)}
.controls button:disabled{opacity:.3;cursor:default}
.controls button.active{background:#e6c27a;color:#0b2f33}
.counter,.zoom{min-width:64px;text-align:center;font-size:14px;font-variant-numeric:tabular-nums}
.sep{width:1px;height:24px;background:rgba(255,255,255,.2);margin:0 8px}

.thumbs{display:flex;gap:10px;padding:10px 16px;overflow-x:auto;background:rgba(7,20,42,.55);justify-content:center}
.thumbs[hidden]{display:none}
.thumbs img{height:70px;border-radius:4px;border:2px solid transparent;cursor:pointer;opacity:.65;transition:.2s;flex:0 0 auto}
.thumbs img:hover{opacity:1}
.thumbs img.current{border-color:#e6c27a;opacity:1}

.empty{margin:auto;text-align:center;opacity:.8}
.empty code{background:rgba(255,255,255,.12);padding:2px 6px;border-radius:4px}

@media (max-width:900px){ .stage{padding:20px 64px} }
@media (max-width:640px){
  .stage{padding:16px 14px}
  .side-btn{display:none}
  .sep{display:none}
  .topbar h1{font-size:12px}
}