/* =========================================================
   PASSPORT OPENING
   The left half is a 3D "leaf" hinged on the spine:
     front = maroon frame + bio-data page
     back  = the closed cover (gold foil)
   On load the leaf starts folded over the right page (closed book,
   centred), then swings open while the book slides to centre.
   Pure CSS. Desktop/tablet only; phones and reduced motion get the
   open passport straight away.
   ========================================================= */

:root {
  --open-dur: 2.9s;                 /* whole sequence */
  --open-ease: cubic-bezier(.62, .02, .24, 1);
  --gold: linear-gradient(100deg, #b98d3e 0%, #f4dd9b 42%, #c79b48 58%, #e9c97c 100%);
  --cover-bg:
    var(--grain),
    radial-gradient(130% 100% at 30% 10%, #2c3d6b 0%, #1c2a4f 58%, #131d3a 100%);
}

/* ---------- Two cover halves instead of one maroon slab ---------- */
.passport {
  background: none; padding: 0; box-shadow: none; border-radius: 0;
  perspective: 2600px; perspective-origin: 50% 35%;
  position: relative;
}
.pp-leaf {
  position: relative; z-index: 3;
  display: flex;
  transform-origin: 100% 50%;              /* the spine */
  transform-style: preserve-3d;
}
.pp-leaf__front {
  flex: 1; display: flex; position: relative;
  padding: 10px 0 10px 10px;
  background: var(--cover-bg);
  border-radius: 22px 0 0 22px;
  box-shadow: 0 30px 60px -24px rgba(12, 20, 45, .45), 0 12px 24px -14px rgba(0,0,0,.3);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.pp-leaf__front .pp-left { flex: 1; box-shadow: inset -26px 0 30px -18px rgba(70, 50, 30, .28), inset -2px 0 0 rgba(70, 50, 30, .12); }
/* light on the inside page as it lands */
.pp-leaf__front::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(to left, rgba(20, 10, 5, .55), rgba(20, 10, 5, .15));
  opacity: 0;
}

.pp-right {
  border: 10px solid #1c2a4f; border-left: 0;
  border-radius: 4px 22px 22px 4px;
  box-shadow:
    inset 26px 0 30px -18px rgba(70, 50, 30, .28),
    inset 2px 0 0 rgba(70, 50, 30, .12),
    0 30px 60px -24px rgba(12, 20, 45, .45), 0 12px 24px -14px rgba(0,0,0,.3);
}
/* shadow the turning cover throws onto the right page */
.pp-right::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background: linear-gradient(to right, rgba(25, 12, 6, .55), rgba(25, 12, 6, .18) 45%, transparent 80%);
  opacity: 0;
}

/* ---------- The closed cover ---------- */
.pp-cover {
  position: absolute; inset: 0;
  transform: rotateY(180deg);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  border-radius: 4px 22px 22px 4px;           /* spine side is square-ish */
  background: var(--cover-bg);
  box-shadow:
    inset 6px 0 10px -4px rgba(0, 0, 0, .45),  /* hinge crease */
    inset 0 0 0 1px rgba(255, 255, 255, .06),
    0 30px 60px -20px rgba(12, 20, 45, .55);
  overflow: hidden;
}
.pp-cover__frame {
  position: absolute; inset: 18px 18px 18px 26px;
  border: 1px solid rgba(233, 201, 124, .35);
  border-radius: 4px 12px 12px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center;
}
.pp-cover__kicker, .pp-cover__title, .pp-cover__name {
  margin: 0;
  background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent;
  font-family: "Passport Garamond", "Fraunces", Georgia, serif;
  text-transform: uppercase;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .35));   /* debossed foil */
}
.pp-cover__kicker { font-size: 11px; letter-spacing: .32em; font-weight: 500; opacity: .85; }
.pp-cover__title  { font-size: clamp(25.5px, 3.06vw, 39px); letter-spacing: .28em; font-weight: 600; margin-right: -.28em; }
.pp-cover__name   { font-size: 13px; letter-spacing: .34em; font-weight: 500; margin-right: -.34em; }
.pp-cover__emblem { width: clamp(110px, 12vw, 150px); height: auto; filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
.pp-cover__chip   { width: 44px; height: auto; margin-top: 14px; opacity: .95; filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
/* a glint travelling across the foil */
.pp-cover__shine {
  position: absolute; inset: -20% -60%; pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 240, 200, .22) 50%, transparent 60%);
  transform: translateX(-60%);
}

