:root {
  --ivory: #fbf4eb;
  --pearl: #fffaf4;
  --champagne: #d8b875;
  --rose: #f5bdc8;
  --ink: #4f372f;
  --shadow: rgba(80, 48, 34, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.86), transparent 30rem),
    linear-gradient(145deg, #f6e6dd 0%, var(--ivory) 46%, #ead6c5 100%);
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
}

.stage-wrap {
  width: 100%;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.card {
  position: relative;
  width: min(430px, calc((100svh - 36px) * 9 / 16), calc(100vw - 36px));
  height: auto;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  isolation: isolate;
  background: var(--ivory);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(78, 49, 36, 0.28);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.012);
  transition: opacity 980ms ease, transform 1800ms ease;
  z-index: 1;
}

.scene.is-active {
  opacity: 1;
  transform: scale(1);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    linear-gradient(to bottom, rgba(255, 251, 245, 0.18), transparent 30%, rgba(79, 47, 36, 0.12)),
    radial-gradient(circle at 50% 42%, transparent 0 42%, rgba(255, 247, 236, 0.16) 72%, rgba(122, 75, 50, 0.2) 100%);
  mix-blend-mode: soft-light;
}

.mode-badge {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 10;
  max-width: calc(100% - 132px);
  padding: 7px 11px;
  border: 1px solid rgba(202, 160, 83, 0.76);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.9);
  color: #6b4a2e;
  box-shadow: 0 8px 22px rgba(88, 54, 39, 0.12);
  backdrop-filter: blur(12px);
  font: 700 10px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
}

.mode-badge[hidden] {
  display: none;
}

.soft-glow {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 22%;
  aspect-ratio: 1;
  z-index: 3;
  pointer-events: none;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 252, 221, 0.92), rgba(238, 185, 99, 0.34) 36%, transparent 72%);
  filter: blur(2px);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.35);
}

.soft-glow.bloom {
  animation: glowBloom 1200ms ease-out;
}

.sparkle-layer,
.petal-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255, 246, 195, 0.96);
  box-shadow: 0 0 12px rgba(255, 231, 151, 0.95);
  animation: sparkleDrift var(--dur) ease-out forwards;
}

.petal {
  position: absolute;
  width: var(--w);
  height: calc(var(--w) * 1.45);
  border-radius: 80% 20% 70% 30%;
  background: linear-gradient(135deg, rgba(255, 232, 236, 0.94), rgba(242, 165, 181, 0.82));
  box-shadow: 0 2px 8px rgba(170, 92, 102, 0.13);
  opacity: 0;
  transform: translate3d(0, 0, 0) rotate(var(--rot));
  animation: petalFloat var(--dur) cubic-bezier(0.22, 0.62, 0.38, 1) forwards;
}

.celebration-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: hidden;
}

.celebration-particle {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  will-change: transform, opacity;
  pointer-events: none;
}

.celebration-particle.rice {
  width: var(--size);
  height: calc(var(--size) * 2.15);
  border-radius: 999px;
  background: rgba(255, 255, 248, 0.92);
  box-shadow: 0 0 5px rgba(255, 246, 218, 0.68);
}

.celebration-particle.celebration-petal {
  width: var(--size);
  height: calc(var(--size) * 1.45);
  border-radius: 80% 20% 75% 25%;
  background: linear-gradient(135deg, rgba(255, 232, 237, 0.9), rgba(244, 174, 188, 0.74));
  box-shadow: 0 2px 8px rgba(160, 83, 98, 0.12);
}

.celebration-particle.celebration-spark {
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  background: rgba(255, 233, 164, 0.92);
  box-shadow: 0 0 11px rgba(242, 199, 104, 0.74);
}

.music-toggle {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 8;
  min-width: 92px;
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid rgba(202, 160, 83, 0.76);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.82);
  color: #6b4a2e;
  font: 700 12px/1.1 Georgia, "Times New Roman", serif;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(88, 54, 39, 0.12);
  backdrop-filter: blur(12px);
  cursor: pointer;
}

.music-toggle.is-off {
  color: rgba(88, 61, 40, 0.76);
}

.cover-copy {
  position: absolute;
  inset-inline: 24px;
  top: 43%;
  z-index: 5;
  text-align: center;
  color: #fff9ee;
  text-shadow: 0 2px 10px rgba(65, 38, 28, 0.5), 0 0 24px rgba(220, 181, 124, 0.34);
  transition: opacity 650ms ease, transform 650ms ease;
}

