/* ---------------------------------- base ---------------------------------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Nunito", -apple-system, "Segoe UI", sans-serif;
  color: #7c3557;
  background: #ffb9d2;
  overflow: hidden;               /* unlocked after the pop */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
body.revealed { overflow-y: auto; overflow-x: hidden; }

img { -webkit-user-drag: none; }

.hidden-soft { opacity: 0; visibility: hidden; }

/* ------------------------------- background ------------------------------- */
.sky {
  position: fixed; inset: 0; z-index: -3;
  background:
    radial-gradient(120% 90% at 50% -10%, #ffe3ee 0%, transparent 60%),
    radial-gradient(90% 70% at 85% 100%, #ffc9de 0%, transparent 55%),
    radial-gradient(70% 60% at 10% 85%, #ffd9e6 0%, transparent 60%),
    linear-gradient(180deg, #ffdce9 0%, #ffc3d9 45%, #ffb1cd 100%);
}
.sky::after {                      /* soft vignette */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 120% at 50% 45%, transparent 60%, rgba(214,90,143,.18) 100%);
}

.bokeh { position: fixed; inset: 0; z-index: -2; pointer-events: none; }
.bokeh i {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,.85), rgba(255,255,255,0) 70%);
  opacity: .5; animation: drift 14s ease-in-out infinite alternate;
}
.bokeh i:nth-child(1){ width:110px; height:110px; left:6%;  top:14%; animation-duration:16s; }
.bokeh i:nth-child(2){ width:60px;  height:60px;  left:78%; top:8%;  animation-duration:12s; }
.bokeh i:nth-child(3){ width:90px;  height:90px;  left:86%; top:52%; animation-duration:18s; }
.bokeh i:nth-child(4){ width:45px;  height:45px;  left:14%; top:62%; animation-duration:11s; }
.bokeh i:nth-child(5){ width:70px;  height:70px;  left:48%; top:6%;  animation-duration:15s; }
.bokeh i:nth-child(6){ width:40px;  height:40px;  left:64%; top:74%; animation-duration:13s; }
.bokeh i:nth-child(7){ width:85px;  height:85px;  left:4%;  top:86%; animation-duration:17s; }
.bokeh i:nth-child(8){ width:50px;  height:50px;  left:35%; top:80%; animation-duration:10s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(18px, -26px) scale(1.12); }
}

.branch {
  position: fixed; z-index: -1; pointer-events: none;
  width: min(46vw, 300px); height: auto;
  filter: drop-shadow(0 4px 10px rgba(190,80,130,.25));
}
.branch-tl { top: -8px; left: -12px; }
.branch-br { bottom: -8px; right: -12px; }

#petals {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
}

/* ------------------------------ layout / stage ---------------------------- */
#stage {
  position: relative; z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 18px
           calc(env(safe-area-inset-bottom, 0px) + 28px);
}

#title {
  font-family: "Dancing Script", "Amiri", cursive;
  font-size: clamp(2.1rem, 8.5vw, 3.6rem);
  font-weight: 700;
  text-align: center;
  margin-top: max(2vh, 10px);
  background: linear-gradient(90deg, #e84d8a, #ff8fb5, #d8447f);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 8px rgba(255,255,255,.75));
  transition: opacity 1.4s ease, visibility 1.4s, transform 1.4s ease;
  transform: translateY(-12px);
}
#title.show { opacity: 1; visibility: visible; transform: none; }

#scene {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  min-height: min(78dvh, 660px);
}

/* ------------------------------- the box ---------------------------------- */
#boxWrap {
  position: relative;
  width: min(74vw, 330px);
  cursor: pointer;
  touch-action: none;                    /* the hold gesture owns this element */
  will-change: transform, filter;
}
#box { display: block; width: 100%; height: auto; overflow: visible; }

#lid { transform-origin: 92px 150px; }
#leak { filter: blur(4px); }
#lid.fly {
  animation: lidFly .9s cubic-bezier(.22,.9,.32,1) forwards;
}
@keyframes lidFly {
  20%  { transform: translate(10px, -90px) rotate(18deg);  opacity: 1; }
  100% { transform: translate(120px, -340px) rotate(75deg); opacity: 0; }
}

#ring {
  position: absolute; inset: -6% -6% auto -6%;
  width: 112%; height: auto;
  pointer-events: none;
  opacity: 0; transition: opacity .25s ease;
}
#boxWrap.holding #ring { opacity: .9; }
#ringFill { transition: none; }