/* ---------- Phones: no 3D, stacked passport as before ---------- */
@media (max-width: 760px) {
  .pp-cover { display: none; }
  .pp-leaf { transform: none; }
  .pp-leaf__front { padding: 0 8px 8px; border-radius: 0 0 18px 18px; }
  .pp-leaf__front .pp-left { border-radius: 4px 4px 12px 12px; box-shadow: inset 0 22px 26px -18px rgba(70,50,30,.25); }
  .pp-right { border-width: 8px 8px 0 8px; border-left: 8px solid #1c2a4f; border-radius: 18px 18px 0 0; }
}

/* Cover headline sits at the top like "Republic of India" on the real cover */
.pp-cover__kicker { font-size: clamp(16px, 1.6vw, 21px); line-height: 1.45; letter-spacing: .2em; font-weight: 600; opacity: 1; margin-right: -.2em; }
.pp-cover__flag { width: 46px; height: auto; margin-top: 14px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(233, 201, 124, .55), 0 2px 4px rgba(0,0,0,.35); }

/* =========================================================
   LOCKED → OPENING  (desktop / tablet, motion allowed)
   html.pp-locked  : set in <head> before paint. Closed book, strap on,
                     nothing else on the page.
   html.pp-opening : set by main.js when the strap is dragged/clicked.
   Without JS neither class exists, so the page simply shows open.
   ========================================================= */
:root { --open: 1.9s; }

/* ---------- Locked: closed, centred, waiting ---------- */
html.pp-locked { overflow: hidden; }
html.pp-locked .passport          { transform: translateX(-25%); animation: pp-arrive .8s cubic-bezier(.2, .7, .2, 1) both; }
html.pp-locked .pp-leaf           { transform: rotateY(180deg); }
html.pp-locked .pp-leaf__front::after, html.pp-locked .pp-right::after { opacity: 1; }
html.pp-locked .pp-cover__shine   { animation: pp-glint 5s ease-in-out 1s infinite; }
html.pp-locked .pp-seal           { animation: none; opacity: 0; }
html.pp-locked .pp-portrait       { animation: none; }
html.pp-locked .site-header,
html.pp-locked main > section:not(.hero),
html.pp-locked .notes-toggle,
html.pp-locked .hero__scroll      { opacity: 0; visibility: hidden; }

/* ---------- Opening: strap released, cover swings ---------- */
html.pp-opening { overflow: hidden; }
html.pp-opening .passport         { animation: pp-slide var(--open) var(--open-ease) both; }
html.pp-opening .pp-leaf          { animation: pp-leaf var(--open) both; }
html.pp-opening .pp-leaf__front::after { animation: pp-land var(--open) both; }
html.pp-opening .pp-right::after  { animation: pp-cast var(--open) both; }
html.pp-opening .pp-seal          { animation: seal-stamp .5s linear 1.75s both; }
html.pp-opening .pp-portrait      { animation: photo-jolt .45s ease-out 2.02s both; }
html.pp-opening .site-header,
html.pp-opening main > section:not(.hero),
html.pp-opening .notes-toggle     { animation: ui-in .8s cubic-bezier(.2, .7, .2, 1) 1.9s both; }
html.pp-opening .hero__scroll     { animation: ui-fade .8s ease-out 2.3s both; }
html.pp-opened  { overflow: visible; }

@keyframes pp-arrive {
  from { opacity: 0; transform: translate(-25%, 28px) rotateX(12deg) scale(.95); }
  to   { opacity: 1; transform: translateX(-25%); }
}
@keyframes pp-slide { from { transform: translateX(-25%); } to { transform: none; } }
@keyframes pp-leaf {
  0%   { transform: rotateY(180deg); animation-timing-function: var(--open-ease); }
  52%  { transform: rotateY(70deg) translateZ(16px); animation-timing-function: cubic-bezier(.3, .5, .3, 1); }
  100% { transform: rotateY(0deg); }
}
@keyframes pp-land { 0%, 40% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pp-cast { 0% { opacity: 1; } 50% { opacity: .55; } 100% { opacity: 0; } }
@keyframes pp-glint { 0%, 70% { transform: translateX(-60%); } 100% { transform: translateX(60%); } }
@keyframes ui-in   { from { opacity: 0; visibility: hidden; transform: translateY(-10px); } to { opacity: 1; visibility: visible; transform: none; } }
@keyframes ui-fade { from { opacity: 0; visibility: hidden; } to { opacity: 1; visibility: visible; } }

/* ---------- Leather strap with snap (only while locked/opening) ----------
   Same navy leather as the cover. Hinged where it wraps the book's right edge:
   dragging lifts the free end toward you; releasing flips it fully open. */
.pp-strap { display: none; }
html.pp-locked .pp-strap, html.pp-opening .pp-strap {
  display: block;
  position: absolute; z-index: 6; top: 50%; right: -16px;
  width: clamp(84px, 8.4vw, 105px); height: 70px; margin-top: -35px;
  border: 0; padding: 0; cursor: grab; touch-action: none;
  border-radius: 12px 16px 16px 12px;
  background:
    var(--grain),
    radial-gradient(130% 140% at 30% 20%, #34477a 0%, #1f2e56 55%, #141e3c 100%);
  box-shadow:
    inset 0 1px 0 rgba(170, 190, 240, .18),
    inset -9px 0 12px -6px rgba(0, 0, 0, .5),            /* curls round the edge */
    0 6px 14px -4px rgba(5, 10, 30, .55), 0 2px 3px rgba(0, 0, 0, .35);
  transform-origin: calc(100% - 16px) 50%;              /* hinge exactly at the book edge */
  transform-style: preserve-3d;
  transform: perspective(700px) rotateY(0deg);
}
.pp-strap::before {                                      /* gold saddle stitching */
  content: ""; position: absolute; inset: 7px 9px 7px 8px; border-radius: 8px 11px 11px 8px;
  border: 1.5px dashed rgba(233, 201, 124, .75);
}
.pp-strap__snap {                                        /* brass press-stud */
  position: absolute; left: 18px; top: 50%; width: 28px; height: 28px; margin-top: -14px; border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg, rgba(120, 80, 20, .35) 0 6deg, transparent 6deg 30deg),
    radial-gradient(circle at 35% 30%, #f6dc95 0%, #c99a45 45%, #8a6122 100%);
  box-shadow: inset 0 0 0 2px rgba(110, 72, 20, .55), inset 0 -2px 3px rgba(0,0,0,.3), 0 2px 3px rgba(0,0,0,.45);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;   /* hidden once the flap turns over */
  transition: transform .15s ease-out;
}
.pp-strap:focus-visible { outline: 3px solid #f4dd9b; outline-offset: 4px; }
.pp-strap.is-dragging { cursor: grabbing; transition: none; }
.pp-strap.is-dragging .pp-strap__snap, .pp-strap.is-open .pp-strap__snap { transform: scale(1.12); }   /* the stud pops */
/* invite: the free end lifts a little every few seconds while locked */
html.pp-locked .pp-strap:not(.is-dragging) { animation: strap-lift 3.2s ease-in-out 1.4s infinite; }
@keyframes strap-lift {
  0%, 76%, 100% { transform: perspective(700px) rotateY(0deg); }
  84%           { transform: perspective(700px) rotateY(32deg); }
  91%           { transform: perspective(700px) rotateY(0deg); }
  95%           { transform: perspective(700px) rotateY(10deg); }
}
/* released: flips open on its hinge, rests open, then fades once the book is open */
html .pp-strap.is-open {
  pointer-events: none;
  transform: perspective(700px) rotateY(180deg);         /* lies open, flat, still attached */
  transition: transform .55s cubic-bezier(.25, .9, .35, 1);   /* no overshoot past flat */
}

/* hint sits just right of the strap, pointing the way to pull */
.pp-hint { display: none; }
html.pp-locked .pp-hint, html.pp-opening .pp-hint {
  display: block; position: absolute; z-index: 6; top: 50%; left: calc(100% + 34px);
  transform: translateY(-50%); margin: 0; white-space: nowrap;
  font: italic 400 15px/1 "Passport Garamond", "Fraunces", Georgia, serif; color: #6f6458;
}
html.pp-locked .pp-hint  { animation: ui-fade .8s ease-out 1.2s both; }
html.pp-opening .pp-hint { opacity: 0; transition: opacity .25s ease-out; }
.pp-hint span { display: inline-block; animation: hint-nudge 1.6s ease-in-out infinite; }
@keyframes hint-nudge { 50% { transform: translateX(6px); } }
/* underside of the flap has no stud: hide it as the flap passes edge-on */
html .pp-strap.is-open .pp-strap__snap { opacity: 0; transition: transform .15s ease-out, opacity .05s linear .17s; }

/* the bit of strap stitched to the back cover: always joins flap and book */
.pp-strap-root { display: none; }
html.pp-locked .pp-strap-root, html.pp-opening .pp-strap-root {
  display: block; position: absolute; z-index: 5; top: 50%; right: -16px;
  width: 22px; height: 70px; margin-top: -35px; border-radius: 0 10px 10px 0;
  background: var(--grain), linear-gradient(to right, #1a2749, #22325c 60%, #16213f);
  box-shadow: inset -6px 0 8px -4px rgba(0, 0, 0, .45), 0 4px 10px -4px rgba(5, 10, 30, .5);
}

/* The strap leaves the moment the cover starts to open (no leather left on the open book) */
html.pp-opening .pp-strap,
html.pp-opening .pp-strap.is-open,
html.pp-opening .pp-strap-root {
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .55s cubic-bezier(.25, .9, .35, 1), opacity .18s ease-out, visibility 0s linear .18s;
}

/* =========================================================
   PEBBLED LEATHER (cover, frame and strap)
   Fine noise used as a bump map and lit from the top-left, which gives
   the small raised pebbles of a real passport cover. Blended soft-light
   over the navy so the colour stays the same.
   ========================================================= */
:root {
  --pebble: url("../assets/textures/leather.png");    /* generated by tools/leather-texture.swift */
  --navy-leather: radial-gradient(130% 100% at 30% 10%, #263659 0%, #19243f 58%, #10182e 100%);
}

/* closed cover + the frame around the left page */
.pp-cover, .pp-leaf__front {
  background-image: var(--pebble), var(--navy-leather);
  background-size: 240px 240px, auto;
  background-blend-mode: overlay, normal;
}

/* frame around the right page: leather in the border, paper inside */
.pp-right {
  border-color: transparent;
  background-image: var(--grain), var(--guilloche), linear-gradient(var(--paper), var(--paper)), var(--pebble), var(--navy-leather);
  background-size: 180px 180px, 120px 36px, auto, 240px 240px, auto;
  background-origin: padding-box, padding-box, padding-box, border-box, border-box;
  background-clip: padding-box, padding-box, padding-box, border-box, border-box;
  background-blend-mode: normal, normal, normal, overlay, normal;
}

/* strap + its root piece */
html.pp-locked .pp-strap, html.pp-opening .pp-strap,
html.pp-locked .pp-strap-root, html.pp-opening .pp-strap-root {
  background-image: var(--pebble), var(--navy-leather);
  background-size: 240px 240px, auto;
  background-blend-mode: overlay, normal;
}

/* ---------- Cover: name as the main title, PASSPORT at the bottom (25% smaller) ---------- */
.pp-cover__title { letter-spacing: .16em; margin-right: -.16em; white-space: nowrap; }
.pp-cover__word {
  margin: 6px -.28em 0 0;
  font: 600 clamp(19px, 2.3vw, 29px)/1 "Passport Garamond", "Fraunces", Georgia, serif;
  letter-spacing: .28em; text-transform: uppercase;
  background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .35));
}
.pp-cover__word { position: absolute; left: 0; right: 0; bottom: 26px; margin: 0; padding-left: .28em; text-align: center; }
