:root {
  --bg: #F8EFE6;
  --rose: #D98A98;
  --rose-deep: #A9526A;
  --blush: #E9B4BE;
  --peach: #F2CBC3;
  --gold: #F6C76A;
  --wood: #C9A27E;
  --sage: #9FBF94;
  --ink: #7A5560;
  --muted: #A98A86;
  --paper: #FFFDF9;
  --script: 'Aref Ruqaa', serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-snap-type: y proximity; }
body {
  margin: 0; min-height: 100svh; background: var(--bg); color: var(--ink);
  font-family: 'Tajawal', system-ui, sans-serif; overflow-x: hidden;
}
button { font: inherit; }
.script { font-family: var(--script); color: var(--rose-deep); }
.hint { font-size: 14px; color: var(--muted); }

/* Floating heart balloons (balloons.js) */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.balloon { position: absolute; animation: float var(--d, 9s) ease-in-out infinite; animation-delay: var(--delay, 0s); }
@keyframes float { 50% { transform: translateY(-18px) rotate(2deg); } }

/* Login */
.login { position: relative; z-index: 1; min-height: 100svh; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(320px, 100%); padding: 28px 24px 24px; border-radius: 24px;
  background: rgba(255, 250, 246, .82); border: 1px solid #EED6D2;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 14px 40px rgba(180, 110, 110, .16); text-align: center;
}
.card .icon { font-size: 30px; color: var(--rose); }
.card h1 { font-family: var(--script); font-weight: 700; color: var(--rose-deep); font-size: 30px; margin: 4px 0; }
.card p { margin: 0 0 18px; }
.card input {
  display: block; width: 100%; margin-bottom: 10px; padding: 12px 14px; font: inherit; font-size: 16px;
  color: var(--ink); background: #fff; border: 1px solid #F0DCD8; border-radius: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.card input:focus { border-color: var(--rose); box-shadow: 0 0 0 4px rgba(217, 138, 152, .18); }
.btn {
  width: 100%; margin-top: 6px; padding: 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--rose); color: #fff; font-size: 17px; font-weight: 500;
  transition: transform .15s, background .2s;
}
.btn:hover { background: #CF7D8C; }
.btn:active { transform: scale(.97); }
.err { color: #B5586A; font-size: 14px; margin-top: 10px; }
.shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* Sections */
section {
  position: relative; z-index: 1; min-height: 100svh; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 16px; text-align: center;
}
section h2 { font-family: var(--script); font-weight: 700; color: var(--rose-deep); font-size: clamp(30px, 7vw, 46px); margin: 0 0 6px; }
.down { margin-top: 28px; opacity: 0; transition: opacity .6s; color: var(--muted); text-decoration: none; font-size: 15px; }
.down.show { opacity: 1; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* 1. Envelope */
.env { position: relative; width: 280px; height: 220px; margin-top: 200px; cursor: pointer; perspective: 800px; border: 0; padding: 0; background: none; }
.env > span { position: absolute; border-radius: 8px; }
.env .back { inset: 0; background: #D990A0; }
.env .letter {
  left: 14px; right: 14px; top: 10px; height: 205px; background: var(--paper); z-index: 2;
  padding-top: 18px; transition: transform 1s cubic-bezier(.2, .8, .2, 1) .35s;
  box-shadow: 0 4px 14px rgba(150, 80, 80, .12);
}
.env .pocket { inset: 0; background: #E9AEBB; clip-path: polygon(0 28%, 50% 62%, 100% 28%, 100% 100%, 0 100%); z-index: 3; }
.env .flap { left: 0; right: 0; top: 0; height: 127px; background: #DE9CAA; clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top; transition: transform .5s; z-index: 4; }
.env .seal {
  left: 50%; top: 104px; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%;
  background: var(--rose-deep); color: #F8E3D5; display: grid; place-items: center; font-size: 18px; z-index: 5; transition: opacity .3s;
}
.env.open .flap { transform: rotateX(180deg); z-index: 1; }
.env.open .seal { opacity: 0; }
.env.open .letter { transform: translateY(-180px); }
.letter small { display: block; font-family: 'Reem Kufi Fun', sans-serif; font-weight: 700; color: var(--wood); font-size: 17px; }
.letter b { display: block; font-family: var(--script); font-size: 54px; line-height: 1.25; }
.letter b span:nth-child(1) { color: #D16F86; }
.letter b span:nth-child(2) { color: #E0A24A; }
.letter b span:nth-child(3) { color: #7C9A72; }
.letter em { font-style: normal; font-size: 14px; color: var(--muted); }
.letter .love { display: block; margin-top: 8px; font-family: var(--script); font-size: 24px; color: var(--rose-deep); }
.letter .sign { display: block; margin-top: 2px; font-family: 'Tajawal', sans-serif; font-weight: 500; font-size: 19px; color: var(--ink); }

/* 2. Cake */
.cake { position: relative; width: 240px; margin-top: 20px; cursor: pointer; border: 0; background: none; padding: 0; }
.candles { display: flex; justify-content: center; gap: 20px; height: 64px; align-items: flex-end; }
.candle { position: relative; width: 10px; height: 38px; border-radius: 3px; background: repeating-linear-gradient(45deg, var(--peach) 0 5px, #fff 5px 10px); }
.flame {
  position: absolute; bottom: 39px; left: 50%; width: 12px; height: 20px; margin-left: -6px;
  background: var(--gold); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  box-shadow: 0 0 14px 4px rgba(246, 199, 106, .55); transform-origin: bottom;
  animation: flicker .5s ease-in-out infinite alternate; transition: opacity .4s, transform .4s;
}
.candle:nth-child(2) .flame { animation-delay: -.2s; }
.candle:nth-child(3) .flame { animation-delay: -.35s; }
.candle:nth-child(4) .flame { animation-delay: -.1s; }
@keyframes flicker { to { transform: scaleY(1.15) rotate(3deg); } }
.cake.out .flame { opacity: 0; transform: scaleY(.2); }
.tier { position: relative; margin: 0 auto; border-radius: 14px 14px 8px 8px; }
.tier.top { width: 180px; height: 66px; background: #E7A3B1; }
.tier.bottom { width: 240px; height: 84px; background: var(--rose); }
.tier::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 26px; border-radius: 14px 14px 0 0; background: #FFF6EE;
  -webkit-mask: radial-gradient(9px 12px at 50% 100%, #000 98%, transparent) 0 0 / 30px 100% repeat-x, linear-gradient(#000 0 0) top / 100% 14px no-repeat;
  mask: radial-gradient(9px 12px at 50% 100%, #000 98%, transparent) 0 0 / 30px 100% repeat-x, linear-gradient(#000 0 0) top / 100% 14px no-repeat;
}
.plate { width: 280px; height: 14px; margin: 0 -20px; border-radius: 8px; background: var(--wood); }
.mic { margin-top: 26px; padding: 10px 18px; border-radius: 999px; border: 1px solid #EBCFCB; background: rgba(255, 255, 255, .7); color: var(--rose-deep); cursor: pointer; }
.confetti { position: fixed; width: 9px; height: 13px; border-radius: 2px; pointer-events: none; z-index: 10; animation: burst 1.8s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--x), var(--y)) rotate(600deg); opacity: 0; } }

/* 3. Photo string — the string + bulbs are one repeating SVG, 2 photos per period (380px). */
.string {
  direction: ltr; width: 100%; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity;
  display: flex; padding: 0 0 40px; margin-top: 18px; scrollbar-width: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='380' height='60'%3E%3Cpath d='M0 20Q95 60 190 20T380 20' stroke='%237A5C4F' stroke-width='1.5' fill='none'/%3E%3Cg fill='%23F6C76A'%3E%3Ccircle cx='40' cy='34' r='5'%3E%3Canimate attributeName='opacity' values='1;.4;1' dur='2.4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='150' cy='34' r='5'%3E%3Canimate attributeName='opacity' values='.4;1;.4' dur='2.1s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='230' cy='7' r='5'%3E%3Canimate attributeName='opacity' values='1;.5;1' dur='1.8s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='340' cy='7' r='5'%3E%3Canimate attributeName='opacity' values='.5;1;.5' dur='2.7s' repeatCount='indefinite'/%3E%3C/circle%3E%3C/g%3E%3C/svg%3E") 0 0 repeat-x local;
}
.string::-webkit-scrollbar { display: none; }
.string { cursor: grab; user-select: none; -webkit-user-select: none; }
.string.dragging { cursor: grabbing; scroll-snap-type: none; }
.rail { width: 100%; }
.pol {
  flex: 0 0 150px; height: 190px; margin: 46px 20px 0; scroll-snap-align: center;
  transform-origin: 50% -12px; animation: sway 4s ease-in-out infinite; perspective: 700px;
  border: 0; padding: 0; background: none; cursor: pointer;
}
.pol:nth-child(even) { margin-top: 6px; }
.pol:nth-child(3n) { animation-delay: -1.3s; }
.pol:nth-child(3n+1) { animation-delay: -2.6s; }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.pol .in { position: relative; display: block; width: 100%; height: 100%; transition: transform .7s; transform-style: preserve-3d; }
.pol.flip .in { transform: rotateY(180deg); }
.pol .face, .pol .note {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: #fff; border-radius: 3px; box-shadow: 0 8px 18px rgba(120, 70, 60, .18); padding: 8px 8px 34px;
}
.pol .face img, .pol .face i, .pol .face video { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; border-radius: 2px; }
.pol .note {
  transform: rotateY(180deg); display: grid; place-items: center; padding: 14px; background: #FFF8F2;
  font-family: var(--script); color: var(--ink); font-size: 19px; line-height: 1.5; direction: rtl;
}
.pol::before {
  content: ''; position: absolute; top: -14px; left: 50%; width: 9px; height: 22px; margin-left: -4.5px;
  background: var(--wood); border-radius: 2px; z-index: 2;
}

/* Video polaroid: ▶ badge */
.pol.vid::after {
  content: '▶'; position: absolute; top: 16px; right: 16px; z-index: 2; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; color: #fff; background: rgba(169, 82, 106, .78);
}
#viewer {
  width: min(92vw, 520px); max-height: 92svh; padding: 10px; border: 0; border-radius: 18px;
  background: var(--paper); box-shadow: 0 20px 60px rgba(90, 40, 50, .35); overflow: visible;
}
#viewer::backdrop { background: rgba(90, 50, 55, .55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
#viewer video { display: block; width: 100%; max-height: calc(92svh - 20px); border-radius: 10px; background: #000; }
#viewer .close {
  position: absolute; top: -14px; left: -14px; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--rose); color: #fff; font-size: 16px; box-shadow: 0 4px 12px rgba(90, 40, 50, .3);
}

/* 4. Final letter */
.paper {
  width: min(380px, 100%); padding: 32px 28px 22px; border-radius: 6px; background-color: var(--paper);
  background-image: repeating-linear-gradient(transparent 0 35px, #F1E2DC 35px 36px); background-position: 0 18px;
  box-shadow: 0 14px 34px rgba(150, 90, 80, .15); transform: rotate(-1.5deg);
}
.paper h2 { font-size: clamp(26px, 7vw, 34px); }
.paper p { font-family: var(--script); font-size: 21px; line-height: 36px; margin: 8px 0 16px; }
.paper footer { display: flex; justify-content: space-between; align-items: center; }
.song {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px;
  background: #F3DCD8; color: var(--rose-deep); text-decoration: none; font-weight: 500; transition: transform .15s;
}
.song:hover { transform: scale(1.04); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01s !important; }
  html { scroll-behavior: auto; }
}
#viewer img { display: block; width: 100%; max-height: calc(92svh - 20px); object-fit: contain; border-radius: 10px; }
#viewer [hidden] { display: none; }
.pol .face img { background: #F3E4DE; } /* soft tint while a photo loads */
/* Teaser: photos are blurred on the string until she opens them, then stay clear. */
.pol .face img, .pol .face video { clip-path: inset(0 round 2px); transition: filter .8s ease; }
.pol:not(.seen) .face img, .pol:not(.seen) .face video { filter: blur(12px) saturate(1.1); }
.letter > * { transition: opacity .4s .4s; }
.env:not(.open) .letter > * { opacity: 0; transition-delay: 0s; } /* no peeking through the closed flap */
