:root {
  --card-max-width: min(100vw, 430px);
  --card-max-height: min(100dvh, 764px);

  /* Candle flame tuning: adjust these if the wick position changes. */
  --left-flame-x: 37.1%;
  --left-flame-y: 15.7%;
  --right-flame-x: 61.8%;
  --right-flame-y: 16.8%;
  --flame-width: 4.35%;
  --flame-height: 6.25%;

  --gold: #b98b35;
  --deep-gold: #8d6422;
  --wine-brown: #6b2520;
  --cream: #fff8ec;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--wine-brown);
  background:
    radial-gradient(circle at 50% 20%, rgba(191, 146, 71, 0.18), transparent 32%),
    linear-gradient(145deg, #19100d 0%, #332017 48%, #120d0b 100%);
  font-family: Georgia, "Times New Roman", serif;
}

button {
  font: inherit;
}

.page-shell {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
}

.card {
  position: relative;
  width: min(var(--card-max-width), calc(var(--card-max-height) * 9 / 16));
  aspect-ratio: 9 / 16;
  max-height: 100dvh;
  overflow: hidden;
  background: #f7efe3;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 236, 188, 0.26);
  isolation: isolate;
}

.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

.scene.active {
  opacity: 1;
  pointer-events: auto;
}

.scene img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-cover {
  cursor: pointer;
}

.scene-cover::after,
.scene-candles::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene-cover::after {
  background: linear-gradient(to bottom, transparent 62%, rgba(45, 29, 17, 0.12) 100%);
}

.scene-candles::after {
  background:
    radial-gradient(circle at 50% 13%, rgba(255, 198, 97, 0.08), transparent 21%),
    linear-gradient(to bottom, rgba(20, 11, 8, 0.06), rgba(10, 5, 4, 0.17));
}

.tap-prompt {
  position: absolute;
  left: 50%;
  bottom: 7.2%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 0.42rem 1.15rem;
  color: #fff9e9;
  border: 1px solid rgba(184, 138, 48, 0.44);
  border-radius: 999px;
  background: rgba(90, 61, 28, 0.24);
  box-shadow: 0 10px 26px rgba(103, 69, 23, 0.15);
  font-size: clamp(1rem, 4vw, 1.25rem);
  letter-spacing: 0;
  text-shadow: 0 1px 8px rgba(78, 53, 19, 0.42);
  animation: softPulse 2.15s ease-in-out infinite;
}

.candle-hit {
  position: absolute;
  z-index: 5;
  width: 20%;
  height: 18%;
  top: 9%;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.candle-hit-left {
  left: 27%;
}

.candle-hit-right {
  left: 52%;
}

.candle-hit.hidden {
  display: none;
}

.light-hint {
  position: absolute;
  z-index: 4;
  transform: translateX(-50%);
  padding: 0.35rem 0.72rem;
  color: rgba(255, 246, 226, 0.92);
  border: 1px solid rgba(255, 218, 154, 0.24);
  border-radius: 999px;
  background: rgba(42, 21, 8, 0.35);
  box-shadow: 0 8px 18px rgba(12, 5, 2, 0.2);
  font-size: clamp(0.68rem, 2.7vw, 0.82rem);
  line-height: 1;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
  transition: opacity 0.22s ease, transform 0.22s ease;
  animation: hintGlow 2.4s ease-in-out infinite;
}

.light-hint-left {
  left: var(--left-flame-x);
  top: 23.8%;
}

.light-hint-right {
  left: var(--right-flame-x);
  top: 24.8%;
}

.light-hint.hidden {
  opacity: 0;
  transform: translate(-50%, 5px);
  pointer-events: none;
  animation: none;
}

.flame {
  position: absolute;
  left: var(--flame-x);
  top: var(--flame-y);
  z-index: 6;
  width: var(--flame-width);
  height: var(--flame-height);
  opacity: 0;
  transform: translate(-50%, -92%) rotate(-1deg) scale(0.82);
  transform-origin: 50% 92%;
  pointer-events: none;
  filter: blur(0.04rem);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.flame.visible {
  opacity: 1;
  transform: translate(-50%, -92%) rotate(-1deg) scale(1);
  animation: flicker 1.55s ease-in-out infinite alternate;
}

.flame::before,
.flame::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  transform-origin: 50% 88%;
  border-radius: 56% 44% 58% 42% / 70% 70% 30% 30%;
}

.flame::before {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 48% 68%, rgba(255, 255, 238, 0.95) 0 12%, rgba(255, 239, 154, 0.86) 21%, transparent 44%),
    radial-gradient(ellipse at 52% 48%, rgba(255, 207, 80, 0.96) 0 31%, rgba(238, 96, 19, 0.92) 60%, rgba(177, 54, 4, 0.08) 78%, transparent 100%);
  box-shadow:
    0 0 0.38rem rgba(255, 231, 137, 0.52),
    0 0 0.9rem rgba(255, 138, 34, 0.26);
  filter: blur(0.01rem);
  animation: flameBody 1.18s ease-in-out infinite alternate;
}

.flame::after {
  width: 38%;
  height: 56%;
  bottom: 7%;
  background: linear-gradient(to top, rgba(50, 45, 155, 0.72), rgba(255, 252, 229, 0.96) 28%, rgba(255, 255, 249, 0.92) 67%, transparent 100%);
  border-radius: 48% 52% 42% 58% / 62% 62% 38% 38%;
  filter: blur(0.015rem);
  opacity: 0.82;
  animation: flameCore 0.95s ease-in-out infinite alternate;
}

.flame-left {
  --flame-x: var(--left-flame-x);
  --flame-y: var(--left-flame-y);
}

.flame-right {
  --flame-x: var(--right-flame-x);
  --flame-y: var(--right-flame-y);
}

.flame-right.visible {
  animation-duration: 1.78s;
  animation-delay: -0.62s;
}

.flame-right::before {
  animation-duration: 1.36s;
  animation-delay: -0.34s;
}

.flame-right::after {
  animation-duration: 1.08s;
  animation-delay: -0.48s;
}

.scene-final {
  z-index: 8;
}

.scene-final::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(255, 248, 235, 0.12), transparent 42%),
    radial-gradient(ellipse at 50% 31%, rgba(255, 250, 240, 0.42), transparent 42%);
}