#hint {
  margin-top: 20px;
  font-size: clamp(1rem, 4.2vw, 1.2rem);
  font-weight: 700;
  letter-spacing: .02em;
  color: #b8447c;
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
  animation: hintPulse 2.2s ease-in-out infinite;
  text-align: center;
  transition: opacity .5s ease;
}
@keyframes hintPulse {
  0%, 100% { opacity: .55; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.05); }
}
#hint.quiet, body.revealed #hint { animation: none; opacity: 0; }

/* --------------------------- the polaroid reveal --------------------------- */
#mainPhoto {
  position: absolute;
  left: 50%; top: 3%;
  width: min(56vw, 270px);
  z-index: -1;                    /* hides behind the box until it springs out */
  transform: translate(-50%, 95%) scale(.12) rotate(6deg);
  opacity: 0;
  pointer-events: none;
}
#mainPhoto img {
  display: block; width: 100%; height: auto;
  border-radius: 6px;
  box-shadow: 0 14px 40px rgba(180,60,110,.35), 0 0 0 1px rgba(255,255,255,.6);
}
#mainPhoto.pop {
  animation: photoSpring 1.5s cubic-bezier(.3,1.6,.4,1) .18s forwards;
}
@keyframes photoSpring {
  0%   { transform: translate(-50%, 95%) scale(.12) rotate(6deg);  opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: translate(-50%, 0) scale(1) rotate(-2.5deg); opacity: 1; }
}
#mainPhoto.settled {
  animation: photoFloat 5s ease-in-out infinite;
  transform: translate(-50%, 0) rotate(-2.5deg);
  opacity: 1;
}
@keyframes photoFloat {
  0%, 100% { transform: translate(-50%, 0)    rotate(-2.5deg); }
  50%      { transform: translate(-50%, -8px) rotate(-1deg); }
}

/* ------------------------------ floating photos ---------------------------- */
#floaters { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.floater {
  position: absolute;
  width: var(--w, 96px);
  padding: 6px 6px 20px;
  background: #fffdf9;
  border-radius: 4px;
  box-shadow: 0 8px 22px rgba(180,60,110,.28);
  left: 50%; top: 60%;
  transform: translate(-50%, -50%) scale(.1) rotate(0deg);
  opacity: 0;
  transition:
    left 1.4s cubic-bezier(.2,.8,.25,1),
    top 1.4s cubic-bezier(.2,.8,.25,1),
    transform 1.4s cubic-bezier(.2,.8,.25,1),
    opacity .6s ease;
}
.floater img { display: block; width: 100%; height: auto; border-radius: 2px; }
.floater.placed {
  left: var(--x); top: var(--y);
  transform: translate(-50%, -50%) scale(1) rotate(var(--r));
  opacity: 1;
}
.floater.placed .inner-float { animation: floaty var(--dur, 6s) ease-in-out infinite alternate; }
.floater .inner-float { display: block; }
@keyframes floaty {
  from { transform: translateY(-6px) rotate(-1.2deg); }
  to   { transform: translateY(8px)  rotate(1.4deg); }
}

/* --------------------------------- letter --------------------------------- */
#letterWrap {
  width: 100%;
  max-width: 560px;
  margin: 4vh auto 0;
  transition: opacity 1.2s ease, visibility 1.2s;
}
#letterWrap.show { opacity: 1; visibility: visible; }

#letter {
  position: relative; z-index: 3;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,248,251,.98));
  border: 1px solid rgba(255,150,190,.5);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(180,60,110,.25);
  padding: 26px 24px 22px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.letter-deco {
  text-align: center;
  color: #ff86b3;
  letter-spacing: .6em;
  margin-bottom: 14px;
  font-size: 1rem;
}
#letterText {
  font-size: clamp(1.05rem, 4.4vw, 1.25rem);
  line-height: 1.9;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #6d2c4c;
  -webkit-user-select: text; user-select: text;
}
#letterText.arabic {
  direction: rtl;
  font-family: "Amiri", "Nunito", serif;
  font-size: clamp(1.15rem, 5vw, 1.4rem);
  line-height: 2.1;
}
#caret {
  display: inline-block;
  width: 2px; height: 1.15em;
  margin-inline-start: 2px;
  vertical-align: -0.18em;
  background: #ff5c93;
  animation: blink 0.9s steps(1) infinite;
}
#caret.done { display: none; }
@keyframes blink { 50% { opacity: 0; } }

.sig-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 18px;
}
#signature {
  font-family: "Dancing Script", "Amiri", cursive;
  font-size: clamp(1.4rem, 6vw, 1.8rem);
  color: #d8447f;
  transition: opacity 1.5s ease, visibility 1.5s;
}
#letterDate {
  font-size: .95rem;
  font-weight: 600;
  color: #c06592;
  transition: opacity 1.5s ease, visibility 1.5s;
}
#signature.show, #letterDate.show { opacity: 1; visibility: visible; }

