:root {
  --bg-1: #1f0010;
  --bg-2: #37081b;
  --bg-3: #10000a;
  --red-1: #ff3d63;
  --red-2: #ff173f;
  --red-3: #ff7b94;
  --text: #ffeaf0;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Unbounded", sans-serif;
  color: var(--text);
  background:
    radial-gradient(80vw 80vh at 20% 20%, #6d0f33 0%, transparent 45%),
    radial-gradient(80vw 80vh at 80% 75%, #4f0d2f 0%, transparent 45%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 50%, var(--bg-3));
  overflow: hidden;
}

.scene {
  position: relative;
  width: 100vw;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  place-items: center;
  padding: clamp(14px, 2vw, 24px);
  isolation: isolate;
}

.glow {
  position: absolute;
  width: min(48vw, 500px);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.35;
  z-index: -1;
}

.glow--left {
  left: -12vw;
  top: -20vh;
  background: radial-gradient(circle, #ff4b74 0%, transparent 70%);
}

.glow--right {
  right: -12vw;
  bottom: -20vh;
  background: radial-gradient(circle, #ff1b45 0%, transparent 70%);
}

.title-wrap {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 6px;
}

.subtitle {
  margin: 0;
  font-family: "Poiret One", sans-serif;
  font-size: clamp(1rem, 2.1vw, 1.35rem);
  opacity: 0.88;
}

h1 {
  margin: 6px 0 0;
  font-size: clamp(1.8rem, 5.2vw, 3.6rem);
  font-weight: 700;
  text-shadow: 0 0 20px color-mix(in oklab, var(--red-3) 60%, transparent);
}

.heart-stage {
  position: relative;
  width: min(92vw, 980px);
  height: min(72vh, 700px);
  display: grid;
  place-items: center;
  perspective: 1200px;
  touch-action: manipulation;
}

.heart-guide {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--guide-size, min(44vw, 340px));
  transform:
    translate(-50%, -50%)
    translateY(var(--guide-offset-y, 0px))
    rotateX(-14deg)
    rotateY(-12deg);
  transform-origin: center;
  opacity: 0.4;
  filter:
    drop-shadow(0 0 10px rgba(255, 105, 164, 0.24))
    drop-shadow(0 0 22px rgba(255, 74, 146, 0.14));
  animation: auto-spin 9.4s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

.heart-cloud {
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform: rotateX(-14deg) rotateY(-12deg);
  animation: auto-spin 9.4s ease-in-out infinite;
  will-change: transform;
  z-index: 3;
}

.heart-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.heart-center.hidden {
  opacity: 0;
  transform: scale(0.88);
}

.heart-center::before {
  content: "";
  grid-area: 1 / 1;
  width: min(25vw, 176px);
  aspect-ratio: 1 / 0.68;
  border-radius: 999px;
  background: radial-gradient(
    ellipse at center,
    rgba(37, 0, 20, 0.48) 0%,
    rgba(56, 0, 30, 0.24) 52%,
    rgba(56, 0, 30, 0.04) 100%
  );
  filter: blur(4px);
  box-shadow:
    0 0 12px rgba(255, 74, 138, 0.16),
    0 0 24px rgba(255, 74, 138, 0.1);
}

.heart-action {
  grid-area: 1 / 1;
  pointer-events: auto;
  position: relative;
  z-index: 2;
  border: 1px solid rgba(255, 233, 240, 0.95);
  border-radius: 999px;
  padding: 9px 22px;
  font-family: "Unbounded", sans-serif;
  font-size: clamp(0.66rem, 1.35vw, 0.84rem);
  font-weight: 700;
  letter-spacing: 0.09em;
  color: #fff8fb;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.55);
  background: linear-gradient(135deg, rgba(255, 96, 134, 0.92), rgba(255, 56, 115, 0.9));
  box-shadow:
    0 0 16px rgba(255, 84, 141, 0.95),
    0 0 34px rgba(255, 68, 128, 0.7),
    inset 0 0 16px rgba(255, 221, 230, 0.45);
  animation: heart-action-glow 2.2s ease-in-out infinite;
  cursor: pointer;
}

.heart-action:active {
  transform: translateY(1px);
}

.heart-action:disabled {
  cursor: default;
  opacity: 0.86;
}

.surprise-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 9;
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.7s ease;
}

.surprise-overlay.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.envelope-wrap {
  position: relative;
  width: min(62vw, 360px);
  display: grid;
  place-items: center;
  transform-origin: center bottom;
  animation: envelope-shake 1.05s ease-in-out infinite;
  filter: drop-shadow(0 14px 30px rgba(72, 7, 32, 0.42));
  transition: transform 0.5s ease;
  will-change: transform, opacity, filter;
  z-index: 5;
}

.envelope-wrap.opened {
  animation: none;
  transform: translateY(-4px);
}

.envelope-wrap.dropping {
  animation: envelope-drop 0.72s cubic-bezier(0.2, 0.75, 0.28, 1) forwards;
}

.envelope-wrap.opened .envelope {
  cursor: default;
}

.envelope {
  position: relative;
  width: 100%;
  aspect-ratio: 1.56 / 1;
  overflow: visible;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.envelope-shadow {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -11%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 0, 10, 0.44), transparent 72%);
  filter: blur(7px);
  z-index: 0;
}

.envelope-shell {
  position: absolute;
  inset: 0 1.5%;
  z-index: 2;
  border-radius: 22px;
  overflow: hidden;
}

.env-back,
.env-front,
.env-side,
.env-flap,
.env-seam {
  position: absolute;
  inset: 0;
  border-radius: 22px;
}

.env-back {
  z-index: 1;
  background: linear-gradient(165deg, #ffe7f2 0%, #ffd6e8 56%, #ffc4dd 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -12px 18px rgba(183, 29, 90, 0.13);
}

.env-front {
  z-index: 3;
  inset: auto 0 0 0;
  height: 62%;
  border-radius: 0 0 22px 22px;
  background: linear-gradient(160deg, #ff97c1 0%, #ff6daa 62%, #ff589a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 233, 244, 0.5),
    0 -2px 6px rgba(116, 14, 55, 0.1);
}

.env-side {
  z-index: 4;
  bottom: 0;
  height: 62%;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.04));
}

.env-side--left {
  clip-path: polygon(0 0, 100% 58%, 0 100%);
}

.env-side--right {
  clip-path: polygon(0 58%, 100% 0, 100% 100%);
}

.env-seam {
  z-index: 5;
  inset: auto 12% 38% 12%;
  height: 1px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
}

.env-flap {
  z-index: 6;
  inset: 0 0 auto 0;
  height: 56%;
  border-radius: 22px 22px 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 84%);
  background: linear-gradient(150deg, #ff8ebb 0%, #ff71ab 60%, #ff629f 100%);
  box-shadow: inset 0 -12px 18px rgba(186, 27, 92, 0.15);
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 0.62s cubic-bezier(0.2, 0.82, 0.24, 1);
  backface-visibility: hidden;
}

.envelope-wrap.opened .env-flap {
  transform: rotateX(-170deg) translateY(-1px);
}

.envelope::after {
  content: "";
  position: absolute;
  left: 24%;
  right: 24%;
  top: 10%;
  height: 8%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0));
  pointer-events: none;
  z-index: 7;
}

