/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body {
  height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f8d8e2;
  color: #4a2c3a;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ===== Cinematic ambient background ===== */
.ambient-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(255,255,255,.9) 0 3%, transparent 28%),
    radial-gradient(circle at 84% 78%, rgba(255,122,168,.25), transparent 34%),
    linear-gradient(145deg, #f9dbe5 0%, #f7c8d7 46%, #eeb4c9 100%);
  transition: background 1.2s ease, filter 1.2s ease;
}
.bg-gradient {
  position: absolute;
  width: 70vw;
  height: 70vw;
  border-radius: 50%;
  filter: blur(38px);
  opacity: .42;
  animation: drift 16s ease-in-out infinite alternate;
  will-change: transform;
}
.bg-gradient-1 { top:-25%; left:-20%; background:#fff4f8; }
.bg-gradient-2 { right:-25%; bottom:-30%; background:#e85b88; animation-delay:-7s; }
.bg-glow {
  position:absolute;
  width:180px; height:180px;
  border-radius:50%;
  filter:blur(26px);
  opacity:.26;
  animation: floatGlow 9s ease-in-out infinite alternate;
  will-change: transform;
}
.glow-1 { left:8%; top:45%; background:#ff86ad; }
.glow-2 { right:7%; top:20%; background:#fff; animation-delay:-3s; }
.glow-3 { left:42%; bottom:3%; background:#d63062; animation-delay:-6s; }

.bg-heart {
  position:absolute;
  color:rgba(255,255,255,.17);
  font-family:Georgia,serif;
  text-shadow:0 0 20px rgba(214,48,98,.18);
  animation: heartFloat 13s ease-in-out infinite;
  will-change:transform;
  transform: rotate(var(--r,0deg));
}
.heart-1 { font-size:150px; left:-35px; top:10%; --r:-15deg; animation-delay:-2s; }
.heart-2 { font-size:90px; right:7%; top:32%; --r:14deg; animation-delay:-8s; }
.heart-3 { font-size:220px; right:-75px; bottom:-40px; --r:12deg; animation-delay:-5s; opacity:.11; }
.heart-4 { font-size:62px; left:18%; bottom:8%; --r:0deg; animation-delay:-10s; }
.heart-5 { font-size:48px; left:72%; top:8%; --r:0deg; animation-delay:-4s; }

.sparkles {
  position:absolute;
  inset:-10% -10%;
  opacity:.45;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.9) 0 1px, transparent 2px),
    radial-gradient(circle, rgba(255,255,255,.65) 0 1px, transparent 2px);
  background-size:87px 103px, 131px 149px;
  background-position:12px 20px, 44px 65px;
  animation: sparkleShift 12s linear infinite;
  will-change: transform;
}
.grain {
  position:absolute;
  inset:-50%;
  opacity:.03;
  background-image:url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
  animation: grainMove .6s steps(2) infinite;
}
body.celebrating .ambient-bg {
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,.95), transparent 24%),
    radial-gradient(circle at 20% 20%, #ffabc5, transparent 34%),
    linear-gradient(145deg, #f7b4cb, #d94e7d);
  filter:saturate(1.12) brightness(1.06);
}
@keyframes drift { to { transform:translate3d(8vw,5vh,0) scale(1.08); } }
@keyframes floatGlow { to { transform:translate3d(25px,-35px,0) scale(1.2); opacity:.38; } }
@keyframes heartFloat {
  0%,100% { transform: rotate(var(--r,0deg)) translateY(0); }
  50% { transform: rotate(var(--r,0deg)) translateY(-24px); }
}
@keyframes sparkleShift { to { transform: translate3d(-45px,-65px,0); } }
@keyframes grainMove {
  0% { transform:translate(0,0); }
  25% { transform:translate(2%,-1%); }
  50% { transform:translate(-1%,2%); }
  75% { transform:translate(1%,1%); }
  100% { transform:translate(-2%,-2%); }
}
@media (prefers-reduced-motion: reduce) {
  .bg-gradient,.bg-glow,.bg-heart,.sparkles,.grain { animation:none; }
}

/* ===== Particle canvas ===== */
#fxCanvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* ===== Progress indicator ===== */
.progress-wrap {
  position: fixed;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  width: min(220px, 60vw);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}
.progress-track {
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 3px;
  background: rgba(214, 48, 98, .15);
  border-radius: 999px;
  transform: translateY(-50%);
}
.progress-fill {
  position: absolute;
  top: 50%; left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #ff7aa8, #d63062);
  border-radius: 999px;
  transform: translateY(-50%);
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.progress-dots {
  position: relative;
  display: flex;
  justify-content: space-between;
  width: 100%;
}
.progress-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(214,48,98,.25);
  transition: all .4s ease;
}
.progress-dots span.active {
  background: #d63062;
  border-color: #d63062;
  transform: scale(1.25);
  box-shadow: 0 0 10px rgba(214,48,98,.5);
}

/* ===== Music toggle ===== */
.music-btn {
  position: fixed;
  top: 14px; right: 16px;
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.82);
  box-shadow: 0 4px 14px rgba(214,48,98,.18);
  cursor: pointer;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, background .3s ease;
}
.music-btn:active { transform: scale(.9); }
.music-icon {
  font-size: 20px;
  color: #d63062;
  line-height: 1;
}
.music-bars { display: none; }
.music-btn.playing .music-icon { display: none; }
.music-btn.playing .music-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 18px;
}
.music-btn.playing .music-bars i {
  width: 3px;
  background: #d63062;
  border-radius: 2px;
  animation: bar 0.7s ease-in-out infinite alternate;
}
.music-btn.playing .music-bars i:nth-child(1) { height: 60%; animation-delay: 0s; }
.music-btn.playing .music-bars i:nth-child(2) { height: 100%; animation-delay: .2s; }
.music-btn.playing .music-bars i:nth-child(3) { height: 75%; animation-delay: .4s; }
@keyframes bar { from { transform: scaleY(.4); } to { transform: scaleY(1); } }

/* ===== Screens ===== */
main#story { position: relative; width: 100%; height: 100vh; height: 100dvh; }
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-top: 64px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(40px) scale(.98);
  transition: opacity .7s cubic-bezier(.4,0,.2,1), transform .7s cubic-bezier(.4,0,.2,1);
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.center {
  width: 100%;
  max-width: 480px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  margin: auto;
}

/* ===== Typography ===== */
.hello {
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 800;
  color: #d63062;
  letter-spacing: -0.5px;
  line-height: 1.15;
  animation: rise .8s cubic-bezier(.2,.8,.2,1) both;
}
.sub {
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  color: #6b4458;
  font-weight: 500;
  animation: rise .8s .15s cubic-bezier(.2,.8,.2,1) both;
}
.big-sorry {
  font-size: clamp(2.8rem, 12vw, 4.5rem);
  font-weight: 800;
  color: #d63062;
  letter-spacing: -1px;
  animation: popIn 1s cubic-bezier(.2,.8,.2,1) both;
}
.title {
  font-size: clamp(1.6rem, 6.5vw, 2.2rem);
  font-weight: 800;
  color: #d63062;
  line-height: 1.2;
}
.line {
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  color: #6b4458;
  font-weight: 500;
  opacity: 0;
  transform: translateY(16px);
}
.line.show {
  animation: rise .8s cubic-bezier(.2,.8,.2,1) both;
}

/* ===== Buttons ===== */
.btn {
  font-family: inherit;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 15px 34px;
  cursor: pointer;
  position: relative;
  transition: transform .15s cubic-bezier(.2,.8,.2,1), box-shadow .25s ease, background .25s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  line-height: 1;
  overflow: hidden;
}
.btn.primary {
  background: linear-gradient(135deg, #ff7aa8, #d63062);
  color: #fff;
  box-shadow: 0 8px 24px rgba(214,48,98,.35);
}
.btn.primary:hover { box-shadow: 0 10px 30px rgba(214,48,98,.45); transform: translateY(-2px); }
.btn.primary:active { transform: scale(.94); }
.btn.yes {
  background: linear-gradient(135deg, #ff8fb1, #e63972);
  color: #fff;
  box-shadow: 0 8px 24px rgba(230,57,114,.4);
}
.btn.yes:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(230,57,114,.5); }
.btn.yes:active { transform: scale(.94); }
.btn.yes.unavoidable {
  animation: unavoidablePulse 1.1s ease-in-out infinite;
}
@keyframes unavoidablePulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(230,57,114,.4); }
  50% { box-shadow: 0 0 0 14px rgba(230,57,114,.25), 0 8px 30px rgba(230,57,114,.55); }
}
.btn.no {
  background: rgba(255,255,255,.85);
  color: #a04060;
  box-shadow: 0 4px 14px rgba(160,64,96,.15);
  border: 1.5px solid rgba(214,48,98,.2);
}
.btn.no:hover { background: rgba(255,255,255,.8); transform: translateY(-2px); }
.btn.no:active { transform: scale(.94); }
.btn-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
#finalBtnRow { margin-top: 28px; }

