/* ==========================================================================
   Envelope gallery landing — bobthefoto / weddingsbybob
   ========================================================================== */
:root {
  --paper: #f2ede2;
  --paper-light: #f8f4ec;
  --paper-inside: #e6dfd0;
  --bg: #e4ddcf;
  --wax: #7a0f14;
  --ink: #7a0f14;
  --text: #2b2422;
  --seal-size: clamp(150px, min(44vw, 31vh), 290px);
  --fy: 62vh;               /* flap point y — set precisely by script.js */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;          /* no pull-to-refresh / bounce */
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body { position: fixed; inset: 0; touch-action: manipulation; }

.scene {
  position: fixed; inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 45%, #ddd4c3 0%, #cdc2ad 70%, #bfb39c 100%);
}

/* ---------- paper texture --------------------------------------------- */
.paper {
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .37 0 0 0 0 .3 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.38'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .05' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .45 0 0 0 0 .36 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)' opacity='.16'/%3E%3C/svg%3E"),
    radial-gradient(130% 100% at 50% 30%, rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 60%),
    linear-gradient(180deg, #f5f1e8 0%, #efe9dd 100%);
}

/* ---------- envelope -------------------------------------------------- */
.envelope {
  position: absolute; inset: 0;
  perspective: 2200px;
  transform-origin: 50% 50%;
  transition: transform 1.1s var(--ease-io), box-shadow 1.1s var(--ease-io);
}
.pocket {
  position: absolute; inset: 0;
  z-index: 2;
}
.folds { position: absolute; inset: 0; width: 100%; height: 100%; }

/* letter: hidden inside until the flap opens */
.letter {
  position: absolute;
  left: 7%; right: 7%;
  top: 3%; height: 88%;
  z-index: 1;
  background: #fff;
  background-image: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
  box-shadow: 0 1px 2px rgba(60,40,20,.10), 0 18px 40px -18px rgba(60,40,20,.35);
  display: flex; flex-direction: column; align-items: center;
  padding-top: 7%;
  transition: transform 1s var(--ease-out);
}
.letter-mark {
  width: clamp(48px, min(9vh, 15vw), 92px);
  aspect-ratio: 2083 / 752;
  background: var(--ink);
  -webkit-mask: url("assets/logo.svg") center / contain no-repeat;
          mask: url("assets/logo.svg") center / contain no-repeat;
  opacity: .92;
}
.letter-for { margin-top: 14px; font-family: "Homemade Apple", cursive; color: var(--ink); font-size: clamp(13px, 1.9vh, 18px); }
.letter-rule { width: 38px; height: 1px; background: rgba(122,15,20,.35); margin-top: 10px; }

/* ---------- top flap --------------------------------------------------- */
.flap {
  position: absolute; inset: 0;
  z-index: 3;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform 1.05s var(--ease-io);
  pointer-events: none;
}
.flap-shape { position: absolute; inset: 0; clip-path: var(--flap-clip); }
.flap-shadow {
  position: absolute; inset: 0;
  transform: translateY(4px);
  filter: blur(6px);
  opacity: .8;
  transition: opacity .35s ease;
}
.flap-shadow .flap-shape { background: rgba(80, 60, 38, .55); }
.flap-rim {                     /* lighter deckled lip of thick cotton paper */
  background: #fbf8f2;
  clip-path: var(--flap-rim-clip);
  backface-visibility: hidden;
}
.flap-front { backface-visibility: hidden; }
.flap-front::after {            /* soft shading towards the point */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0) 40%, rgba(120,95,60,.06) 100%);
}
.flap-back {
  transform: rotateY(180deg);
  backface-visibility: hidden;
  background:
    linear-gradient(0deg, rgba(110,85,55,.10) 0%, rgba(110,85,55,0) 35%),
    linear-gradient(180deg, #f3eee4 0%, #ebe4d6 100%);
  box-shadow: none;
}

/* ---------- handwritten prompt ---------------------------------------- */
.prompt {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: calc(var(--fy) - var(--seal-size) * .5 - clamp(64px, 11vh, 120px));
  transform: translateX(-50%);
  margin: 0;
  width: min(80vw, 420px);
  text-align: center;
  font-family: "Homemade Apple", "Brush Script MT", cursive;
  font-size: clamp(15px, 2.3vh, 22px);
  line-height: 1.8;
  white-space: pre-line;
  color: var(--ink);
  letter-spacing: .01em;
  opacity: .92;
  pointer-events: none;
  transition: opacity .4s ease, transform .6s var(--ease-out);
}

/* ---------- wax seal --------------------------------------------------- */
.seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: var(--fy);
  width: var(--seal-size);
  height: var(--seal-size);
  margin-left: calc(var(--seal-size) / -2);
  margin-top: calc(var(--seal-size) / -2 + var(--seal-size) * .1);
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;           /* we own the gesture on the seal */
  user-select: none; -webkit-user-select: none;
  outline: none;
  filter: drop-shadow(0 2px 1.5px rgba(40, 0, 0, .35)) drop-shadow(0 10px 14px rgba(70, 20, 10, .28));
}
.seal:focus-visible::after {
  content: ""; position: absolute; inset: -10px;
  border-radius: 50%;
  border: 1.5px dashed rgba(122,15,20,.55);
}
.seal-inner {
  position: absolute; inset: 0;
  transform: translateY(var(--drag, 0px)) scale(var(--press, 1));
  transition: transform .45s var(--ease-out);
}
.seal.dragging .seal-inner { transition: none; }
.seal.idle .seal-inner { animation: bob 3.2s ease-in-out infinite; }
@keyframes bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-5px) scale(1.012); }
}
.seal-half {
  position: absolute; inset: 0;
  transition: transform .9s var(--ease-out), opacity .45s ease .4s;
}
.seal-half svg { width: 100%; height: 100%; display: block; overflow: visible; }
.seal-left  { clip-path: polygon(-10% -10%, 51.5% -10%, 47.5% 17%, 54.5% 33%, 46.5% 51%, 53.5% 67%, 48.5% 83%, 51.5% 110%, -10% 110%); }
.seal-right { clip-path: polygon(50.5% -10%, 110% -10%, 110% 110%, 50.5% 110%, 47.5% 83%, 52.5% 67%, 45.5% 51%, 53.5% 33%, 46.5% 17%); }

