/* Sampled from the OUTER EDGE of assets/1.png */
:root{
  --invitation-parchment: #ebd7c0;
  /* Envelope palette (base + subtle depth) */
  --env-base: #F3EBD6;
  --env-flap: #EADFC7;
  --env-pocket: #E2D4B8;
  --env-pocket-bottom: #D7C6A6;
  /* Envelope texture */
  --env-texture-opacity: 0.60;
  --env-texture-size: 420px;
  /* CC0 texture pack (downloaded) */
  --env-texture-image: url("assets/image.png");
  --env-texture-contrast: 1.18;
  --env-texture-brightness: 0.92;
}

#evnelope{
  /* Fluid width — no transform (keeps fixed fullscreen letter correct).
     All --env-* lengths are concrete px (set by script.resize). Defaults ≈ 320px wide. */
  --env-w: 320px;
  --env-h: 206px;
  --env-half-w: 160px;
  --env-flap-bb: 91px;
  --env-flap-bt: 110px;
  --env-pocket-v: 103px;
  --env-flower-right: -80px;
  --env-flower-bottom: -24px;
  --env-flower-width: 245px;
  --env-perspective: 640px;
  --env-letter-lift: -119px;
  position: relative;
  width: 100%;
  height: var(--env-h);
  max-width: 100%;
  margin-inline: auto;
  box-sizing: border-box;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background-color: var(--env-base);
  /* Subtle texture overlay on envelope body (doesn't affect positioned children) */
  /* NOTE: avoid calc() inside rgba() alpha (breaks on some engines) */
  background-image:
    linear-gradient(
      180deg,
      rgba(255,255,255, 0.12) 0%,
      rgba(0,0,0, 0.10) 100%
    ),
    url("assets/paper-texture.jpg");
  background-size: 100% 100%, var(--env-texture-size) var(--env-texture-size);
  background-position: center, center;
  background-repeat: no-repeat, repeat;
  background-blend-mode: soft-light, multiply;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: opacity 0.35s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Texture overlay that covers the whole envelope (flap + pocket) without affecting layout.
   Kept under the decorative images (flower/wax) to prevent “collapse” issues. */
#evnelope::after{
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: var(--env-texture-opacity);
  background-image: var(--env-texture-image);
  background-size: var(--env-texture-size) var(--env-texture-size);
  background-position: center;
  background-repeat: repeat;
  mix-blend-mode: multiply;
  filter: contrast(var(--env-texture-contrast)) brightness(var(--env-texture-brightness));
}

/* Ensure decorative elements stay above texture overlay */
.wax-stamp{ z-index: 8; }
.envelope-flower{ z-index: 8; }

/* After the first open, no “click here” hand cursor */
#evnelope.open{
  cursor: default;
}

/* No transform on #evnelope here: any transform makes `position: fixed` on
   descendants use the envelope as containing block → wrong top/edges vs viewport. */
.letter-fullscreen #evnelope{
  background-color: transparent;
  box-shadow: none;
  cursor: default;
}

/* When the envelope is hidden in fullscreen mode, hide texture overlay too */
.letter-fullscreen #evnelope::after{
  opacity: 0;
  visibility: hidden;
}

