* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  overflow-x: hidden;
  background-color: #f0e6f6; /* Soft lavender for a romantic, dreamy feel */
}

.envlope-wrapper {
  height: 380px;
}

#envelope {
  position: relative;
  width: 280px;
  height: 180px;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  margin-left: auto;
  margin-right: auto;
  top: 150px;
  background-color: #d9534f; /* Warm romantic red */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.front {
  position: absolute;
  width: 0;
  height: 0;
  z-index: 4;
}

.flap {
  border-left: 140px solid transparent;
  border-right: 140px solid transparent;
  border-bottom: 82px solid transparent;
  /* a little smaller */
  border-top: 98px solid #d9534f; /* Same romantic red */
  /* a little larger */
  transform-origin: top;
  pointer-events: none;
}

.pocket {
  border-left: 140px solid #f5a3a2; /* Soft pinkish red for the pocket */
  border-right: 140px solid #f5a3a2;
  border-bottom: 90px solid #ff6f61; /* Lighter romantic red */
  border-top: 90px solid transparent;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
}

.letter {
  position: relative;
  width: 90%;
  margin-left: auto;
  margin-right: auto;
  transform-style: preserve-3d;
  height: 180%;
  top: -85%;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  font-family: "Dancing Script", cursive;
  z-index: 1;
}

/* Partie basse de la feuille (fixe) */
.paper-half-bottom {
  position: absolute;
  width: 100%;
  height: 50%;
  bottom: 0;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border-radius: 0 0 3px 3px;
  overflow: hidden;
  z-index: 1;
}

/* Partie haute de la feuille (qui se plie) */
.paper-half-top {
  position: absolute;
  width: 100%;
  height: 50%;
  top: 0;
  transform-origin: bottom center;
  transform: rotateX(0deg);
  transition:
    transform 1.3s ease,
    z-index 1.6s;
  transition-delay: 3s;
  transform-style: preserve-3d;
  z-index: 2;
}

/* Face avant de la partie haute */
.paper-half-top-front {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: 0 -5px 20px rgba(70, 69, 69, 0.1);
  border-radius: 3px 3px 0 0;
  backface-visibility: hidden;
  overflow: hidden;
}

/* Face arrière de la partie haute (dos de la feuille) */
.paper-half-top-back {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  border-radius: 0 0 3px 3px;
  backface-visibility: hidden;
  transform: rotateX(180deg);
}