.final-message {
  position: absolute;
  left: 8.5%;
  right: 8.5%;
  top: 20.7%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: var(--wine-brown);
  text-wrap: balance;
  height: 58%;
}

.final-message p {
  max-width: 100%;
  margin: 0;
  opacity: 0;
  transform: translateY(12px);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.62);
}

.scene-final.active .final-message p {
  animation: messageIn 1s ease forwards;
}

.scene-final.active .headline {
  animation-delay: 0.2s;
}

.scene-final.active .message {
  animation-delay: 0.4s;
}

.scene-final.active .date {
  animation-delay: 0.62s;
}

.couple-names {
  width: 100%;
  color: #9b2d26;
  font-family: "Brush Script MT", "Snell Roundhand", "Segoe Script", cursive;
  font-size: clamp(2.45rem, 11.2vw, 3.55rem);
  line-height: 0.98;
}

.headline {
  width: 86%;
  margin-top: 1.05rem;
  color: var(--deep-gold);
  font-size: clamp(1.18rem, 5vw, 1.58rem);
  line-height: 1.16;
  font-weight: 700;
}

.final-message .headline {
  margin-top: 1.05rem;
}

.message {
  width: 80%;
  margin-top: 0.95rem;
  color: #74433b;
  font-size: clamp(0.98rem, 4vw, 1.2rem);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.date {
  margin-top: 1.1rem;
  color: #9a6f2e;
  font-size: clamp(0.82rem, 3.2vw, 1rem);
  line-height: 1.3;
}

.sender {
  margin-top: 0.8rem;
  color: #7d5b3a;
  font-size: clamp(0.72rem, 2.8vw, 0.9rem);
  font-style: italic;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.date[hidden],
.sender[hidden] {
  display: none;
}

.scene-final.active .sender {
  animation-delay: 0.78s;
}

.replay-button {
  position: absolute;
  left: 50%;
  bottom: 7.2%;
  z-index: 4;
  transform: translateX(-50%);
  min-width: 7rem;
  min-height: 2.6rem;
  padding: 0.54rem 1.35rem;
  border: 1px solid rgba(184, 138, 48, 0.48);
  border-radius: 999px;
  color: #fff9e9;
  background: rgba(90, 61, 28, 0.28);
  box-shadow: 0 10px 26px rgba(103, 69, 23, 0.16);
  cursor: pointer;
  font-size: clamp(1rem, 4vw, 1.18rem);
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 1px 8px rgba(78, 53, 19, 0.42);
  transition: background 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.replay-button:active {
  transform: translateX(-50%) translateY(1px);
}

.music-toggle {
  position: absolute;
  right: 4.2%;
  top: 3.2%;
  z-index: 20;
  min-width: 4.7rem;
  min-height: 2.25rem;
  padding: 0.42rem 0.7rem;
  border: 1px solid rgba(255, 229, 172, 0.42);
  border-radius: 999px;
  color: #fff7e4;
  background: rgba(45, 25, 13, 0.44);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(7px);
  cursor: pointer;
  font-size: clamp(0.74rem, 3vw, 0.9rem);
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.42);
  transition: background 0.25s ease, border-color 0.25s ease, opacity 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.music-toggle.on {
  border-color: rgba(255, 221, 142, 0.64);
  background: rgba(112, 61, 20, 0.52);
}

.music-toggle:active {
  transform: translateY(1px);
}

@keyframes softPulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

@keyframes hintGlow {
  0%,
  100% {
    opacity: 0.72;
  }
  50% {
    opacity: 1;
  }
}

@keyframes flicker {
  0% {
    transform: translate(-50%, -92%) translateX(-1px) translateY(0) rotate(-3deg) scaleX(0.94) scaleY(1);
    opacity: 0.88;
    filter: blur(0.035rem) brightness(1.02);
  }
  38% {
    transform: translate(-50%, -93%) translateX(1px) translateY(-1px) rotate(2deg) scaleX(1.04) scaleY(1.08);
    opacity: 1;
    filter: blur(0.025rem) brightness(1.08);
  }
  71% {
    transform: translate(-50%, -91%) translateX(-0.5px) translateY(1px) rotate(-1deg) scaleX(0.98) scaleY(0.96);
    opacity: 0.93;
    filter: blur(0.045rem) brightness(0.98);
  }
  100% {
    transform: translate(-50%, -93%) translateX(0.5px) translateY(-1px) rotate(3deg) scaleX(1.02) scaleY(1.04);
    opacity: 0.98;
    filter: blur(0.03rem) brightness(1.05);
  }
}

@keyframes flameBody {
  0% {
    transform: translateX(-50%) rotate(-2deg) scaleX(0.96) scaleY(1);
  }
  100% {
    transform: translateX(-50%) rotate(2deg) scaleX(1.04) scaleY(1.08);
  }
}

@keyframes flameCore {
  0% {
    transform: translateX(-51%) scaleX(0.88) scaleY(0.95);
    opacity: 0.7;
  }
  100% {
    transform: translateX(-49%) scaleX(1.04) scaleY(1.08);
    opacity: 0.95;
  }
}

@keyframes messageIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 360px) {
  .final-message {
    left: 7%;
    right: 7%;
    top: 19.5%;
  }

  .headline,
  .message {
    width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .scene,
  .flame,
  .light-hint {
    transition-duration: 0.01ms !important;
  }
}