.letter-fullscreen #evnelope .front,
.letter-fullscreen #evnelope .hearts,
.letter-fullscreen #evnelope .wax-stamp,
.letter-fullscreen #evnelope .envelope-flower,
.letter-fullscreen #evnelope .arabic-text{
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.arabic-text{
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  grid-template-rows: 1fr auto;
  text-align: center;
  pointer-events: none;
  user-select: none;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.open .arabic-text{
  opacity: 0;
  visibility: hidden;
}

.arabic-top{
  justify-self: center;
  align-self: start;
  margin-top: 25px;
  display: grid;
  gap: 4px;
}

.arabic-title{
  margin-top: 0;
  padding: 0 64px;
  max-width: 560px;
  font-family: "Aref Ruqaa", "Scheherazade New", "Amiri", serif;
  font-weight: 700;
  font-size: 64px;
  line-height: 1.2;
  letter-spacing: 0.2px;
  background: #000;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 2px 0 rgba(0,0,0,0.22),
    0 12px 26px rgba(0,0,0,0.42);
}

.arabic-date{
  margin-top: 0;
  font-family: "Aref Ruqaa", "Scheherazade New", "Amiri", serif;
  font-weight: 700;
  font-size: 30px;
  opacity: 0.95;
  background: #000;
  /* background: linear-gradient(180deg, #fff1b8 0%, #e6c36a 22%, #caa04a 55%, #fff1b8 100%); */
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 6px 18px rgba(0,0,0,0.42);
}

.arabic-cta{
  justify-self: center;
  align-self: end;
  margin-bottom: 28px;
  font-family: "Aref Ruqaa", "El Messiri", "Amiri", serif;
  font-weight: 700;
  font-size: 44px;
  opacity: 0.95;
  background: #000;
  /* background: linear-gradient(180deg, #fff1b8 0%, #e6c36a 22%, #caa04a 55%, #fff1b8 100%); */
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 2px 0 rgba(0,0,0,0.25),
    0 10px 24px rgba(0,0,0,0.35);
}

.wax-stamp{
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  width: 155px;
  height: auto;
  z-index: 7;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
}

.envelope-flower{
  position: absolute;
  right: var(--env-flower-right);
  bottom: var(--env-flower-bottom);
  width: var(--env-flower-width);
  height: auto;
  z-index: 6;
  pointer-events: none;
  user-select: none;
}
.front{
  position: absolute;
  width: 0;
  height: 0;
  z-index: 3;
}
.flap{
  border-left: var(--env-half-w) solid transparent;
  border-right: var(--env-half-w) solid transparent;
  border-bottom: var(--env-flap-bb) solid transparent;
  border-top: var(--env-flap-bt) solid var(--env-flap);
  transform-origin: top;
}
.pocket{
  border-left: var(--env-half-w) solid var(--env-pocket);
  border-right: var(--env-half-w) solid var(--env-pocket);
  border-bottom: var(--env-pocket-v) solid var(--env-pocket-bottom);
  border-top: var(--env-pocket-v) solid transparent;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  z-index: 6;
}
.letter{
  position: absolute;
  left: 5%;
  right: 5%;
  top: 5%;
  isolation: isolate;
  perspective: var(--env-perspective);
  background-color: #f7f0df;
  background-image:
    url("assets/paper-texture.jpg"),
    /* subtle paper texture */
    radial-gradient(circle at 20% 30%, rgba(120, 94, 45, 0.06) 0 28%, rgba(0,0,0,0) 60%),
    radial-gradient(circle at 70% 65%, rgba(120, 94, 45, 0.05) 0 24%, rgba(0,0,0,0) 58%),
    linear-gradient(180deg, rgba(255,255,255,0.30) 0%, rgba(0,0,0,0.06) 100%),
    /* burnt edges */
    radial-gradient(40px 40px at 0% 0%, rgba(50,22,0,0.55) 0%, rgba(50,22,0,0.22) 45%, rgba(0,0,0,0) 72%),
    radial-gradient(40px 40px at 100% 0%, rgba(50,22,0,0.55) 0%, rgba(50,22,0,0.22) 45%, rgba(0,0,0,0) 72%),
    radial-gradient(44px 44px at 0% 100%, rgba(50,22,0,0.60) 0%, rgba(50,22,0,0.25) 45%, rgba(0,0,0,0) 72%),
    radial-gradient(44px 44px at 100% 100%, rgba(50,22,0,0.60) 0%, rgba(50,22,0,0.25) 45%, rgba(0,0,0,0) 72%),
    linear-gradient(90deg, rgba(50,22,0,0.28) 0%, rgba(0,0,0,0) 12%, rgba(0,0,0,0) 88%, rgba(50,22,0,0.24) 100%),
    linear-gradient(180deg, rgba(50,22,0,0.24) 0%, rgba(0,0,0,0) 12%, rgba(0,0,0,0) 86%, rgba(50,22,0,0.30) 100%);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 90%;
  border-radius: 0;
  box-shadow: 0 2px 26px rgba(0,0,0,0.12);
  filter: contrast(108%) brightness(98%);
  z-index: 4;
  transform-origin: top center;
}

.invitation-fold{
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  user-select: none;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.letter-fullscreen .invitation-fold{
  opacity: 1;
  visibility: visible;
}

/* Same invite as fullscreen — visible as soon as envelope opens (no paper placeholder) */
.letter-preview{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* Inline <img> baseline gap reads as a transparent strip — block removes it */
  /* Fill the letter — no parchment bars around the art */
  object-fit: cover;
  object-position: center top;
  z-index: 6;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}

html:not(.letter-fullscreen) #evnelope .letter-preview{
  opacity: 1;
  visibility: visible;
}

html.letter-fullscreen .letter-preview{
  opacity: 0;
  visibility: hidden;
}

/* Invite image only — fill the pocket, no shadow/radius frame, no baseline gap */
html:not(.letter-fullscreen) #evnelope .letter{
  left: 0;
  right: 0;
  top: 0;
  height: 100%;
  isolation: auto;
  background-color: transparent;
  background-image: none;
  filter: none;
  box-shadow: none;
  overflow: hidden;
}

