body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  background-color: #000000;
  color: white;
  font-family: "Pacifico", cursive;
  /* Safe-area cho màn notch / home indicator */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#ui {
  display: none;
}

#info {
  font-size: 22px;
  letter-spacing: 2px;
  padding: 10px 24px;
  background-color: rgba(60, 20, 45, 0.5);
  border-radius: 10px;
  display: inline-block;
  text-shadow: 0 0 10px rgba(255, 105, 180, 0.8);
  border: 1px solid rgba(255, 182, 193, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.4s ease;
  min-height: 20px;
}

#start-wrap {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.2s ease;
}

#start-wrap.held {
  transform: translateX(-50%) scale(1.05);
}

#start-label {
  font-family: "Pacifico", cursive;
  color: rgba(255, 182, 193, 0.85);
  font-size: 13px;
  text-shadow: 0 0 8px rgba(255, 105, 180, 0.6);
  letter-spacing: 1px;
}

#start-wrap svg {
  width: 68px;
  height: 68px;
  filter: drop-shadow(0 0 8px rgba(255, 105, 180, 0.45));
}

.ring-pulse {
  fill: rgba(255, 105, 180, 0.1);
  animation: ringPulse 2s ease-in-out infinite;
}

@keyframes ringPulse {
  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 0.15;
  }
}

.ring-track {
  fill: none;
  stroke: rgba(255, 182, 193, 0.2);
  stroke-width: 3;
}

.ring-fill {
  fill: none;
  stroke: #ff69b4;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
  transform-origin: 34px 34px;
  transform: rotate(-90deg);
  transition: stroke-dashoffset 1s linear;
}

/* ── Sphere phase ── */
#transition-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

#sphere-click-hint {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1rem;
  border-radius: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  font-family: "Pacifico", cursive;
  letter-spacing: 1px;
}

#sphere-click-hint.visible {
  opacity: 1;
}

#btn-flying-corner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: none;
  padding: 10px 18px;
  font-size: 20px;
  border: none;
  border-radius: 24px;
  background: rgba(255, 105, 180, 0.9);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(255, 105, 180, 0.4);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

#btn-flying-corner.visible {
  display: block;
}

#btn-flying-corner:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(255, 105, 180, 0.5);
}

#sphere-particles-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 1s;
}

.sp-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(255, 105, 180, 0.6);
  border-radius: 50%;
  animation: spFloat 15s infinite ease-in-out;
}

@keyframes spFloat {
  0%,
  100% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  80% {
    opacity: 1;
  }

  90%,
  100% {
    transform: translateY(-100vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes flashFade {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

/* Cupid letter overlay (kiểu cupid bay) */
#cupid-letter-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 350;
  pointer-events: none;
}

#cupid-letter-overlay.visible {
  display: flex;
  pointer-events: auto;
}

#cupid-letter-overlay .cupid-space {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#cupid-flying-img {
  position: absolute;
  width: clamp(120px, 25vw, 220px);
  height: auto;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 352;
}

#letter-envelope-img {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(140px, 30vw, 260px);
  height: auto;
  cursor: pointer;
  display: none;
  z-index: 355;
  transition: transform 0.2s ease;
}

#letter-envelope-img.visible {
  display: block;
  animation: cupidLetterFadeIn 0.5s ease-out;
}

#letter-envelope-img:hover {
  transform: translate(-50%, -50%) scale(1.06);
}

#cupid-letter-frame {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 720px);
  max-height: 90vh;
  overflow: visible;
  display: none;
  flex-direction: column;
  z-index: 360;
  border-radius: clamp(12px, 2.5vw, 20px);
  box-shadow:
    0 20px 60px rgba(255, 105, 180, 0.35),
    0 0 0 1px rgba(255, 182, 193, 0.3);
  background: linear-gradient(
    135deg,
    #ffd1dc 0%,
    #ffe4e9 25%,
    #fff0f5 50%,
    #ffe4ec 75%,
    #ffc0cb 100%
  );
  pointer-events: auto;
  padding: clamp(20px, 4vw, 32px);
}

#cupid-letter-frame.visible {
  display: flex;
  animation: cupidLetterFadeIn 0.6s ease-out;
}

@media (max-width: 767px) {
  #cupid-letter-frame {
    width: min(88vw, 300px);
  }
}