.cover-copy.is-hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.cover-copy h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2rem, 10vw, 3.15rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.cover-copy p {
  margin: 12px 0 0;
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  font-weight: 500;
}

.final-message {
  position: absolute;
  inset-inline: clamp(18px, 6vw, 30px);
  top: clamp(64px, 11svh, 92px);
  z-index: 6;
  padding: clamp(17px, 5.4vw, 25px) clamp(15px, 5vw, 24px);
  border: 1px solid rgba(216, 184, 117, 0.46);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(255, 252, 246, 0.82), rgba(255, 244, 238, 0.62));
  box-shadow: 0 18px 48px rgba(78, 48, 35, 0.16);
  backdrop-filter: blur(8px);
  text-align: center;
  opacity: 0;
  transform: translateY(16px) scale(0.985);
  pointer-events: none;
  transition: opacity 900ms ease, transform 900ms ease;
}

.final-message.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.final-kicker {
  margin: 0 0 8px;
  color: #96704a;
  font-size: clamp(0.84rem, 3.2vw, 1rem);
  font-weight: 600;
}

.final-message h2 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.55rem, 6.4vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0;
  color: #5b3c31;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  transform: translateX(-0.08em);
}

.couple {
  margin: 11px 0 6px;
  font-family: "Great Vibes", "Brush Script MT", cursive;
  font-size: clamp(2.05rem, 9.5vw, 3.35rem);
  line-height: 1;
  color: #b98f4d;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.8);
}

.message {
  max-width: 26ch;
  margin: 12px auto 0;
  font-size: clamp(1.04rem, 4.35vw, 1.28rem);
  line-height: 1.22;
  font-weight: 500;
}

.sender {
  margin: 14px 0 0;
  color: #705246;
  font-size: clamp(0.98rem, 4vw, 1.15rem);
  line-height: 1.2;
  font-weight: 600;
}

.final-tap-hint,
.replay-button {
  position: absolute;
  left: 50%;
  z-index: 9;
  border: 1px solid rgba(202, 160, 83, 0.68);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.78);
  color: #6b4a2e;
  box-shadow: 0 10px 28px rgba(88, 54, 39, 0.14);
  backdrop-filter: blur(10px);
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  letter-spacing: 0;
  white-space: nowrap;
}

.final-tap-hint {
  bottom: max(82px, calc(env(safe-area-inset-bottom) + 72px));
  padding: 8px 18px;
  font-size: clamp(0.98rem, 4.1vw, 1.14rem);
  font-weight: 600;
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  pointer-events: none;
  transition: opacity 700ms ease, transform 700ms ease;
}

.final-tap-hint.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.final-tap-hint.is-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

.replay-button {
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px));
  min-width: 96px;
  min-height: 38px;
  padding: 8px 22px;
  font-size: clamp(1rem, 4.2vw, 1.14rem);
  font-weight: 700;
  opacity: 0;
  transform: translateX(-50%) translateY(14px);
  pointer-events: none;
  cursor: pointer;
  transition: opacity 700ms ease, transform 700ms ease, background-color 200ms ease;
}

.replay-button.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.replay-button:active {
  background: rgba(255, 245, 232, 0.92);
}

@keyframes glowBloom {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25);
  }
  24% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(6.4);
  }
}

@keyframes sparkleDrift {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.4);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx), var(--dy), 0) scale(1.25);
  }
}

@keyframes petalFloat {
  0% {
    opacity: 0;
    transform: translate3d(0, 10px, 0) rotate(var(--rot)) scale(0.86);
  }
  12% {
    opacity: var(--alpha);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx), var(--dy), 0) rotate(calc(var(--rot) + var(--spin))) scale(1);
  }
}

@media (max-width: 560px) {
  .stage-wrap {
    padding: 0;
  }

  .card {
    width: 100vw;
    height: 100svh;
    border-radius: 0;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene,
  .cover-copy,
  .final-message,
  .final-tap-hint,
  .replay-button {
    transition-duration: 200ms;
  }

  .soft-glow,
  .sparkle,
  .petal,
  .celebration-particle {
    animation-duration: 1ms;
  }
}
