:root {
  --pink-1: #ffdde1;
  --pink-2: #ee9ca7;
  --pink-3: #fcbad3;
  --pink-4: #ff6f91;
  --ink: #3d2c3e;
  --gold: #f6d365;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(120deg, var(--pink-1), var(--pink-2));
  animation: backgroundFlow 12s ease-in-out infinite alternate;
  color: var(--ink);
}

@keyframes backgroundFlow {
  0% {
    background: linear-gradient(120deg, var(--pink-1), var(--pink-2));
  }
  50% {
    background: linear-gradient(140deg, var(--pink-3), var(--pink-2));
  }
  100% {
    background: linear-gradient(160deg, #ffe0f0, var(--pink-4));
  }
}

.loading-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0));
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: var(--ink);
  transition: opacity 0.6s ease;
}

.loading-wrapper {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.loading-text {
  font-size: 1.2rem;
  letter-spacing: 0.2rem;
  animation: gentleGlow 2.8s ease-in-out infinite;
}

.loading-sub {
  font-size: 0.9rem;
  opacity: 0.8;
  animation: fadePulse 2s ease-in-out infinite;
}

.loading-petal {
  width: 24px;
  height: 24px;
  border-radius: 60% 40% 65% 35%;
  background: rgba(255, 182, 193, 0.8);
  position: relative;
  animation: petalSwing 1.6s ease-in-out infinite;
}

.loading-petal::before,
.loading-petal::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: inherit;
  opacity: 0.7;
}

.loading-petal::before {
  transform: rotate(60deg);
}

.loading-petal::after {
  transform: rotate(-60deg);
}

@keyframes gentleGlow {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.6));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(255, 255, 255, 1));
  }
}

@keyframes fadePulse {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

@keyframes petalSwing {
  0%, 100% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(15deg) scale(1.1);
  }
}

.scene {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 2rem;
  max-width: 520px;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.scene.visible {
  opacity: 1;
  transform: translateY(0);
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.secret-label {
  position: absolute;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%);
  letter-spacing: 0.4rem;
  font-size: 1.4rem;
  font-weight: 600;
  color: rgba(61, 44, 62, 0.85);
  opacity: 0;
}

.secret-label.show {
  animation: fadeIn 1.6s forwards;
}

.secret-label.fade-out {
  animation: fadeOut 1.2s forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
}

.music-toggle {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 25px rgba(255, 111, 145, 0.25);
  transition: transform 0.4s ease, box-shadow 0.4s ease, background 0.4s ease;
}

.music-toggle.playing {
  animation: spin 4s linear infinite;
  background: rgba(255, 255, 255, 0.92);
}

.music-toggle.hidden {
  display: none;
}

.music-toggle:active {
  transform: scale(0.9);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.envelope {
  width: min(90vw, 420px);
  height: min(70vh, 360px);
  position: relative;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.82));
  border-radius: 20px;
  box-shadow: 0 25px 60px rgba(255, 111, 145, 0.35);
  overflow: hidden;
  perspective: 1000px;
}

.envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(246, 211, 101, 0.4);
  pointer-events: none;
}

.envelope-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 55%;
  background: linear-gradient(180deg, rgba(252, 186, 211, 0.45), rgba(255, 221, 225, 0.9));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transform: rotateX(0deg);
  transition: transform 1.2s cubic-bezier(0.76, 0, 0.24, 1);
  z-index: 2;
}

.envelope.open .envelope-top {
  transform: rotateX(-180deg);
}

.envelope-bottom {
  position: absolute;
  inset: 0;
  padding: 5.5rem 2.6rem 3.4rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1;
}