/* ---------- opening sequence ------------------------------------------ */
.scene.opening .seal { cursor: default; pointer-events: none; }
.scene.opening .seal-inner { animation: none; transform: translateY(-14px) scale(1.06); transition: transform .25s var(--ease-out); }
.scene.opening .prompt { opacity: 0; transform: translateX(-50%) translateY(-8px); }
.scene.cracked .seal-left  { transform: translate(-16%, 34%) rotate(-16deg); opacity: 0; }
.scene.cracked .seal-right { transform: translate(17%, 40%) rotate(18deg);  opacity: 0; }
.scene.flap-open .flap { transform: rotateX(180deg); }
.scene.flap-open .flap-shadow { opacity: 0; }
.scene.flap-behind .flap { z-index: 0; }
.scene.lifted .envelope { transform: translateY(22%) scale(.68); box-shadow: 0 30px 60px -30px rgba(60,40,20,.45); }
.pocket::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 14px;
  background: linear-gradient(180deg, rgba(90,70,45,.16), rgba(90,70,45,0));
  opacity: 0; transition: opacity .6s ease;
}
.scene.lifted .pocket::before { opacity: 1; }
.scene.letter-out .letter { transform: translateY(-58%); }

/* ---------- welcome (white page) -------------------------------------- */
.welcome {
  position: fixed; inset: 0;
  z-index: 20;
  background: #fff;
  display: grid; place-items: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .8s ease, visibility 0s linear .8s;
}
.scene.white .welcome { opacity: 1; visibility: visible; transition: opacity .8s ease; }
.welcome-inner { text-align: center; max-width: 620px; }
.welcome-inner > * {
  opacity: 0; transform: translateY(10px);
  transition: opacity 1s ease, transform 1.2s var(--ease-out);
}
.scene.welcome-in .welcome-inner > * { opacity: 1; transform: none; }
.scene.welcome-in .welcome-inner > :nth-child(2) { transition-delay: .25s; }
.scene.welcome-in .welcome-inner > :nth-child(3) { transition-delay: .55s; }
.scene.welcome-in .welcome-inner > :nth-child(4) { transition-delay: .8s; }
.scene.welcome-in .welcome-inner > :nth-child(5) { transition-delay: 1.1s; }
.scene.welcome-in .welcome-inner > :nth-child(6) { transition-delay: 1.3s; }