/* Wider crop inside the pocket + slight vertical scale for edge bleed */
html:not(.letter-fullscreen) #evnelope .letter-preview{
  inset: auto;
  left: -45%;
  width: 180%;
  height: 100%;
  top: 0;
  transform: scaleY(1.05);
  transform-origin: center top;
}

html:not(.letter-fullscreen) #evnelope .letter::before{
  opacity: 0;
}

html:not(.letter-fullscreen) #evnelope .letter::after{
  opacity: 0;
}

html:not(.letter-fullscreen) #evnelope .letter .words{
  display: none;
}

/*
  Click targets on assets/1.png:
  — Left: dark green velvet “تأكيد الحجز” (RSVP)
  — Right: postage-stamp map “الموقع”
  Percentages are relative to the full letter area (same as the image in fullscreen).
*/
.invitation-hotspots{
  position: absolute;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

.letter-fullscreen .invitation-hotspots{
  z-index: 1000;
}

.invitation-hotspot{
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  background: transparent;
  border: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.invitation-hotspot--rsvp{
  left: 40%;
  bottom: 15%;
  width: 15%;
  height: 15%;
}

.invitation-hotspot--map{
  right: 38%;
  bottom: 15%;
  width: 7%;
  height: 13%;
}


.fold-panel{
  position: absolute;
  left: 0;
  width: 100%;
  height: 33.3334%;
  background-image: url("assets/1.png");
  background-repeat: no-repeat;
  /* Keep the invite centered horizontally while slicing vertically */
  background-size: auto 300%;
  background-position-x: 50%;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

.fold-top{
  top: 0;
  background-position: center 0%;
  transform-origin: top center;
}

.fold-middle{
  top: 33.3334%;
  background-position: center 50%;
  transform-origin: top center;
}

.fold-bottom{
  top: 66.6668%;
  background-position: center 100%;
  transform-origin: top center;
}

.letter-fullscreen .letter{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  transform: none;
  transform-origin: top center;
  z-index: 999;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  background-color: var(--invitation-parchment);
  background-image: none;
  filter: none;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.letter-fullscreen .letter::before{
  opacity: 0;
}

.letter-fullscreen .letter::after{
  opacity: 0;
}

.letter-fullscreen .letter .words{
  display: none;
}

/* 3-part fold animation (no stretching) */
/* Start state when fullscreen is applied */
.letter-fullscreen .fold-top{
  opacity: 1;
  transform: rotateX(-92deg);
}
.letter-fullscreen .fold-middle,
.letter-fullscreen .fold-bottom{
  opacity: 0;
  transform: rotateX(-92deg);
}

/* Open: unfold strictly top → middle → bottom */
.letter-fullscreen:not(.letter-collapsing) .fold-top{
  animation: foldOpen 0.50s ease-out both;
}
.letter-fullscreen:not(.letter-collapsing) .fold-middle{
  animation: foldReveal 0s 0.52s linear both, foldOpen 0.50s 0.52s ease-out both;
}
.letter-fullscreen:not(.letter-collapsing) .fold-bottom{
  animation: foldReveal 0s 1.06s linear both, foldOpen 0.50s 1.06s ease-out both;
}

/* Close: fold bottom → middle → top */
.letter-fullscreen.letter-collapsing .fold-bottom{
  animation: foldClose 0.40s ease-in both, foldHide 0s 0.40s linear both;
}
.letter-fullscreen.letter-collapsing .fold-middle{
  animation: foldClose 0.40s 0.42s ease-in both, foldHide 0s 0.82s linear both;
}
.letter-fullscreen.letter-collapsing .fold-top{
  animation: foldClose 0.40s 0.84s ease-in both;
}

@keyframes foldReveal{
  to{ opacity: 1; }
}

@keyframes foldHide{
  to{ opacity: 0; }
}

@keyframes foldOpen{
  from{ transform: rotateX(-92deg); }
  to{ transform: rotateX(0deg); }
}

@keyframes foldClose{
  from{ transform: rotateX(0deg); }
  to{ transform: rotateX(-92deg); }
}
.letter::before{
  content: "";
  position: absolute;
  inset: -22px;
  background-image: url("assets/burnt-frame.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
  opacity: 0.95;
  z-index: 3;
  mix-blend-mode: multiply;
  filter: contrast(112%) saturate(105%);
}

.letter:after{
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 0 46px rgba(0,0,0,0.35),
    inset 0 0 12px rgba(50,22,0,0.28);
  opacity: 0.85;
  pointer-events: none;
}
.words{
  position: absolute;
  left: 10%;
  width: 80%;
  height: 14%;
  background-color: #eeeff0;
}
.words.line1{
  top: 15%;
  width: 20%;
  height: 7%;
}
.words.line2{
  top: 30%;
}
.words.line3{
  top: 50%;
}
.words.line4{
  top: 70%;
}
.open .flap{
  transform: rotateX(180deg);
  transition: transform 0.4s ease, z-index 0.6s;
  z-index: 1;
}
.close .flap{
  transform: rotateX(0deg);
  transition: transform 0.4s 0.6s ease, z-index 1s;
  z-index: 5;
}
.close .letter{
  transform: translateY(0px);
  transition: transform 0.4s ease, z-index 1s;
  z-index: 2;
}
.open .letter{
  transform: translateY(var(--env-letter-lift));
  transition: transform 0.4s 0.6s ease, z-index 0.6s;
  z-index: 4;
}

/*
  .open .letter uses translateY(-260px) + a delayed transform transition.
  Same specificity as .letter-fullscreen .letter but comes later, so it won
  and the fullscreen letter animated from “lifted” to centered. Fix: higher
  specificity + no transition so it snaps to center immediately.
*/
html.letter-fullscreen #evnelope.open .letter,
html.letter-fullscreen #evnelope.close .letter{
  transform: none;
  transition: none !important;
}

.a1{
  left: 20%;
  transform: scale(0.6);
  opacity: 1;
  animation: animate 4s linear 1, sideSway 2s ease-in-out 4 alternate;
  animation-fill-mode: forwards;
  animation-delay: 0.7s;
}
.a2{
  left: 55%;
  transform: scale(1);
  opacity: 1;
  animation: animate 5s linear 1, sideSway 4s ease-in-out 2 alternate;
  animation-fill-mode: forwards;
  animation-delay: 0.7s;
}
.a3{
  left: 10%;
  transform: scale(0.8);
  opacity: 1;
  animation: animate 7s linear 1, sideSway 2s ease-in-out 6 alternate;
  animation-fill-mode: forwards;
  animation-delay: 0.7s;
}
@keyframes animate{
  0%{
      top: 0;
  }
  100%{
      top: -600px;
  }
}
@keyframes sideSway{
  0%{
      margin-left: 0px;
  }
  100%{
      margin-left: 50px;
  }
}
body{
  background-color: var(--invitation-parchment);
  min-height: 100vh;
  margin: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  width: 100%;
  box-sizing: border-box;
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
}

@supports (padding: max(0px, 1px)){
  body{
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
}

html.letter-fullscreen body{
  display: block;
}

.evnelope-wrapper{
  display: block;
  width: 100%;
  max-width: 700px;
  justify-self: center;
  height: auto;
  box-sizing: border-box;
}

@media (max-width: 720px){
  body{
    padding: 12px;
  }

  .evnelope-wrapper{
    width: 100%;
  }

  .wax-stamp{
  width: 110px;
}


  html:not(.letter-fullscreen) #evnelope .invitation-hotspot--rsvp{
    left: 8%;
    bottom: 10%;
    width: 50%;
    height: 11%;
  }

  html:not(.letter-fullscreen) #evnelope .invitation-hotspot--map{
    right: 6%;
    bottom: 12%;
    width: 28%;
    height: 9%;
  }

  .invitation-hotspot--rsvp{
  left: 32%;
  bottom: 15%;
  width: 26%;
  height: 15%;
  }

  .invitation-hotspot--map{
    right: 28%;
    bottom: 15%;
    width: 13%;
    height: 13%;
  }

  .arabic-title{
    padding: 0 20px;
    font-size: 40px;
  }
  .arabic-date{
    font-size: 22px;
  }
  .arabic-cta{
    margin-bottom: 16px;
    font-size: 28px;
  }
  .arabic-top{
    margin-top: 5px;
  }

  /*
    Show the full invite on small screens (no horizontal zoom/crop).
    Desktop uses a wide crop; on phones that clipped the right side of the art.
  */
  html:not(.letter-fullscreen) #evnelope .letter{
    background-color: var(--invitation-parchment);
  }

  html:not(.letter-fullscreen) #evnelope .letter-preview{
    inset: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: none;
    object-fit: contain;
    object-position: center top;
  }

  /*
    Fullscreen invite: fixed + 100vh is unreliable on mobile (iOS toolbars / visual viewport).
    Fill the screen, respect safe areas, and stretch the fold art to full panel width
    so the right edge of the image is not cropped.
  */
  html.letter-fullscreen{
    overflow: hidden;
    max-width: 100vw;
  }

  html.letter-fullscreen body{
    overflow: hidden;
    max-width: 100vw;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: -webkit-fill-available;
  }

  .letter-fullscreen .letter{
    position: fixed;
    inset: 0;
    left: 0;
    right: 0;
    top: 27px;
    bottom: 0;
    width: 105%;
    /* max-width: 100vw; */
    /* height: 100vh; */
    height: 93dvh;
    /* min-height: -webkit-fill-available; */
    margin: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    box-sizing: border-box;
  }

  .letter-fullscreen .fold-panel{
    background-size: 100% 300%;
    background-position-x: center;
  }
}

@supports (padding: max(0px, 1px)){
  @media (max-width: 720px){
    body{
      padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
  }
}

@media (min-width: 721px) and (max-width: 1024px) {
  .invitation-hotspot--rsvp{
    left: 40%;
    bottom: 15%;
    width: 15%;
    height: 15%;
  } 
  
  .invitation-hotspot--map{
    right: 38%;
    bottom: 15%;
    width: 7%;
    height: 13%;
  }
}

@media (min-width: 1025px) and (max-width: 1600px) {
  .invitation-hotspot--rsvp{
    left: 42%;
    bottom: 15%;
    width: 12%;
    height: 15%;
  } 
  
  .invitation-hotspot--map{
    right: 41%;
    bottom: 15%;
    width: 5%;
    height: 13%;
  }
}

@media (min-width: 1601px) and (max-width: 2300px) {
  .invitation-hotspot--rsvp{
    left: 46%;
    bottom: 15%;
    width: 6%;
    height: 15%;
  }
  
  .invitation-hotspot--map{
    right: 45%;
    bottom: 15%;
    width: 3%;
    height: 13%;
  }
}