/* Ligne de pliage */
.fold-line {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* État plié */
.letter.folded .paper-half-top {
  transform: rotateX(-180deg);
}

.letter:after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.words {
  position: absolute;
  left: 10%;
  width: 80%;
  height: 14%;
  background-color: #ffe6e6; /* Light romantic tone */
}

.words.line1 {
  top: 20%;
  width: 20%;
  height: 11%;
  font-size: 1rem;
}

.words.w1.line1 {
  top: 5%;
  width: 80%;
  text-align: center;
  font-size: 1.1rem;
}

.words.line2 {
  top: 40%;
  text-align: center;
  font-size: 1.1rem;
}

.words.w2.line2 {
  top: 25%;
}

.words.line3 {
  top: 60%;
  font-size: 1.1rem;
  text-align: center;
}

.words.w3.line3 {
  top: 45%;
}

.words.line4 {
  top: 80%;
  font-size: 1.1rem;
  text-align: center;
}

.words.w4.line4 {
  top: 75%;
}

.open .flap {
  transform: rotateX(180deg);
  transition:
    transform 0.4s ease,
    z-index 0.6s;
  z-index: 1;
}

.close .flap {
  transform: rotateX(0deg);
  transition:
    transform 0.9s 1s ease,
    z-index 1.8s;
  transition-delay: 4s;
  z-index: 5;
}

.open .letter {
  animation: slideToOpen 3s ease forwards;
  animation-delay: 0.6s;
}

.close1 .letter {
  animation: slideToClose 3s ease forwards;
}

.hearts {
  position: absolute;
  top: 90px;
  left: 0;
  right: 0;
}

.heart {
  position: absolute;
  bottom: 0;
  right: 10%;
  pointer-events: none;
}

.heart:before,
.heart:after {
  position: absolute;
  content: "";
  left: 50px;
  top: 0;
  width: 50px;
  height: 80px;
  background: #e60073; /* Deep romantic pink */
  border-radius: 50px 50px 0 0;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
  pointer-events: none;
}

.heart:after {
  left: 0;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

.close .heart {
  opacity: 0;
  -webkit-animation: none;
  animation: none;
}

.a1 {
  left: 20%;
  transform: scale(0.6);
  opacity: 1;
  -webkit-animation:
    slideUp 4s linear 1,
    sideSway 2s ease-in-out 4 alternate;
  -moz-animation:
    slideUp 4s linear 1,
    sideSway 2s ease-in-out 4 alternate;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-delay: 0.7s;
  animation-delay: 0.7s;
}

.a2 {
  left: 55%;
  transform: scale(1);
  opacity: 1;
  -webkit-animation:
    slideUp 5s linear 1,
    sideSway 4s ease-in-out 2 alternate;
  -moz-animation:
    slideUp 5s linear 1,
    sideSway 4s ease-in-out 2 alternate;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-delay: 0.7s;
  animation-delay: 0.7s;
}

.a3 {
  left: 10%;
  transform: scale(0.8);
  opacity: 1;
  -webkit-animation:
    slideUp 7s linear 1,
    sideSway 2s ease-in-out 6 alternate;
  -moz-animation:
    slideUp 7s linear 1,
    sideSway 2s ease-in-out 6 alternate;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-delay: 0.7s;
  animation-delay: 0.7s;
}

.absolutely {
  position: absolute;
  bottom: 15%;
  width: 100%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: "Dancing Script", cursive;
  color: #e60073; /* Deep romantic pink */
  font-size: 1.5rem;
}

.absolutely p {
  width: 80%;
  margin: 0 auto;
  text-align: center;
}

.absolute-image {
  position: absolute;
  top: 3%;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.absolute-image .image-screen {
  width: 180px;
  height: auto;
}

@-webkit-keyframes slideToOpen {
  0% {
    transform: translateY(0);
    z-index: 2;
  }
  40% {
    transform: translateY(-167px);
    z-index: 2;
  }
  50% {
    transform: translateY(-167px);
    z-index: 4;
  }

  100% {
    transform: translateY(-30px);
    z-index: 5;
  }
}

@keyframes slideToOpen {
  0% {
    transform: translateY(0);
    z-index: 2;
  }
  40% {
    transform: translateY(-167px);
    z-index: 2;
  }
  50% {
    transform: translateY(-167px);
    z-index: 4;
  }

  100% {
    transform: translateY(-30px);
    z-index: 5;
  }
}

@-webkit-keyframes slideToClose {
  0% {
    transform: translateY(0);
    z-index: 4;
  }
  40% {
    transform: translateY(-167px);
    z-index: 4;
  }
  50% {
    transform: translateY(-167px);
    z-index: 2;
  }

  100% {
    transform: translateY(0);
    z-index: 2;
  }
}

@keyframes slideToClose {
  0% {
    transform: translateY(0);
    z-index: 4;
  }
  40% {
    transform: translateY(-167px);
    z-index: 4;
  }
  50% {
    transform: translateY(-167px);
    z-index: 2;
  }

  100% {
    transform: translateY(0);
    z-index: 2;
  }
}

@-webkit-keyframes slideUp {
  0% {
    top: 0;
  }
  100% {
    top: -700px;
  }
}

@keyframes slideUp {
  0% {
    top: 0;
    z-index: 3;
  }
  50% {
    top: -350px;
    z-index: 5;
  }
  100% {
    top: -700px;
    z-index: 5;
  }
}

@-webkit-keyframes sideSway {
  0% {
    margin-left: 0px;
  }
  100% {
    margin-left: 50px;
  }
}

@keyframes sideSway {
  0% {
    margin-left: 0px;
  }
  100% {
    margin-left: 50px;
  }
}
