/* Postcard submission animation */

/* Container for the animation overlay */
.wppostcards-animation-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;

  /* anchor point */
  --origin-x: 50vw;
  --origin-y: 50vh;
}

/* The animated postcard element */
.wppostcards-animated-postcard {
  position: absolute;
  left: calc(var(--origin-x) - 200px);
  top: var(--origin-y);
  pointer-events: none;
  perspective: 1000px;
  width: 400px;
  max-width: 100%;
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 100001;
}

.wppostcards-animated-postcard-image {
  width: 100%;
  height: auto;
  display: block;
}

.wppostcards-animated-postcard-content {
  padding: 15px;
  background: white;
}

.wppostcards-animated-postcard-message {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 8px;
  max-height: 80px;
  overflow: hidden;
}

.wppostcards-animated-postcard-signature {
  font-style: italic;
  color: #666;
  font-size: 13px;
  text-align: right;
}

/* Envelope element */
.wppostcards-animated-envelope {
  position: absolute;
  left: calc(var(--origin-x) - 200px);
  top: calc(var(--origin-y) + 200px);  
  width: 440px;
  max-width: 85vw;
  height: 300px;
  z-index: 100000;
  pointer-events: none;
  perspective: 1000px;
}

.wppostcards-envelope-body {
  position: absolute;
  inset: 0; 
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #f5f5dc 0%, #e8dcc0 100%);
  border: 2px solid #d4c5a0;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.wppostcards-envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(180deg, #e8dcc0 0%, #d4c5a0 100%);
  border-bottom: 2px solid #d4c5a0;
  transform-origin: top center;
  transform-style: preserve-3d;
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  z-index: 1;
  transform: rotateX(180deg);
}

.wppostcards-envelope-back-flap {
  position: absolute;
  top: 0;
  left: 0;
  /* transform: translate(70%, 0%);   */
  width: 100%;
  height: 50%;
  background: #e8dcc0;
  clip-path: polygon(0 0, 50% 100%, 100% 0);
}

/* Animation stages */
@keyframes wppostcards-postcard-fly-out {
  0% {
    opacity: 1;
    transform: translate(0%, 0%) scale(1) rotate(0deg);
  }

  /* Right → Down */
  12.5% {
    transform: translate(40%, 40%) scale(0.95) rotate(90deg);
  }

  /* Bottom */
  25% {
    transform: translate(0%, 80%) scale(0.9) rotate(180deg);
  }

  /* Left → Down */
  37.5% {
    transform: translate(-40%, 40%) scale(0.85) rotate(270deg);
  }

  /* Left */
  50% {
    transform: translate(-80%, 0%) scale(0.8) rotate(360deg);
  }

  /* Left → Up */
  62.5% {
    transform: translate(-40%, -40%) scale(0.75) rotate(450deg);
  }

  /* Top */
  75% {
    transform: translate(0%, -80%) scale(0.7) rotate(540deg) translateZ(30px); 
  }

  /* Right → Up */
  87.5% {
    transform: translate(40%, -40%) scale(0.65) rotate(630deg);
  }

  /* Back to center, aligned with envelope */
  100% {
    transform: translate(0%, 0%) scale(0.6) rotate(720deg);
    opacity: 1;
  }
}


/* Stage 2: Envelope appears */
@keyframes wppostcards-envelope-appear {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.8) rotate(0deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
}

/* Stage 3: Postcard enters envelope */
@keyframes wppostcards-postcard-enter-envelope {
  0% {
    transform: translate(0%, 0%) scale(0.6);
    opacity: 1;
  }
  50% {
    transform: translate(0%, -30%) scale(0.6);
    opacity: 1;
  }
  100% {
    transform: translate(0%, 40%) scale(0.6);
    opacity: 0;
  }
}

/* Stage 4: Envelope flap closes */
@keyframes wppostcards-envelope-close {
  0% {
    transform: rotateX(180deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

/* Stage 5: Envelope flies to bottom-right corner */
@keyframes wppostcards-envelope-fly-to-corner {
  to {
    transform: translate(calc(50vw - 120px), calc(50vh - 120px)) scale(0.5) rotate(8deg);
  }
}

/* Stage 6: Envelope transforms to notification */
@keyframes wppostcards-envelope-to-notification {
  0% {
    transform: translate(calc(100vw - 250px), calc(100vh - 200px)) scale(0.5) rotate(8deg);
    opacity: 1;
  }
  100% {
    transform: translate(calc(100vw - 250px), calc(100vh - 200px)) scale(0.3) rotate(0deg);
    opacity: 0;
  }
}

/* Animation class states */
.wppostcards-animated-postcard.stage-fly-out {
  animation: wppostcards-postcard-fly-out 0.8s cubic-bezier(0.45, 0.05, 0.55, 0.95) forwards;
}

.wppostcards-animated-envelope.stage-appear {
  animation: wppostcards-envelope-appear 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.wppostcards-animated-postcard.stage-enter-envelope {
  animation: wppostcards-postcard-enter-envelope 0.8s cubic-bezier(0.4, 0.0, 0.6, 1) forwards;
}

.wppostcards-envelope-flap.stage-close {
  animation: wppostcards-envelope-close 0.6s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.wppostcards-animated-envelope.stage-fly-to-corner {
  animation: wppostcards-envelope-fly-to-corner 2.0s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.wppostcards-animated-envelope.stage-to-notification {
  animation: wppostcards-envelope-to-notification 0.4s cubic-bezier(0.4, 0.0, 0.6, 1) forwards;
}

/* Notification entrance animation (enhanced) */
#wppostcards-floating-notice.from-animation {
  animation: wppostcards-notification-appear 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes wppostcards-notification-appear {
  0% {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .wppostcards-animated-postcard {
    width: 300px;
  }
  
  .wppostcards-animated-envelope {
    width: 320px;
    height: 220px;
  }
}

@media (max-width: 480px) {
  .wppostcards-animated-postcard {
    width: 250px;
  }
  
  .wppostcards-animated-envelope {
    width: 280px;
    height: 190px;
  }
}