#footerHeart {
  text-align: center;
  font-size: 1.6rem;
  color: #ff6ea1;
  margin: 26px 0 6px;
  animation: heartBeat 1.6s ease-in-out infinite;
}
@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  25%      { transform: scale(1.25); }
  40%      { transform: scale(1); }
}

/* ------------------------------- secret gate ------------------------------ */
#gate {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(255,227,238,.75) 0%, transparent 60%),
    linear-gradient(180deg, rgba(255,220,233,.82), rgba(255,177,205,.9));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 1s ease, visibility 1s;
}
#gate.open { opacity: 0; visibility: hidden; pointer-events: none; }

#gateCard {
  width: min(92vw, 380px);
  background: linear-gradient(180deg, rgba(255,255,255,.97), rgba(255,248,251,.99));
  border: 1px solid rgba(255,150,190,.5);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(180,60,110,.35);
  padding: 30px 26px 26px;
  text-align: center;
}
#gateCard.wrong { animation: gateShake .5s ease; }
@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); } 40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }  80% { transform: translateX(4px); }
}

#gateBow { font-size: 2.6rem; animation: heartBeat 2s ease-in-out infinite; }
#gateTitle {
  font-family: "Amiri", "Dancing Script", serif;
  font-size: 1.5rem; color: #c2447e; margin-top: 8px;
}
#gatePrompt { font-size: 1rem; color: #a05579; margin-top: 8px; }
#gateInput {
  width: 100%; margin-top: 18px;
  padding: 13px 16px;
  font-size: 16px;                 /* ≥16px stops iOS zoom-on-focus */
  font-family: inherit;
  text-align: center;
  color: #7c3557;
  background: #fff;
  border: 2px solid #ffb0cd;
  border-radius: 14px;
  outline: none;
  -webkit-user-select: text; user-select: text;
}
#gateInput:focus { border-color: #ff5c93; box-shadow: 0 0 0 4px rgba(255,92,147,.15); }
#gateBtn {
  width: 100%; margin-top: 12px;
  padding: 13px 16px;
  font-size: 1.05rem; font-weight: 700; font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, #ff7fae, #e84d8a);
  border: none; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(232,77,138,.4);
}
#gateBtn:active { transform: scale(.97); }
#gateErr {
  min-height: 1.4em;
  margin-top: 12px;
  font-size: .95rem; font-weight: 700; color: #e84d8a;
  opacity: 0; transition: opacity .3s ease;
}
#gateErr.show { opacity: 1; }

/* ----------------------------- pop! overlays ------------------------------- */
#flash {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(circle at 50% 58%, #fff 0%, #fff6da 30%, rgba(255,220,235,0) 70%);
  opacity: 0; pointer-events: none;
}
#flash.go { animation: flashGo 1.4s ease-out forwards; }
@keyframes flashGo {
  0%   { opacity: 0; }
  8%   { opacity: 1; }
  100% { opacity: 0; }
}

#rays {
  position: fixed; z-index: 45;
  left: 50%; top: 58%;
  width: 240vmax; height: 240vmax;
  margin: -120vmax 0 0 -120vmax;
  background: repeating-conic-gradient(
    rgba(255,255,255,.55) 0deg 6deg,
    rgba(255,255,255,0)  6deg 18deg);
  border-radius: 50%;
  opacity: 0; pointer-events: none;
  transform: scale(0);
  -webkit-mask-image: radial-gradient(circle, black 0%, transparent 62%);
          mask-image: radial-gradient(circle, black 0%, transparent 62%);
}
#rays.go { animation: raysGo 2.4s ease-out forwards; }
@keyframes raysGo {
  0%   { transform: scale(0)   rotate(0deg);  opacity: 0; }
  12%  { opacity: .95; }
  100% { transform: scale(1) rotate(28deg);   opacity: 0; }
}

#burst {
  position: fixed; inset: 0; z-index: 48;
  pointer-events: none;
}

/* ------------------------------ bigger screens ----------------------------- */
@media (min-width: 700px) {
  #boxWrap { width: 340px; }
  #mainPhoto { width: 320px; }
  .floater { --w: 150px; }
  #scene { min-height: min(76dvh, 700px); }
}

@media (prefers-reduced-motion: reduce) {
  .bokeh i, #hint, #footerHeart, .floater.placed .inner-float, #mainPhoto.settled { animation: none; }
}