@keyframes cupidLetterFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

#cupid-letter-frame .letter-content {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  max-height: 72vh;
  font-family: "Pacifico", cursive;
  font-size: clamp(0.95rem, 2vw, 1.2em);
  color: #8b3a62;
  line-height: 1.75;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: pre-wrap;
}

#cupid-letter-frame .letter-content::-webkit-scrollbar {
  display: none;
}

/* Ảnh trong thư — kiểu polaroid lãng mạn, xuất hiện mượt */
#cupid-letter-frame .letter-image-wrap {
  margin-top: 1.25rem;
  text-align: center;
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(12px) scale(0.92);
  transition: none;
}

#cupid-letter-frame .letter-image-wrap.visible {
  animation: letterImageReveal 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes letterImageReveal {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#cupid-letter-frame .letter-inline-image {
  display: block;
  max-width: min(85vw, 70%);
  width: auto;
  height: auto;
  max-height: 38vh;
  margin: 0 auto;
  border-radius: clamp(6px, 1.2vw, 10px);
  box-shadow: 0 4px 20px rgba(139, 58, 98, 0.2);
}

#cupid-letter-frame .letter-image-caption {
  display: block;
  margin-top: 0.5em;
  font-size: 1.1em;
  color: #d84a6f;
  letter-spacing: 0.2em;
  text-align: center;
  text-shadow: 0 0 10px rgba(255, 182, 193, 0.6);
}

#cupid-letter-frame .letter-content .letter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: #8b3a62;
  margin-left: 2px;
  animation: letterCursorBlink 0.8s infinite;
  vertical-align: text-bottom;
}

@keyframes letterCursorBlink {
  0%,
  50% {
    opacity: 1;
  }

  51%,
  100% {
    opacity: 0;
  }
}

/* Bướm trái: đậu ở góc trên-trái của lá thư (ngoài viền) */
#cupid-letter-frame .letter-butterfly-left {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  pointer-events: none;
  transform: translate(-55%, -50%) rotate(-10deg);
}

#cupid-letter-frame .letter-butterfly-left img {
  width: clamp(200px, 32vw, 340px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.2));
}

/* Bướm phải: đậu ở góc trên-phải của lá thư (ngoài viền) */
#cupid-letter-frame .letter-butterfly-right {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  transform: translate(52%, -48%) rotate(10deg);
}

#cupid-letter-frame .letter-butterfly-right img {
  width: clamp(110px, 24vw, 200px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.2));
}

#cupid-letter-frame .letter-bottom-bg {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 42%;
  z-index: 0;
  pointer-events: none;
  border-bottom-left-radius: clamp(12px, 2.5vw, 20px);
  border-bottom-right-radius: clamp(12px, 2.5vw, 20px);
  background: url("https://cdn.festgift.top/projects/womens-day/images/nenthugocduoi.png")
    no-repeat bottom center;
  background-size: 100% auto;
}

#loading {
  position: fixed;
  width: 100%;
  height: 100%;
  background-color: #000000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.6s ease-out;
}

#loading span {
  font-size: 24px;
  letter-spacing: 2px;
  margin-bottom: 15px;
}

#progress-container {
  width: 60%;
  max-width: 300px;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

#progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff69b4, #ffb6c1);
  transition: width 0.3s ease;
  border-radius: 3px;
}

/* ========== PASSCODE SCREEN ========== */
#passcodeScreen {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(70, 20, 50, 0.82), rgba(45, 10, 35, 0.88)),
    linear-gradient(160deg, #2d0f2a 0%, #1a0a18 100%);
  z-index: 2000;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px 30px;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  font-family: -apple-system, sans-serif;
}

#passcodeScreen.visible {
  display: flex;
}

#passcodeScreen.hiding {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease-out;
}

.passcode-bears {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 200px;
  flex-shrink: 0;
}

.passcode-bear {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: clamp(160px, 35vw, 220px);
  width: auto;
  object-fit: contain;
  transition:
    left 0.4s ease,
    right 0.4s ease;
}

.passcode-bear.left {
  left: 5%;
}

.passcode-bear.right {
  right: 5%;
  left: auto;
}

.passcode-bear.left.pos-0 {
  left: 5%;
}