.welcome-kicker {
  margin: 0 0 6px;
  font-family: "Homemade Apple", cursive;
  color: var(--ink);
  font-size: clamp(18px, 2.6vw, 24px);
}
.welcome-name {
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 400;
  font-size: clamp(46px, 8vw, 84px);
  line-height: 1.05;
  color: var(--text);
  letter-spacing: .005em;
  overflow-wrap: anywhere;
}
.welcome-msg {
  margin: 18px auto 0;
  max-width: 30ch;
  text-wrap: balance;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-style: italic;
  font-size: clamp(20px, 2.4vw, 27px);
  line-height: 1.4;
  color: #4a3f3b;
}
.welcome-rule { width: 44px; height: 1px; margin: 34px auto 22px; background: rgba(122,15,20,.45); }
.welcome-status {
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 15px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #8a7f79;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.welcome-status a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid rgba(122,15,20,.35);
  padding-bottom: 2px;
  letter-spacing: .12em;
}
.welcome-status a:hover, .welcome-status a:focus-visible { border-bottom-color: var(--ink); outline: none; }
.welcome-brand {
  position: fixed; left: 0; right: 0; bottom: max(22px, env(safe-area-inset-bottom));
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 13px; letter-spacing: .22em; text-transform: lowercase;
  color: #a1968e;
}

.noscript { position: fixed; inset: 0; z-index: 50; background: #fff; display: grid; place-content: center; text-align: center; font-family: Georgia, serif; }
.noscript a { color: var(--ink); }

/* ---------- reduced motion -------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .seal.idle .seal-inner { animation: none; }
  .envelope, .flap, .letter, .seal-half, .seal-inner, .prompt { transition-duration: .01ms !important; }
  .welcome, .scene.white .welcome { transition: opacity .4s ease; }
  .welcome-inner > * { transform: none; transition: opacity .5s ease !important; transition-delay: 0s !important; }
}


/* Default view: no personal link, no invitation. Kept outside the hidden scene. */
.private-notice {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: max(28px, env(safe-area-inset-top)) 26px max(28px, env(safe-area-inset-bottom));
  text-align: center; overflow: auto;
}
.private-inner { max-width: 520px; margin: auto; }
.private-mark {
  display: block; width: 80px; height: auto; margin: 0 auto 42px;
  filter: invert(12%) sepia(46%) saturate(3312%) hue-rotate(335deg) brightness(80%) contrast(108%);
  opacity: .94;
}
.private-script {
  margin: 0 0 22px; font-family: "Homemade Apple", cursive;
  font-size: clamp(17px, 4.4vw, 22px); line-height: 1.8; color: var(--ink);
}
.private-inner h1 {
  margin: 0; font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(29px, 5vw, 43px); font-weight: 400; line-height: 1.22;
  letter-spacing: -.01em; color: #403630;
}
.private-link {
  display: inline-block; margin-top: 38px; padding: 7px 0 4px;
  font-family: "Cormorant Garamond", Georgia, serif; font-size: 15px;
  letter-spacing: .08em; color: var(--ink); text-decoration: none;
  border-bottom: 1px solid rgba(122,15,20,.3);
}
.private-link:hover { border-bottom-color: var(--ink); }
.private-link:focus-visible { outline: 2px solid var(--ink); outline-offset: 5px; }