.message-area {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.secret-input {
  width: 100%;
  height: 6rem;
  border: none;
  outline: none;
  resize: none;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 16px;
  padding: 1.2rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(246, 211, 101, 0.35);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.secret-input.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.failure-message {
  width: 100%;
  padding: 1.4rem 1rem;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(246, 211, 101, 0.25);
  text-align: center;
  font-size: 1.05rem;
  letter-spacing: 0.2rem;
  color: rgba(61, 44, 62, 0.9);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.failure-message.hidden {
  opacity: 0;
  transform: translateY(10px);
}

.secret-input::placeholder {
  color: rgba(61, 44, 62, 0.45);
}

.secret-input.error {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% {
    transform: translateY(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

.letter {
  width: 100%;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: inset 0 0 0 1px rgba(246, 211, 101, 0.25);
  font-size: 1rem;
  line-height: 1.8;
  color: rgba(61, 44, 62, 0.95);
  min-height: 10rem;
  letter-spacing: 0.08rem;
}

.letter .line {
  min-height: 1.8rem;
}

.wax-seal {
  position: absolute;
  bottom: 1.6rem;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.8), rgba(255, 111, 145, 0.9));
  box-shadow: 0 18px 30px rgba(255, 111, 145, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.5s ease, box-shadow 0.5s ease, opacity 0.8s ease;
  overflow: hidden;
}

.wax-seal .wax-text {
  font-size: 1.2rem;
  letter-spacing: 0.3rem;
  color: white;
  text-shadow: 0 2px 8px rgba(157, 19, 59, 0.4);
}

.wax-seal .wax-glow {
  position: absolute;
  inset: -30%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.45), rgba(255, 111, 145, 0));
  opacity: 0;
  transition: opacity 0.8s ease;
}

.wax-seal:hover {
  transform: translateX(-50%) scale(1.05);
  box-shadow: 0 22px 40px rgba(255, 111, 145, 0.5);
}

.wax-seal:hover .wax-glow {
  opacity: 1;
}

.wax-seal.disabled {
  pointer-events: none;
}

.wax-seal.fade-out {
  opacity: 0;
  transform: translateX(-50%) scale(0.6);
}

.sakura-layer,
.fireworks-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.sakura-petal {
  position: absolute;
  width: 18px;
  height: 24px;
  background: rgba(255, 182, 193, 0.85);
  border-radius: 60% 40% 70% 30%;
  box-shadow: inset -4px 0 8px rgba(255, 255, 255, 0.5);
  animation: fall linear forwards;
}

.sakura-petal::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 240, 245, 0.8);
  transform: rotate(30deg);
  opacity: 0.5;
}

@keyframes fall {
  0% {
    transform: translate3d(0, -120vh, 0) rotateZ(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--x drift, 0px), 120vh, 0) rotateZ(360deg);
    opacity: 0;
  }
}

.firework {
  position: absolute;
  width: 6px;
  height: 6px;
  background: radial-gradient(circle, rgba(255, 255, 255, 1), rgba(255, 111, 145, 0.6));
  border-radius: 50%;
  pointer-events: none;
  animation: explode 800ms ease-out forwards;
}

.firework::before,
.firework::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 -12px 0 rgba(255, 255, 255, 0.7),
    0 12px 0 rgba(255, 111, 145, 0.8),
    12px 0 0 rgba(255, 182, 193, 0.7),
    -12px 0 0 rgba(246, 211, 101, 0.7);
  opacity: 0.8;
  animation: spark 800ms ease-out forwards;
}

@keyframes explode {
  from {
    transform: scale(0.4);
    opacity: 0.6;
  }
  to {
    transform: scale(1.4);
    opacity: 0;
  }
}

@keyframes spark {
  from {
    transform: rotate(0deg) scale(0.5);
    opacity: 1;
  }
  to {
    transform: rotate(120deg) scale(1.6);
    opacity: 0;
  }
}

@media (max-width: 480px) {
  .secret-label {
    font-size: 1.1rem;
  }

  .envelope {
    width: 92vw;
    height: 68vh;
  }

  .wax-seal {
    width: 90px;
    height: 90px;
  }
}
