/* ============================================================
   The Wedding of Hana & Raihan — flipbook invitation
   Layout units: every page is a container, so 1cqw = 1% of page
   width and 1cqh = 1% of page height. All geometry below is taken
   straight from the original A4 design (595.5 x 842.25 pt).
   ============================================================ */

:root{
  --paper:#e3caaf;
  --brown:#472521;
  --brown2:#3e241d;
  --maroon:#40010f;
  --cream:#fcf4e9;
  --cream2:#f8f3ee;
  --cream3:#f3f2ed;
  --tan:#c4ae8f;
  --mid:#6b5249;
  --red:#cc3827;
  --olive:#a7a58f;

  --f-script:'Great Vibes',cursive;
  --f-pinyon:'Pinyon Script',cursive;
  --f-serif:'Playfair Display',serif;
  --f-sans:'Jost',system-ui,sans-serif;
  --f-alice:'Alice',serif;

  /* Page-turn timing. Paper resists at first, sweeps through the middle,
     then flops the last few degrees and settles — the tail goes just past
     1 and comes back, which is that final flop. */
  --ease-flip:cubic-bezier(.3,.03,.18,1);
  --ease-paper:var(--ease-flip);
  --ease-drop:cubic-bezier(.22,.78,.3,1);   /* releasing a dragged page */
  --flip-ms:900ms;
  --flip:var(--flip-ms) var(--ease-flip);
}

@supports (transition-timing-function:linear(0,1)){
  :root{
    --ease-paper:linear(
      0, 0.0045 4.5%, 0.0185 9%, 0.043 13.5%, 0.079 18%, 0.129 22.5%,
      0.195 27%, 0.277 31.5%, 0.374 36%, 0.48 40.5%, 0.588 45%,
      0.690 49.5%, 0.779 54%, 0.853 58.5%, 0.911 63%, 0.952 67.5%,
      0.979 72%, 0.995 76.5%, 1.0038 81%, 1.0045 86%, 1.0022 91%, 1);
  }
}

/* animatable progress of a turning sheet: 0 = closed, 1 = fully turned.
   Registered so it can be transitioned, which drives all the fold shading. */
@property --p{syntax:"<number>";inherits:true;initial-value:0}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:#241310 radial-gradient(120% 90% at 50% 0%,#52302a 0%,#241310 70%);
  font-family:var(--f-sans);
  color:var(--cream);
  overflow:hidden;
  -webkit-tap-highlight-color:transparent;
}