.note-sheet {
  position: absolute;
  width: min(58vw, 340px);
  min-height: min(66vh, 430px);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 246, 251, 0.94)),
    repeating-linear-gradient(
      to bottom,
      rgba(243, 178, 208, 0.2) 0,
      rgba(243, 178, 208, 0.2) 2px,
      transparent 2px,
      transparent 34px
    );
  box-shadow:
    0 24px 48px rgba(57, 6, 27, 0.42),
    inset 0 0 0 1px rgba(230, 154, 190, 0.34);
  padding: clamp(18px, 4.2vw, 30px);
  display: grid;
  align-content: start;
  justify-items: center;
  opacity: 0;
  transform-origin: top center;
  transform: translateY(16px) rotateX(-84deg) scaleY(0.14) scaleX(0.95);
  transition: none;
  pointer-events: none;
  z-index: 1;
}

.note-sheet::before {
  content: "";
  width: 72px;
  height: 4px;
  border-radius: 999px;
  background: rgba(223, 92, 150, 0.32);
  margin-bottom: 18px;
}

.note-body {
  width: 100%;
  min-height: 220px;
  margin: 0;
  text-align: center;
  font-size: clamp(0.9rem, 1.85vw, 1.1rem);
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: #922051;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.note-body:empty::before {
  content: "";
  display: block;
  width: 100%;
  height: 190px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(217, 98, 158, 0.22) 0,
    rgba(217, 98, 158, 0.22) 2px,
    transparent 2px,
    transparent 34px
  );
  border-radius: 8px;
}

.surprise-overlay.show-note .note-sheet {
  animation: note-unfold 0.9s cubic-bezier(0.2, 0.9, 0.24, 1) forwards;
}

@keyframes heart-action-glow {
  0% {
    box-shadow:
      0 0 16px rgba(255, 84, 141, 0.95),
      0 0 34px rgba(255, 68, 128, 0.7),
      inset 0 0 16px rgba(255, 221, 230, 0.45);
  }
  50% {
    box-shadow:
      0 0 20px rgba(255, 120, 162, 1),
      0 0 46px rgba(255, 86, 142, 0.84),
      inset 0 0 18px rgba(255, 230, 238, 0.6);
  }
  100% {
    box-shadow:
      0 0 16px rgba(255, 84, 141, 0.95),
      0 0 34px rgba(255, 68, 128, 0.7),
      inset 0 0 16px rgba(255, 221, 230, 0.45);
  }
}

