body {
  background-color: #f7e0e4; /* Soft pink background */
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let clicks pass through */
  z-index: 10;
}

.container {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Envelope Styling */
.envelope-wrapper {
  position: relative;
  width: 450px;
  height: 300px;
  background: #d44d5c; /* Darker red/pink base */
  cursor: pointer;
  transition: transform 0.5s ease;
}

.envelope-wrapper:hover {
  transform: translateY(-5px);
}

.envelope {
  position: relative;
  width: 100%;
  height: 100%;
  background: #e05e6d;
}

/* The Flap (Top Triangle) */
.flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 225px solid transparent;
  border-right: 225px solid transparent;
  border-top: 150px solid #c43c4b; /* Darker flap color */
  transform-origin: top;
  transition: transform 0.6s 0.4s ease-in-out, z-index 0.6s;
  z-index: 5;
}

/* The Pocket (Bottom Triangles creating the envelope look) */
.pocket {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 225px solid #e05e6d; /* Main color */
  border-right: 225px solid #e05e6d;
  border-top: 150px solid transparent;
  border-bottom: 150px solid #c94553; /* Shadow/Depth */
  z-index: 4;
}

/* The Letter/Card Inside */
.letter {
  position: absolute;
  bottom: 5px;
  left: 22px;
  width: 406px;
  height: 270px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  z-index: 2; /* Start behind pocket and flap */
  opacity: 0; /* Hide completely when closed */
  transition: transform 0.8s ease-in-out, opacity 0.8s ease-in-out,
    z-index 0s 1s;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  box-sizing: border-box;
  text-align: center;
}

.text-content {
  font-family: "Dancing Script", cursive;
  font-optical-sizing: auto;
  font-weight: 400;
  font-style: normal;
  font-size: 1.7rem;
  color: #555;
  opacity: 0;
  transition: opacity 0.5s 1.5s;
}

/* Animation for letter sliding out and back */
@keyframes slideOutAndBack {
  0% {
    transform: translateY(0);
    opacity: 0;
  }
  40% {
    transform: translateY(-280px);
    opacity: 1;
  }
  100% {
    transform: translateY(-15px);
    opacity: 1;
  }
}

/* ... existing code ... */

/* Animation States: OPEN */
.envelope-wrapper.open .flap {
  transform: rotateX(180deg);
  z-index: 1; /* Moves behind the letter */
  border-top-color: #be3746;
}

.envelope-wrapper.open .letter {
  animation: slideOutAndBack 2.2s ease-in-out forwards;
  z-index: 10; /* Eventually move to the very front */
}

.envelope-wrapper.open .text-content {
  opacity: 1;
}

.envelope-wrapper.open .heart-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
}

.heart-seal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  cursor: pointer;
  user-select: none;
  z-index: 6;
  transition: opacity 0.4s, transform 0.4s;
}

.envelope-wrapper.open {
  cursor: default;
}

/* Controls */
.controls {
  display: none; /* Hide navigation buttons */
}

.nav-btn {
  background: #c43c4b;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 1rem;
  margin: 0 10px;
  transition: background 0.3s;
}

.nav-btn:hover {
  background: #a02d3a;
}

.instruction {
  margin-top: 20px;
  color: #888;
  font-size: 0.9rem;
  opacity: 1;
  transition: opacity 0.5s;
}

.envelope-wrapper.open ~ .instruction {
  opacity: 0;
}

/* Desktop responsiveness */
@media (min-width: 768px) {
  .envelope-wrapper {
    width: 600px;
    height: 400px;
  }

  .flap {
    border-left: 300px solid transparent;
    border-right: 300px solid transparent;
    border-top: 200px solid #c43c4b;
  }

  .pocket {
    border-left: 300px solid #e05e6d;
    border-right: 300px solid #e05e6d;
    border-top: 200px solid transparent;
    border-bottom: 200px solid #c94553;
  }

  .letter {
    width: 540px;
    height: 360px;
    left: 30px;
    bottom: 10px;
    padding: 40px;
  }

  .text-content {
    font-size: 2.3rem;
  }

  @keyframes slideOutAndBack {
    0% {
      transform: translateY(0);
      opacity: 0;
    }
    40% {
      transform: translateY(-370px);
      opacity: 1;
    }
    100% {
      transform: translateY(-20px);
      opacity: 1;
    }
  }
}