/* ---------- loader ---------- */
.loader{position:fixed;inset:0;z-index:90;display:grid;place-content:center;justify-items:center;gap:18px;
  background:#241310;transition:opacity .6s ease,visibility .6s}
.loader.hide{opacity:0;visibility:hidden}
.loader p{margin:0;font-size:14px;letter-spacing:.18em;text-transform:uppercase;color:#c9ab8e}
.loader__seal{width:54px;height:54px;border-radius:50%;border:2px solid #8d6b4f;border-top-color:transparent;
  animation:spin 1.1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* ---------- stage & book ---------- */
.stage{position:fixed;inset:0;display:grid;place-items:center;padding:clamp(8px,2vmin,28px);
  opacity:0;transform:translateY(10px) scale(.985);
  transition:opacity .7s ease,transform .9s var(--ease-flip)}
.stage.in{opacity:1;transform:none}
/* --persp is set from the book's own height in sizeBook(), so the eye sits
   the same distance from the page whether the book is a two-page spread on
   a laptop or one page on a phone. The old fixed 2400px was more than three
   times the width of the book on a desktop, which is nearly an orthographic
   view: a page standing up barely changed shape, so the turn read as a flat
   card being rotated rather than paper lifting towards you. */
.book{position:relative;perspective:var(--persp,1700px);perspective-origin:50% 44%;
  touch-action:none;cursor:grab}
.book.grabbing{cursor:grabbing}
.book::after{ /* soft drop shadow under the whole book */
  content:"";position:absolute;left:4%;right:4%;bottom:-2.4%;height:4.5%;
  background:radial-gradient(50% 100% at 50% 0,rgba(0,0,0,.5),transparent 72%);
  filter:blur(7px);pointer-events:none}

/* --p alone drives the turn: the rotation, the arc the paper lifts into,
   the way it narrows as it bows, and every shadow below all read from it,
   so an animated turn and a dragged one go through exactly the same states.
   --bend runs 0 → 1 → 0 across the turn, peaking when the page is edge-on. */
.sheet{position:absolute;top:0;height:100%;transform-style:preserve-3d;--p:0;
  --bend:calc(var(--p) * (1 - var(--p)) * 4);
  transform:
    translateZ(calc(var(--bend) * 26px))
    rotateY(calc(var(--p) * -180deg))
    scaleX(calc(1 - var(--bend) * 0.045))}
.book.spread .sheet{left:50%;width:50%;transform-origin:left center}
.book.single .sheet{left:0;width:100%;transform-origin:left center}
.sheet.flipped{--p:1}
.sheet.active{will-change:transform}

.face{position:absolute;inset:0;backface-visibility:hidden;overflow:hidden;background:#ece2d3}
.face.back{transform:rotateY(180deg)}
.face.blank{background:#ece2d3 url(../img/paper.webp) center/cover}

/* --- fold shading -------------------------------------------------------
   Every face carries two overlays. `.gutter` is the permanent crease next to
   the spine; `.lift` darkens as the sheet lifts off the stack, and a thin
   sheen runs along the fold. Both read --p, so they stay in step with the
   turn whether it is animated or dragged by hand. The spine is always at the
   face's own left edge: the back face is mirrored, so its left edge lands on
   the screen's right side exactly where the gutter belongs. */
.gutter,.lift{position:absolute;inset:0;pointer-events:none}
.gutter{background:
  linear-gradient(90deg,rgba(56,33,24,.30) 0%,rgba(56,33,24,.10) 5%,rgba(56,33,24,.02) 12%,transparent 20%);
  opacity:calc(.8 + var(--bend) * .2)}
.book.single .gutter{opacity:.35}

/* three reads of the same light: a catch-light on the free edge where the
   sheet curls up, a sheen along the fold, and the body shadow that deepens
   towards the spine */
.lift{background:
  linear-gradient(270deg,rgba(255,249,238,.50) 0%,rgba(255,249,238,0) 2.6%),
  linear-gradient(90deg,rgba(255,246,232,.40) 0%,rgba(255,246,232,0) 6%),
  linear-gradient(90deg,rgba(38,20,14,.62) 0%,rgba(38,20,14,.27) 25%,
                  rgba(38,20,14,.07) 56%,transparent 80%)}
.face.front .lift{opacity:calc(var(--p) * 1.35)}
.face.back  .lift{opacity:calc((1 - var(--p)) * 1.35)}

/* paper that sits under the left half once the book is open, so a turning
   sheet lifts off a page rather than off the backdrop */
.base{position:absolute;top:0;height:100%;pointer-events:none;
  background:#ece2d3 url(../img/paper.webp) center/cover;
  opacity:0;transition:opacity .3s ease}
.base::after{content:"";position:absolute;inset:0;
  background:linear-gradient(270deg,rgba(56,33,24,.3) 0%,rgba(56,33,24,.08) 6%,transparent 16%)}
.book.spread .base{left:0;width:50%}
.book.spread.opened .base{opacity:1}
.book.single .base{display:none}

/* --- peeling paper ------------------------------------------------------
   Mid-turn the sheet is drawn twice over. What is still lying on the book
   is the ordinary flat face, clipped to the near side of the fold line, so
   it keeps its own crease and costs nothing. What has gone over is a row of
   narrow panels laid along the roll, each shaded on its own angle — that
   per-panel light is what makes the bend readable. The panels exist only
   for the sheet actually moving and are thrown away the moment it lands,
   where they coincide exactly with the flat face, so the handover is
   invisible. The geometry is worked out in app.js; see the long note there.

   Note: any clipping (overflow, clip-path) flattens a preserve-3d element,
   so the strip itself never clips; its two faces do, and they are leaves. */
.sheet.curling{transform:none}
.sheet.curling > .face.back{visibility:hidden}
/* paper still on the book is not lifting, so it carries no lift shading */
.sheet.curling > .face.front > .lift{opacity:0}

.curl{position:absolute;left:0;top:0;width:100%;height:100%;
  transform-origin:0 0;transform-style:preserve-3d;pointer-events:none}
.strip{position:absolute;left:0;transform-origin:left center;
  transform-style:preserve-3d}
/* left:-OVER with right:0 widens the face by the overlap without anyone
   having to write a width every frame; the leading panel has nothing
   behind it to overlap, so it starts flush */
.sface{position:absolute;left:calc(0px - var(--over,5px));right:0;top:0;height:100%;
  overflow:hidden;backface-visibility:hidden}
.sface.lead{left:0}
.sface.sback{transform:rotateY(180deg)}
/* Every panel is a different width on every frame, and without this each
   of those writes drags a whole page copy — a dozen images and their
   container queries — back through layout. The copy is a fixed page-sized
   box whose contents never reach outside it, so nothing is lost by saying
   so, and the frame cost drops by more than half. */
.slice{position:absolute;left:0;top:0;transform-origin:0 0;contain:strict}
.slice.blank{background:#ece2d3 url(../img/paper.webp) center/cover}
.slice > .page{position:absolute;top:0}
/* Roll shading. It fills the face exactly, so it is clipped on the very
   same edge as the artwork and no line is drawn down the seam. Declaring
   the two stops as non-inheriting is what keeps them cheap: written on a
   leaf, a change restyles that leaf and nothing under it. The back face is
   mirrored, so its gradient runs the other way to keep the fold end of the
   panel the darker one on screen. */
@property --s1{syntax:"<number>";inherits:false;initial-value:0}
@property --s2{syntax:"<number>";inherits:false;initial-value:0}
.sface > .shade{position:absolute;inset:0;display:block;pointer-events:none;
  background:linear-gradient(90deg,rgba(43,23,16,var(--s1)),rgba(43,23,16,var(--s2)))}
.sface.sback > .shade{
  background:linear-gradient(270deg,rgba(43,23,16,var(--s1)),rgba(43,23,16,var(--s2)))}

/* The same three reads of the light the flat faces carry in .lift, drawn
   once across the whole page and sliced by each panel — see the note in
   app.js. It rides inside .slice, which is page-sized and already carries
   the transform that places the page, so the spine end of the gradient
   always lands on the spine end of the page. --p inherits from the sheet,
   so it fades in and out exactly as the flat face does and the handover
   stays invisible. app.js sets the opacity per frame, straight on to each
   one — see the note there. */
.slice > .sheen{position:absolute;inset:0;display:block;pointer-events:none;opacity:0;
  background:
    linear-gradient(270deg,rgba(255,249,238,.50) 0%,rgba(255,249,238,0) 2.6%),
    linear-gradient(90deg,rgba(255,246,232,.40) 0%,rgba(255,246,232,0) 6%),
    linear-gradient(90deg,rgba(38,20,14,.62) 0%,rgba(38,20,14,.27) 25%,
                    rgba(38,20,14,.07) 56%,transparent 80%)}
/* the back of the sheet keeps the spine on its other edge, so every one of
   its gradients runs the other way */
.sback .sheen{
  background:
    linear-gradient(90deg,rgba(255,249,238,.50) 0%,rgba(255,249,238,0) 2.6%),
    linear-gradient(270deg,rgba(255,246,232,.40) 0%,rgba(255,246,232,0) 6%),
    linear-gradient(270deg,rgba(38,20,14,.62) 0%,rgba(38,20,14,.27) 25%,
                    rgba(38,20,14,.07) 56%,transparent 80%)}

/* --- dog-ear ------------------------------------------------------------
   The corner of the page you can turn next, folded back along the diagonal.
   The page's own corner has flipped over onto the top-left triangle, so the
   bottom-right triangle is the next page showing through, sitting in the
   flap's shadow. It is a plain div inside the book, so the book's pointer
   handler already treats a tap or a drag on it as a page turn. */
.dogear{position:absolute;right:0;bottom:0;height:7%;aspect-ratio:1;z-index:15;
  cursor:pointer;
  transition:height .3s var(--ease-drop),opacity .35s ease,visibility .35s}
.dogear:hover{height:10.5%}
.dogear.off{opacity:0;visibility:hidden;height:7%}

.dogear::before{content:"";position:absolute;inset:0;
  background:
    linear-gradient(315deg,rgba(60,36,25,.26),rgba(60,36,25,.05) 55%,transparent 80%),
    #e6dccb url(../img/paper.webp) center/230% auto;
  background-blend-mode:normal,multiply;
  clip-path:polygon(100% 0,100% 100%,0 100%)}

.dogear i{position:absolute;inset:0;display:block;
  background:linear-gradient(135deg,#f9f3e7 0%,#f0e8d9 45%,#e2d6c1 78%,#d2c3a9 100%);
  clip-path:polygon(0 0,100% 0,0 100%);
  border-top-left-radius:12%;
  filter:drop-shadow(1.5px 1.5px 3px rgba(45,25,17,.32))}

/* There is no shadow cast along the fold line, by choice. A dark band
   hugging the fold is the usual way to sell a page turn, but over this
   artwork it read as a grey smear with a hard straight edge lying across
   the page. The paper's own shading carries the turn instead: the roll
   shaded panel by panel in .shade, and .sheen across the whole sheet. */

/* ---------- a page ---------- */
.page{
  position:absolute;inset:0;container-type:size;
  background:#ece2d3 url(../img/paper.webp) center/cover;
  user-select:none;
}
.el{position:absolute;display:block;object-fit:fill;pointer-events:none;
  -webkit-user-drag:none;user-select:none}
.el.svg{pointer-events:none}

/* the cover art breathes very slightly, as one piece */
.page[data-page="1"] .el{animation:breathe 9s ease-in-out infinite}
@keyframes breathe{
  0%,100%{transform:translate3d(0,0,0)}
  50%{transform:translate3d(0,-.5%,0)}
}
.mask-cincin{background:var(--maroon);
  -webkit-mask:url(../img/p4-cincin.webp) center/100% 100% no-repeat;
  mask:url(../img/p4-cincin.webp) center/100% 100% no-repeat}

/* ---------- text ---------- */
.tx{position:absolute;left:calc(var(--cx,50)*1cqw);top:calc(var(--y)*1cqh);
  transform:translate(-50%,-50%);font-size:calc(var(--s)*1cqw);line-height:1.08;
  white-space:nowrap;letter-spacing:0}
.tx.l{left:calc(var(--x)*1cqw);transform:translate(0,-50%)}
.script{font-family:var(--f-script);line-height:1.25}
.pinyon{font-family:var(--f-pinyon);line-height:1.3}
.serif{font-family:var(--f-serif)}
.alice{font-family:var(--f-alice)}
.sans{font-family:var(--f-sans);font-weight:300}
.bold{font-weight:600}
.caps{text-transform:uppercase;letter-spacing:.012em}
.c-maroon{color:var(--maroon)}
.c-cream{color:var(--cream)}
.c-cream2{color:var(--cream2)}
.c-cream3{color:var(--cream3)}
.c-brown{color:var(--brown)}
.note{color:#66323b;font-weight:300}
.guest{color:var(--maroon)}

/* ---------- page 5 · Google Maps pill ---------- */
.maps{position:absolute;display:grid;place-items:center;border-radius:999px;
  background:var(--olive);color:#fff;text-decoration:underline;text-underline-offset:.18em;
  font-family:var(--f-sans);font-weight:300;font-size:3.27cqw;letter-spacing:.01em;
  transition:filter .2s,transform .2s}
.maps:hover{filter:brightness(1.08);transform:translateY(-2%)}

/* ---------- page 6 · calendar + countdown ---------- */
.cal{position:absolute;left:15.22cqw;top:22.46cqh;width:69.65cqw;height:34.86cqh;
  display:grid;grid-template-columns:repeat(7,1fr);grid-template-rows:repeat(6,1fr);
  place-items:center;font-family:var(--f-sans);font-weight:300;font-size:4.3cqw;color:var(--brown)}
.cal i{font-style:normal}
.cal .sun{color:var(--red)}
.cal .hd{font-weight:400}

.cd{position:absolute;inset:0;pointer-events:none}
.cd__cell{position:absolute;left:calc(var(--cx)*1cqw);top:68.6cqh;transform:translateX(-50%);
  display:flex;flex-direction:column;align-items:center;gap:2.6cqh}
.cd__cell b{font:400 5.4cqw/1 var(--f-sans);color:var(--brown);font-variant-numeric:tabular-nums}
.cd__cell span{font:400 2.75cqw/1 var(--f-sans);letter-spacing:.03em;color:var(--brown)}
.cd__sep{position:absolute;left:calc(var(--cx)*1cqw);top:70.6cqh;transform:translate(-50%,-50%);
  width:.95cqw;height:3.4cqh}
.cd__sep::before,.cd__sep::after{content:"";position:absolute;left:0;width:.95cqw;height:.95cqw;
  border-radius:50%;background:var(--brown)}
.cd__sep::before{top:0}
.cd__sep::after{bottom:0}

/* ---------- page 7 · form ---------- */
.card{position:absolute;background:var(--cream);border:.26cqw solid var(--maroon);border-radius:2.6cqw;
  box-shadow:0 1.2cqw 3cqw rgba(60,30,20,.12)}
.wform{position:absolute;inset:0}
.fld{position:absolute;background:var(--cream);border:.18cqw solid #8d5a62;border-radius:1.1cqw;
  font-family:var(--f-sans);font-weight:300;font-size:2.5cqw;color:var(--maroon);
  padding:0 1.6cqw;outline:none;resize:none}
textarea.fld{padding:1.1cqw 1.6cqw;line-height:1.35}
.fld:focus{border-color:var(--maroon);box-shadow:0 0 0 .25cqw rgba(64,1,15,.12)}
.send{position:absolute;background:var(--maroon);color:#fff;border:0;border-radius:1.6cqw;cursor:pointer;
  font-family:var(--f-serif);font-weight:600;font-size:3.01cqw;letter-spacing:.02em;
  transition:filter .2s,transform .15s}
.send:hover{filter:brightness(1.25)}
.send:active{transform:translateY(.3cqh)}
.send[disabled]{opacity:.55;cursor:default}

.wlist{position:absolute;overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;
  display:flex;flex-direction:column;gap:1.4cqh;padding-right:1.2cqw}
.wlist::-webkit-scrollbar{width:.9cqw}
.wlist::-webkit-scrollbar-thumb{background:rgba(64,1,15,.3);border-radius:99px}
.wi{background:rgba(252,244,233,.72);border-left:.5cqw solid var(--maroon);border-radius:.8cqw;
  padding:1.2cqh 1.8cqw;font-family:var(--f-sans);color:var(--brown)}
.wi b{display:block;font-weight:500;font-size:2.5cqw;color:var(--maroon)}
.wi p{margin:.5cqh 0 0;font-weight:300;font-size:2.4cqw;line-height:1.35;white-space:pre-wrap}
.wi i{display:block;margin-top:.4cqh;font-style:normal;font-size:1.8cqw;opacity:.6}
.wempty{font-family:var(--f-sans);font-weight:300;font-size:2.4cqw;color:var(--mid);text-align:center;
  opacity:.75;padding-top:2cqh}

/* ---------- chrome ---------- */
.nav{position:fixed;top:50%;transform:translateY(-50%);z-index:40;
  width:clamp(38px,5vmin,52px);aspect-ratio:1;border-radius:50%;border:1px solid rgba(226,200,170,.28);
  background:rgba(36,19,16,.45);backdrop-filter:blur(6px);color:#e8d6c2;
  font-size:clamp(20px,3vmin,28px);line-height:1;cursor:pointer;
  display:grid;place-items:center;transition:opacity .25s,background .25s}
.nav:hover{background:rgba(64,1,15,.75)}
.nav--prev{left:clamp(6px,1.6vmin,18px)}
.nav--next{right:clamp(6px,1.6vmin,18px)}
.nav[disabled]{opacity:.22;cursor:default}

.hud{position:fixed;left:50%;bottom:clamp(8px,2vmin,20px);transform:translateX(-50%);z-index:40;
  display:flex;align-items:center;gap:12px}
.hud__pages{display:flex;gap:4px;align-items:baseline;padding:7px 15px;border-radius:999px;
  background:rgba(36,19,16,.5);backdrop-filter:blur(6px);border:1px solid rgba(226,200,170,.22);
  font-size:13px;letter-spacing:.12em;color:#e8d6c2}
.hud__pages i{opacity:.5;font-style:normal}

.open-cta{position:fixed;left:50%;bottom:clamp(58px,10vmin,96px);transform:translateX(-50%);z-index:45;
  padding:13px 30px;border:0;border-radius:999px;cursor:pointer;
  background:linear-gradient(145deg,#6e3a21,#40010f);color:#f5e3cf;
  font-family:var(--f-sans);font-weight:400;font-size:14px;letter-spacing:.2em;text-transform:uppercase;
  box-shadow:0 10px 26px rgba(0,0,0,.45),0 0 0 0 rgba(214,160,112,.45);
  transition:opacity .45s ease,transform .45s var(--ease-flip),visibility .45s;
  animation:cta 3.4s ease-out infinite}
.open-cta:hover{transform:translateX(-50%) translateY(-2px)}
.open-cta.hide{opacity:0;visibility:hidden;transform:translateX(-50%) translateY(14px) scale(.96);
  animation:none}
@keyframes cta{
  0%{box-shadow:0 10px 26px rgba(0,0,0,.45),0 0 0 0 rgba(214,160,112,.4)}
  60%,100%{box-shadow:0 10px 26px rgba(0,0,0,.45),0 0 0 16px rgba(214,160,112,0)}
}

/* On a phone the A4 page is scaled right down, so the form's own text is
   nudged up a little to stay comfortable to read. */
@media (pointer:coarse){
  .fld{font-size:3.1cqw}
}

@media (max-width:520px){
  .open-cta{white-space:nowrap;font-size:12px;padding:11px 24px;letter-spacing:.16em}
  .nav{width:34px;background:rgba(36,19,16,.3)}
  .hud__pages{padding:6px 13px;font-size:12px}
}

@media (prefers-reduced-motion:reduce){
  :root{--flip-ms:1ms;--flip:1ms linear}
  .page[data-page="1"] .el{animation:none}
  .open-cta{animation:none}
}