/* ===== Ripple effect ===== */
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.5);
  pointer-events: none;
  transform: scale(0);
  animation: ripple .6s ease-out;
}
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

/* ===== Meter card (Screen 3) ===== */
.meter-card {
  background: rgba(255,250,252,.82);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  padding: 30px 26px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(214,48,98,.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.meter-value {
  font-size: 2.6rem;
  font-weight: 800;
  color: #d63062;
  line-height: 1;
  transition: transform .2s ease;
}
.meter-emoji {
  font-size: 2.2rem;
  line-height: 1;
}
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd1dc, #ff7aa8, #d63062);
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #d63062;
  box-shadow: 0 4px 12px rgba(214,48,98,.4);
  cursor: pointer;
  transition: transform .15s ease;
}
.slider::-webkit-slider-thumb:active { transform: scale(1.2); }
.slider::-moz-range-thumb {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #d63062;
  box-shadow: 0 4px 12px rgba(214,48,98,.4);
  cursor: pointer;
}
.meter-label {
  font-size: 1.15rem;
  font-weight: 600;
  color: #6b4458;
  min-height: 1.4em;
  transition: opacity .25s ease;
}

/* ===== Letter / envelope centerpiece (Screen 4) ===== */
.letter-center { gap: 18px; }

.envelope-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.envelope-hint {
  font-size: clamp(1.05rem, 4.2vw, 1.25rem);
  color: #6b4458;
  font-weight: 500;
  max-width: 320px;
}
.envelope {
  position: relative;
  width: min(280px, 78vw);
  height: calc(min(280px, 78vw) * 0.62);
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  perspective: 800px;
}
.envelope-back,
.envelope-front {
  position: absolute;
  inset: 0;
  border-radius: 10px;
}
.envelope-back {
  background: linear-gradient(160deg, #ffe1ea, #ffc7d9);
  box-shadow: 0 16px 40px rgba(214,48,98,.28);
}
.envelope-front {
  background: linear-gradient(160deg, #fff0f5, #ffd6e4);
  clip-path: polygon(0 100%, 50% 42%, 100% 100%);
  z-index: 2;
}
.envelope-flap {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 62%;
  background: linear-gradient(200deg, #ffb8cf, #ff8fb1);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .7s cubic-bezier(.4,0,.2,1);
  z-index: 3;
  border-radius: 10px 10px 0 0;
}
.wax-seal {
  position: absolute;
  top: 50%; left: 50%;
  width: 46px; height: 46px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ff5c86, #c72158);
  border-radius: 50%;
  color: #ffe4ec;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(199,33,88,.5), inset 0 -2px 4px rgba(0,0,0,.15);
  z-index: 4;
  transition: transform .5s cubic-bezier(.34,1.56,.64,1), opacity .4s ease;
}
.envelope-tap {
  font-size: .9rem;
  color: #a45b78;
  letter-spacing: .3px;
  animation: pulseHint 1.8s ease-in-out infinite;
}
@keyframes pulseHint { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

.envelope-wrap.opening .envelope-flap {
  transform: rotateX(180deg);
}
.envelope-wrap.opening .wax-seal {
  transform: translate(-50%, -50%) scale(0) rotate(35deg);
  opacity: 0;
}
.envelope-wrap.opening .envelope-tap { opacity: 0; }

.letter-card {
  background: rgba(255,252,253,.94);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 20px;
  padding: 26px 24px 24px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(214,48,98,.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: letterRise .6s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes letterRise {
  from { opacity: 0; transform: translateY(30px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.polaroid {
  background: #fff;
  padding: 10px 10px 34px;
  border-radius: 4px;
  box-shadow: 0 10px 24px rgba(0,0,0,.18);
  transform: rotate(-3deg);
  width: 72%;
  max-width: 220px;
}
.polaroid-img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 2px;
}
.polaroid-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #ffd6e4, #ff9fbd);
  font-size: 1.8rem;
}
.polaroid-fallback small {
  font-size: .7rem;
  font-weight: 600;
  color: #a04060;
  line-height: 1.3;
  text-align: center;
}
.polaroid-caption {
  display: block;
  margin-top: 8px;
  font-family: "Caveat", cursive;
  font-size: 1.15rem;
  color: #a45b78;
  text-align: center;
}

.handwritten {
  font-family: "Caveat", cursive;
  font-size: clamp(1.25rem, 5vw, 1.55rem);
  line-height: 1.45;
  color: #5a3848;
  text-align: left;
  width: 100%;
}
.handwritten p { margin-bottom: 6px; }
.handwritten .signature {
  margin-top: 10px;
  font-size: clamp(1.4rem, 5.5vw, 1.7rem);
  color: #d63062;
  text-align: right;
}

/* ===== Serious part (Screen 5) ===== */
.serious .serious-head {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: #b04060;
}
.serious-msg {
  background: rgba(255,255,255,.82);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 24px;
  padding: 28px 26px;
  box-shadow: 0 12px 40px rgba(160,64,96,.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.serious-msg p {
  font-size: clamp(1.05rem, 4.2vw, 1.2rem);
  color: #5a3848;
  font-weight: 500;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(14px);
}
.serious-msg p.show {
  animation: rise .9s cubic-bezier(.2,.8,.2,1) both;
}

/* ===== Final question (Screen 6) ===== */
.final-q .big {
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 800;
  color: #d63062;
  line-height: 1.15;
  animation: rise .8s cubic-bezier(.2,.8,.2,1) both;
}
.response { gap: 18px; }
.resp-line {
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 600;
  color: #6b4458;
  opacity: 0;
  transform: translateY(14px);
}
.resp-line.show { animation: rise .8s cubic-bezier(.2,.8,.2,1) both; }
.resp-final {
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-weight: 800;
  color: #d63062;
  opacity: 0;
  transform: translateY(14px);
}
.resp-final.show { animation: rise .9s .2s cubic-bezier(.2,.8,.2,1) both; }
.yay {
  font-size: clamp(2.6rem, 12vw, 4rem);
  font-weight: 800;
  color: #d63062;
  letter-spacing: -1px;
  animation: popIn .8s cubic-bezier(.2,.8,.2,1) both;
}

/* ===== Keyframes ===== */
@keyframes rise {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(.6); }
  60% { opacity: 1; transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes meterBump {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.meter-value.bump { animation: meterBump .3s ease; }

/* ===== Responsive ===== */
@media (min-width: 700px) {
  .center { gap: 28px; }
  .serious-msg { padding: 36px 40px; }
}
@media (max-width: 380px) {
  .btn { padding: 13px 26px; font-size: .98rem; }
  .btn-row { flex-direction: column; width: 100%; }
  .btn-row .btn { width: 100%; }
}
