/* ============================================================================
   Invitation Animation Component
   A delightful envelope opening animation for first-time visitors
   ========================================================================= */

/* ============================================================================
   Overlay and Container
   ========================================================================= */

#invitation-animation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: none; /* Hidden by default, JS makes visible */
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  contain: layout style paint;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

#invitation-animation-overlay.spotlight {
  opacity: 1;
}

#invitation-animation-overlay.fade-out {
  opacity: 0;
  transition: opacity 0.5s ease-out;
}

/* ============================================================================
   Envelope Container
   ========================================================================= */

.envelope-container {
  position: relative;
  width: 90%;
  max-width: 600px;
  perspective: 1000px;
  transform-style: preserve-3d;
}

.envelope {
  position: relative;
  width: 100%;
  aspect-ratio: 1.6;
  transform-style: preserve-3d;
  transform: scale(0.8);
  opacity: 0;
  transition: transform 1.2s ease-out, opacity 1.2s ease-out;
}

.envelope.spotlight {
  transform: scale(1);
  opacity: 1;
}

.envelope.flip {
  animation: envelopeFlip 1.5s ease-in-out forwards;
}

@keyframes envelopeFlip {
  0% {
    transform: scale(1) rotateY(0deg);
  }
  100% {
    transform: scale(1) rotateY(180deg);
  }
}

/* ============================================================================
   Envelope Front
   ========================================================================= */

.envelope-front {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #f5f5dc 0%, #e8e6d0 100%);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  backface-visibility: hidden;
  transform-style: preserve-3d;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.envelope-front::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.02) 0%,
    transparent 50%
  );
  border-radius: 8px;
  pointer-events: none;
}

.invitation-text {
  font-family: var(--font-wedding);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  color: var(--color-primary);
  text-align: center;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 1;
}

/* ============================================================================
   Envelope Back (with wax seal)
   ========================================================================= */

.envelope-back {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #e8e6d0 0%, #d8d6c0 100%);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  backface-visibility: hidden;
  transform: rotateY(180deg);
  transform-style: preserve-3d;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Envelope flap shadow effect */
.envelope-back::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 150px solid transparent;
  border-right: 150px solid transparent;
  border-top: 100px solid rgba(0, 0, 0, 0.05);
  z-index: 0;
}

.envelope.opening .envelope-back::before {
  animation: flapOpen 1s ease-out forwards;
}

@keyframes flapOpen {
  0% {
    transform: translateX(-50%) rotateX(0deg);
    transform-origin: top center;
  }
  100% {
    transform: translateX(-50%) rotateX(-120deg);
    transform-origin: top center;
  }
}

/* ============================================================================
   Wax Seal
   ========================================================================= */

.wax-seal {
  position: relative;
  width: 40%;
  height: 65%;
  /* Fallback gradient (if image doesn't load) */
  background: radial-gradient(circle, #8b0000 0%, #660000 100%);
  /* Custom wax seal image */
  background-image: url('../../images/wax_seal.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(139, 0, 0, 0.6),
              inset 0 2px 5px rgba(255, 255, 255, 0.2),
              inset 0 -2px 5px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease-out;
  outline: none;
}

.wax-seal:hover {
  transform: scale(1.05);
}

.wax-seal:focus {
  outline: 3px solid rgba(255, 255, 255, 0.8);
  outline-offset: 4px;
}

.seal-text {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Pulse animation for wax seal */
.wax-seal.pulse {
  animation: sealPulse 2s ease-in-out infinite;
}

@keyframes sealPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* Interaction hints - pulsing glow effect */
.wax-seal.hint {
  animation: sealPulse 2s ease-in-out infinite, hintGlow 2s ease-in-out infinite;
}

@keyframes hintGlow {
  0%, 100% {
    box-shadow: 0 4px 15px rgba(139, 0, 0, 0.6),
                inset 0 2px 5px rgba(255, 255, 255, 0.2),
                inset 0 -2px 5px rgba(0, 0, 0, 0.3),
                0 0 20px rgba(255, 215, 0, 0.6);
  }
  50% {
    box-shadow: 0 4px 15px rgba(139, 0, 0, 0.6),
                inset 0 2px 5px rgba(255, 255, 255, 0.2),
                inset 0 -2px 5px rgba(0, 0, 0, 0.3),
                0 0 40px rgba(255, 215, 0, 0.9);
  }
}

/* ============================================================================
   Invitation Card
   ========================================================================= */

.invitation-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  width: 90%;
  max-width: 500px;
  opacity: 0;
  z-index: 1;
  pointer-events: none;
  content-visibility: auto;
  transition: transform 1.5s ease-out, opacity 1.5s ease-out;
}

.invitation-card.visible {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.invitation-card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: block;
}

/* ============================================================================
   Skip Button
   ========================================================================= */

.skip-button {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.8);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10001;
  transition: all 0.2s ease-out;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.skip-button:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--color-primary);
  transform: scale(1.05);
}

.skip-button:focus {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  outline-offset: 3px;
}

.skip-button:active {
  transform: scale(0.98);
}

/* ============================================================================
   Responsive Design
   ========================================================================= */

/* Mobile Portrait */
@media (max-width: 768px) {
  .envelope-container {
    width: 90%;
    max-width: 400px;
  }

  .invitation-text {
    font-size: clamp(1.25rem, 6vw, 1.75rem);
    padding: 0 1rem;
  }

  .wax-seal {
    width: 35%;
    height: 55%;
  }

  .wax-seal::before {
    width: 50px;
    height: 50px;
  }

  .seal-text {
    font-size: 0.65rem;
  }

  .skip-button {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
  }

  .invitation-card {
    width: 95%;
    max-width: 350px;
  }
}

/* Mobile Landscape */
@media (max-height: 500px) and (orientation: landscape) {
  .envelope-container {
    max-width: 400px;
    width: 60%;
  }

  .invitation-text {
    font-size: clamp(1rem, 4vw, 1.5rem);
  }

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

  .wax-seal::before {
    width: 40px;
    height: 40px;
  }

  .seal-text {
    font-size: 0.6rem;
  }

  .invitation-card {
    max-width: 300px;
  }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1024px) {
  .envelope-container {
    max-width: 500px;
  }

  .invitation-card {
    max-width: 450px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .envelope-container {
    max-width: 600px;
  }

  .invitation-card {
    max-width: 500px;
  }

  .skip-button:hover {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  }
}

/* ============================================================================
   Accessibility - Reduced Motion
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  #invitation-animation-overlay,
  .envelope,
  .envelope.spotlight,
  .envelope.flip,
  .envelope.opening,
  .wax-seal,
  .wax-seal.pulse,
  .wax-seal.hint,
  .invitation-card,
  .invitation-card.visible {
    animation: none !important;
    transition: none !important;
  }

  /* For reduced motion, we rely on JS to skip the animation entirely */
  /* These rules are just a fallback in case JS doesn't catch it */
}

/* ============================================================================
   Print Styles
   ========================================================================= */

@media print {
  #invitation-animation-overlay {
    display: none !important;
  }
}
