: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, .you-cake .frame::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(78vw, 420px); max-height: 80svh; 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(80svh - 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(80svh - 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 */
/* Viewer flip: content shows on the front, a heart on the back. */
#viewer { transform-style: preserve-3d; }
#viewer > * { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
#viewer::before {
  content: '♡'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 56px; color: var(--rose);
  background: var(--paper); border-radius: inherit; transform: rotateY(180deg);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
#viewer[open]::backdrop { animation: fadein .5s ease; }
@keyframes fadein { from { opacity: 0; } }

/* 4. Gift card */
.gift-card {
  position: relative; width: min(340px, 100%); margin-top: 22px; padding: 16px 18px 18px; border-radius: 20px; overflow: hidden;
  color: var(--rose-deep); text-align: right; transform: rotate(-2deg);
  background:
    radial-gradient(circle at 100% 0, #F6CFD7 0 30%, transparent 30.5%),
    radial-gradient(circle at 0 55%, #F8DAE0 0 34%, transparent 34.5%),
    #FCE8EC;
  box-shadow: 0 18px 40px rgba(150, 80, 80, .2);
}
.gift-card::after {
  content: ''; position: absolute; inset: -50%; pointer-events: none;
  background: linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, .35) 50%, transparent 60%);
  animation: sheen 4.5s ease-in-out infinite;
}
@keyframes sheen { 0%, 60% { transform: translateX(-60%); } 100% { transform: translateX(60%); } }
.gift-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.gift-top small { display: block; font-size: 13px; opacity: .9; }
.gift-top b { font-family: 'Reem Kufi Fun', sans-serif; font-size: 24px; }
.gift-heart { font-size: 30px; line-height: 1; }
.scratch { position: relative; border-radius: 14px; overflow: hidden; background: var(--paper); }
.gift-secret { display: grid; justify-items: center; gap: 4px; padding: 18px 12px; color: var(--rose-deep); text-align: center; }
.gift-secret b { font-family: var(--script); font-size: 30px; line-height: 1.2; }
.gift-secret code { direction: ltr; font-family: ui-monospace, Menlo, monospace; font-size: 20px; letter-spacing: 1px; color: var(--ink); user-select: all; -webkit-user-select: all; }
.gift-secret small { font-size: 14px; color: var(--muted); }
.gift-secret small:empty { display: none; }
#scratchLayer { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; transition: opacity .7s ease; z-index: 1; }
#scratchLayer.gone { opacity: 0; pointer-events: none; }
#scratchLayer:focus-visible { outline: 3px solid var(--rose); outline-offset: -3px; }
.gift-after { margin-top: 22px; display: grid; justify-items: center; gap: 8px; }
.gift-after .btn { width: auto; padding: 11px 28px; }
.gift-after p { margin: 4px 0 0; max-width: 320px; }
.gift-after [hidden] { display: none; }
.gift-after[hidden] { display: none; }
.gift-top small { margin-top: 2px; }
.gift-about { margin: 10px 0 2px; max-width: 340px; font-family: var(--script); font-size: 20px; line-height: 1.6; color: var(--ink); }
.chips { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 360px; }
.chips li { padding: 6px 14px; border-radius: 999px; background: #F3DCD8; color: var(--rose-deep); font-size: 14px; font-weight: 500; }
.chips li:last-child { background: transparent; border: 1px dashed #E3C4BF; color: var(--muted); }
.gift-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
section[hidden] { display: none; }
.logout { display: flex; justify-content: center; margin-top: 30px; }
.logout button {
  padding: 8px 18px; border-radius: 999px; border: 1px solid #EBCFCB; background: rgba(255, 255, 255, .6);
  color: var(--muted); font-size: 14px; cursor: pointer; transition: color .2s, border-color .2s;
}
.logout button:hover { color: var(--rose-deep); border-color: var(--rose); }

/* Login: November calendar with a heart on the 23rd, and a tag tied to the card's corner */
.card { position: relative; }
.card .month { font-size: 13px; color: var(--muted); margin: -6px 0 6px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px 2px; margin: 0 0 16px; font-size: 13px; color: #9A8582; }
.cal span { height: 26px; line-height: 26px; }
.cal .wd { color: var(--wood); font-size: 12px; }
.cal .day { position: relative; z-index: 0; color: #fff; font-weight: 500; animation: beat 2.4s ease-in-out infinite; }
/* Heart as its own layer, larger than the 26px cell so it isn't clipped; nudged down so the
   heart is raised 3px because Arabic digits sit high in the line box, so the number looks centered. */
.cal .day::before {
  content: ''; position: absolute; z-index: -1; left: 50%; top: 50%; width: 34px; height: 31px;
  transform: translate(-50%, calc(-50% - 3px)); background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 46 42'%3E%3Cpath fill='%23D98A98' d='M23 40C10 30 2 22 2 13 2 6 8 1 14 1c4 0 7 2 9 6 2-4 5-6 9-6 6 0 12 5 12 12 0 9-8 17-21 27z'/%3E%3C/svg%3E") center / contain no-repeat;
}
@keyframes beat { 0%, 70%, 100% { transform: scale(1); } 80% { transform: scale(1.15); } 90% { transform: scale(1.04); } }
.tag-hang {
  position: absolute; top: 12px; left: 16px; display: flex; flex-direction: column; align-items: center;
  transform-origin: 50% 0; animation: tagsway 3.5s ease-in-out infinite; pointer-events: none;
}
@keyframes tagsway { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
.tag-hang .thread { width: 1px; height: 14px; background: var(--wood); }
.tag-hang .tag {
  position: relative; width: 56px; padding: 16px 0 7px; background: #E8D5BE; text-align: center;
  clip-path: polygon(20% 0, 80% 0, 100% 14%, 100% 100%, 0 100%, 0 14%);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .08));
}
.tag-hang .tag::before { content: ''; position: absolute; top: 5px; left: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--bg); }
.tag-hang b { display: block; font-family: var(--script); font-weight: 700; font-size: 19px; color: #8A4B55; line-height: 1.1; }
.tag-hang small { display: block; color: var(--rose); font-size: 13px; }

/* Her photo as a cake: frosting drips over the top, sprinkles, one candle, a plate. */
.you-cake { margin: 34px 0 0; display: flex; flex-direction: column; align-items: center; }
.you-cake .candle { margin-bottom: -2px; z-index: 2; }
.you-cake .frame {
  position: relative; display: block; width: 170px; height: 162px; overflow: hidden;
  border: 5px solid #E7A3B1; border-radius: 18px 18px 10px 10px; background: #F3E4DE;
  box-shadow: 0 10px 24px rgba(150, 80, 80, .2);
}
.you-cake .frame::before { z-index: 1; height: 24px; } /* band covers the 12px strip above the photo; only drips overlap it */
.you-cake .frame::after {
  content: ''; position: absolute; top: 1px; left: 0; right: 0; height: 12px; z-index: 2;
  background:
    radial-gradient(circle, #F6C76A 2px, transparent 2.5px) 10px 2px / 34px 12px repeat-x,
    radial-gradient(circle, #9FBF94 2px, transparent 2.5px) 27px 7px / 34px 12px repeat-x;
}
.you-cake img { display: block; width: 100%; height: calc(100% - 12px); margin-top: 12px; object-fit: cover; object-position: 50% 25%; }
.you-cake .plate { display: block; width: 210px; height: 12px; margin: 0; border-radius: 8px; }
.you-cake figcaption { margin-top: 12px; font-family: var(--script); font-size: 28px; color: var(--rose-deep); }

/* Soft redraw of the gift card: name on the right, a cupcake with a candle on the left. */
.gift-top { align-items: center; margin-bottom: 12px; }
.gift-name b { display: block; font-family: var(--script); font-size: 30px; line-height: 1.2; color: var(--rose-deep); }
.gift-name small { color: var(--ink); opacity: 1; }
.gift-name em { display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 999px; font-style: normal; font-size: 12px; color: #fff; background: var(--rose); }
.cupcake { width: 92px; height: 100px; flex: none; }
.gift-lock { display: grid; justify-items: center; gap: 2px; }
.gift-lock small { font-size: 14px; color: var(--muted); }
.gift-lock .timer { direction: ltr; font-size: 26px; font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.gift-lock .timer:empty { display: none; }
.gift-lock[hidden], .gift-secret [hidden] { display: none; }
#giftSub:empty, #giftAmount:empty { display: none; }