.passcode-bear.right.pos-0 {
  right: 5%;
}

.passcode-bear.left.pos-1 {
  left: 10%;
}

.passcode-bear.right.pos-1 {
  right: 10%;
}

.passcode-bear.left.pos-2 {
  left: 18%;
}

.passcode-bear.right.pos-2 {
  right: 18%;
}

.passcode-bear.left.pos-3 {
  left: 27%;
}

.passcode-bear.right.pos-3 {
  right: 27%;
}

.passcode-bear.left.pos-4 {
  left: 37%;
}

.passcode-bear.right.pos-4 {
  right: 37%;
}

.passcode-couple-img {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: clamp(180px, 38vw, 250px);
  width: auto;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
}

.passcode-bears.show-couple .passcode-bear {
  opacity: 0;
  transition: opacity 0.4s;
}

.passcode-bears.show-couple .passcode-couple-img {
  opacity: 1;
  transition: opacity 0.8s ease-out 0.2s;
}

.passcode-bears.show-couple ~ .passcode-title,
.passcode-bears.show-couple ~ .passcode-subtitle,
.passcode-bears.show-couple ~ .passcode-dots {
  display: none !important;
}

.hearts-passcode {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
}

.passcode-bears.show-couple ~ .hearts-passcode {
  opacity: 1;
}

.hearts-passcode .heart-fly {
  position: absolute;
  bottom: -50px;
  font-size: clamp(20px, 5vw, 28px);
  animation: heartFly 4s linear infinite;
}

@keyframes heartFly {
  0% {
    transform: translateY(0) scale(0.6);
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  80% {
    opacity: 1;
  }

  100% {
    transform: translateY(-80vh) scale(1.2);
    opacity: 0;
  }
}

.hearts-passcode .heart-fly:nth-child(1) {
  left: 5%;
  animation-delay: 0s;
  animation-duration: 3.5s;
}

.hearts-passcode .heart-fly:nth-child(2) {
  left: 15%;
  animation-delay: 0.3s;
  animation-duration: 4s;
}

.hearts-passcode .heart-fly:nth-child(3) {
  left: 28%;
  animation-delay: 0.7s;
  animation-duration: 3.8s;
}

.hearts-passcode .heart-fly:nth-child(4) {
  left: 42%;
  animation-delay: 0.1s;
  animation-duration: 4.2s;
}

.hearts-passcode .heart-fly:nth-child(5) {
  left: 55%;
  animation-delay: 0.5s;
  animation-duration: 3.5s;
}

.hearts-passcode .heart-fly:nth-child(6) {
  left: 68%;
  animation-delay: 0.9s;
  animation-duration: 4.1s;
}

.hearts-passcode .heart-fly:nth-child(7) {
  left: 78%;
  animation-delay: 0.2s;
  animation-duration: 3.7s;
}

.hearts-passcode .heart-fly:nth-child(8) {
  left: 88%;
  animation-delay: 0.6s;
  animation-duration: 4.4s;
}

.hearts-passcode .heart-fly:nth-child(9) {
  left: 22%;
  animation-delay: 1.1s;
  animation-duration: 3.9s;
}

.hearts-passcode .heart-fly:nth-child(10) {
  left: 48%;
  animation-delay: 0.4s;
  animation-duration: 4s;
}

.passcode-title {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  text-align: center;
}

.passcode-subtitle {
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  margin-bottom: 20px;
  text-align: center;
}

.passcode-dots {
  display: flex;
  gap: 14px;
  margin-bottom: 32px;
}

.passcode-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  transition: all 0.2s;
}

.passcode-dot.filled {
  background: #fff;
  border-color: #fff;
}

.passcode-dot.error {
  border-color: #ff3b30;
  background: #ff3b30;
  animation: shake 0.4s;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.passcode-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  max-width: 300px;
  width: 100%;
  margin-top: auto;
}

.passcode-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  justify-self: center;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 26px;
  font-weight: 400;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.passcode-btn:active {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0.94);
}

.passcode-btn.empty {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  cursor: default;
}

.passcode-btn.empty:active {
  transform: none;
}

.passcode-cancel {
  margin-top: 20px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 15px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 20px;
}

.passcode-cancel:hover {
  color: rgba(255, 255, 255, 0.9);
}