@keyframes envelope-shake {
  0% {
    transform: rotate(-1.2deg) translateX(-0.5px);
  }
  20% {
    transform: rotate(1.3deg) translateX(0.8px);
  }
  40% {
    transform: rotate(-0.8deg) translateX(-0.6px);
  }
  60% {
    transform: rotate(1deg) translateX(0.6px);
  }
  100% {
    transform: rotate(-1.2deg) translateX(-0.5px);
  }
}

@keyframes envelope-drop {
  0% {
    transform: translateY(-4px) rotate(0deg) scale(1);
    opacity: 1;
    filter: drop-shadow(0 14px 30px rgba(72, 7, 32, 0.42)) blur(0);
  }
  35% {
    transform: translateY(34px) rotate(2deg) scale(0.98);
    opacity: 1;
  }
  100% {
    transform: translateY(250px) rotate(14deg) scale(0.9);
    opacity: 0;
    filter: drop-shadow(0 4px 14px rgba(40, 3, 18, 0.25)) blur(2px);
  }
}

@keyframes note-unfold {
  0% {
    opacity: 0;
    transform: translateY(18px) rotateX(-84deg) scaleY(0.14) scaleX(0.95);
  }
  42% {
    opacity: 1;
    transform: translateY(-8px) rotateX(-36deg) scaleY(0.56) scaleX(0.98);
  }
  72% {
    transform: translateY(-22px) rotateX(-9deg) scaleY(0.94) scaleX(1);
  }
  100% {
    opacity: 1;
    transform: translateY(-30px) rotateX(0deg) scaleY(1) scaleX(1);
  }
}

.word {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) translateZ(var(--z, 0px)) rotateY(var(--ry, 0deg));
  transform-origin: center;
  backface-visibility: hidden;
  white-space: nowrap;
  font-weight: 600;
  font-size: clamp(8px, 0.95vw, 13px);
  line-height: 1;
  letter-spacing: 0.01em;
  text-align: center;
  user-select: none;
  pointer-events: none;
  color: var(--red-1);
  -webkit-text-stroke: 0.18px rgba(255, 255, 255, 0.18);
  filter: drop-shadow(0 0 2px rgba(255, 120, 170, 0.2));
  text-shadow:
    0 0 1px color-mix(in srgb, var(--red-1) 42%, white),
    0 0 3px color-mix(in srgb, var(--red-2) 42%, transparent);
  opacity: 0.9;
}

@keyframes auto-spin {
  0% {
    transform: rotateX(-14deg) rotateY(-13deg);
  }
  50% {
    transform: rotateX(-12deg) rotateY(-3deg);
  }
  100% {
    transform: rotateX(-14deg) rotateY(-13deg);
  }
}

@media (max-width: 780px) {
  .scene {
    grid-template-rows: 1fr;
    padding-top: max(14px, env(safe-area-inset-top));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .title-wrap {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0;
    width: 100%;
    z-index: 12;
    pointer-events: none;
  }

  .heart-stage {
    width: min(96vw, 520px);
    height: 100vh;
    max-height: 100vh;
  }

  .heart-guide {
    opacity: 0.5;
    transform:
      translate(-50%, -50%)
      translateY(var(--guide-offset-y, 0px))
      rotateX(-13deg)
      rotateY(-10deg);
    animation: auto-spin-mobile 8.8s ease-in-out infinite;
    filter:
      drop-shadow(0 0 8px rgba(255, 106, 173, 0.26))
      drop-shadow(0 0 18px rgba(255, 82, 154, 0.14));
  }

  .heart-cloud {
    transform: rotateX(-13deg) rotateY(-10deg) scale(1.08);
    animation: auto-spin-mobile 8.8s ease-in-out infinite;
  }

  .heart-center::before {
    width: min(35vw, 132px);
  }

  .heart-action {
    padding: 8px 14px;
    font-size: clamp(0.56rem, 2.2vw, 0.72rem);
  }

  .word {
    font-size: clamp(7px, 2.2vw, 10px);
    -webkit-text-stroke: 0;
    filter: none;
    text-shadow: 0 0 2px rgba(255, 120, 170, 0.42);
  }

  .envelope-wrap {
    width: min(88vw, 340px);
  }

  .note-sheet {
    width: min(90vw, 360px);
    min-height: min(66vh, 420px);
    padding: 16px 16px 20px;
  }

  .note-body {
    min-height: 170px;
    font-size: clamp(0.9rem, 4vw, 1.02rem);
  }
}

@media (hover: hover) and (pointer: fine) {
  .heart-stage {
    touch-action: none;
  }
}

@keyframes auto-spin-mobile {
  0% {
    transform: rotateX(-13deg) rotateY(-10deg) scale(0.94);
  }
  50% {
    transform: rotateX(-11deg) rotateY(-2deg) scale(0.94);
  }
  100% {
    transform: rotateX(-13deg) rotateY(-10deg) scale(0.94);
  }
}
