/* ══════════════════════════════════════
   ENVELOPE — Cinematic Opening
   ══════════════════════════════════════ */

.envelope-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--charcoal);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.envelope-scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  perspective: 1200px;
}

/* ── Envelope Container ── */
.envelope-container {
  position: relative;
  width: min(340px, 85vw);
  height: min(240px, 60vw);
  transition: opacity 1.2s ease, transform 0.4s var(--ease-out);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.envelope-container:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 12px;
  border-radius: var(--radius-sm);
}

.envelope-container:hover .envelope-back {
  box-shadow:
    0 14px 50px rgba(0, 0, 0, 0.5),
    0 2px 10px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 0 30px rgba(201, 168, 76, 0.06);
}

.envelope-container:active {
  transform: scale(0.985);
}

.envelope-container.dissolving {
  opacity: 0;
}

/* ── Envelope Body ── */
.envelope-body {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.envelope-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, #d4c5a9, #c9b896, #bfae8a);
  border-radius: var(--radius-sm);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.4),
    0 2px 10px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.envelope-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(255, 255, 255, 0.03) 10px,
      rgba(255, 255, 255, 0.03) 20px
    );
  border-radius: var(--radius-sm);
}

/* Subtle hover lift on envelope body */
.envelope-container:hover .envelope-body {
  transform: translateY(-2px);
  transition: transform 0.5s var(--ease-out);
}

.envelope-body {
  transition: transform 0.5s var(--ease-out);
}

.envelope-left-flap,
.envelope-right-flap {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 3;
}

.envelope-left-flap {
  left: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(135deg, #c9b896, #b8a77e);
}

.envelope-right-flap {
  right: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(225deg, #c9b896, #b8a77e);
}

.envelope-bottom-flap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  z-index: 3;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
  background: linear-gradient(to top, #bfae8a, #c9b896);
}

/* ── Envelope Flap (Top) ── */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 55%;
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 5;
}

.envelope-flap-inner {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, #d4c5a9, #c9b896);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
}

.envelope-flap-inner::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0.1), transparent);
  clip-path: polygon(0 0, 50% 100%, 100% 0);
}

.envelope-container.flap-open .envelope-flap {
  transform: rotateX(180deg);
}

/* ── Wax Seal ── */
.envelope-seal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70px;
  height: 70px;
  z-index: 10;
  transition: transform 0.5s var(--ease-spring), filter 0.4s ease, opacity 0.6s ease;
  animation: sealBreathe 3s ease-in-out infinite;
}

@keyframes sealBreathe {
  0%, 100% {
    filter: brightness(1) drop-shadow(0 0 0 rgba(192, 57, 43, 0));
  }
  50% {
    filter: brightness(1.06) drop-shadow(0 0 8px rgba(192, 57, 43, 0.12));
  }
}

.envelope-container:hover .envelope-seal {
  transform: translate(-50%, -50%) scale(1.05);
  animation: none;
}

.envelope-container:hover .seal-shine {
  animation: sealHoverShine 0.8s var(--ease-out) forwards;
}

@keyframes sealHoverShine {
  0% {
    opacity: 0;
    transform: translateX(-100%);
  }
  40% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
    transform: translateX(100%);
  }
}

.envelope-container:hover .envelope-seal .seal-inner {
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.5),
    0 0 25px rgba(192, 57, 43, 0.15),
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}

/* Tactile press feedback — seal physically depresses */
.envelope-container.seal-pressing .envelope-seal {
  transform: translate(-50%, -50%) scale(0.92);
  transition: transform 0.15s ease-in;
}

.envelope-container.seal-pressing .seal-inner {
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    inset 0 3px 6px rgba(0, 0, 0, 0.4),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1);
  transition: box-shadow 0.15s ease-in;
}

/* Press ring — subtle expanding ring on press */
.seal-press-ring {
  position: absolute;
  inset: -8px;
  border-radius: var(--radius-full);
  border: 1.5px solid rgba(201, 168, 76, 0);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
}

.envelope-container.seal-pressing .seal-press-ring {
  inset: -14px;
  border-color: rgba(201, 168, 76, 0.3);
  opacity: 1;
  transition: all 0.2s ease-out;
}

.seal-inner {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 35% 35%, #c0392b, #962d22, #7a241b);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 15px rgba(0, 0, 0, 0.4),
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3);
  position: relative;
}

.seal-inner::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}

.seal-monogram {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.05em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.seal-shine {
  position: absolute;
  inset: -5px;
  border-radius: var(--radius-full);
  background: linear-gradient(
    105deg,
    transparent 20%,
    rgba(255, 255, 255, 0.4) 45%,
    rgba(255, 255, 255, 0.6) 50%,
    rgba(255, 255, 255, 0.4) 55%,
    transparent 80%
  );
  opacity: 0;
  transform: translateX(-100%);
  z-index: 1;
}

.envelope-container.seal-shining .seal-shine {
  animation: sealShine 1s var(--ease-out) forwards;
}

@keyframes sealShine {
  0% {
    opacity: 0;
    transform: translateX(-100%);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(100%);
  }
}

.envelope-container.seal-breaking .envelope-seal {
  transform: translate(-50%, -50%) scale(1.2);
  opacity: 0;
  filter: blur(4px);
  transition: all 0.6s var(--ease-out);
}

/* ── Golden Edge Reflection ── */
.envelope-edge-glow {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
}

.envelope-container.edge-glow .envelope-edge-glow {
  animation: edgeGlow 1.2s ease-out forwards;
}

@keyframes edgeGlow {
  0% {
    opacity: 0;
    border-color: rgba(201, 168, 76, 0);
    box-shadow: inset 0 0 0 0 rgba(201, 168, 76, 0);
  }
  40% {
    opacity: 1;
    border-color: rgba(201, 168, 76, 0.3);
    box-shadow: inset 0 0 20px 0 rgba(201, 168, 76, 0.1);
  }
  100% {
    opacity: 0;
    border-color: rgba(201, 168, 76, 0);
    box-shadow: inset 0 0 30px 0 rgba(201, 168, 76, 0);
  }
}

/* ── Warm White Light ── */
.envelope-light {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10%;
  height: 10%;
  border-radius: var(--radius-full);
  background: radial-gradient(circle, #faf8f0 0%, #f5edd6 40%, rgba(245, 237, 214, 0) 70%);
  opacity: 0;
  z-index: 1;
  pointer-events: none;
  filter: blur(6px);
  transition: none;
}

.envelope-container.light-emerging .envelope-light {
  animation: lightEmerge 2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes lightEmerge {
  0% {
    opacity: 0;
    width: 10%;
    height: 10%;
    filter: blur(8px);
  }
  50% {
    opacity: 0.7;
    width: 50%;
    height: 50%;
    filter: blur(14px);
  }
  100% {
    opacity: 0.9;
    width: 100%;
    height: 100%;
    filter: blur(18px);
  }
}

.envelope-container.light-expanding .envelope-light {
  animation: lightExpand 1.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes lightExpand {
  0% {
    opacity: 0.9;
    width: 100%;
    height: 100%;
    filter: blur(18px);
  }
  100% {
    opacity: 1;
    width: 300vmax;
    height: 300vmax;
    filter: blur(50px);
  }
}

/* ── Open Button ── */
.envelope-open-btn {
  position: absolute;
  bottom: 15%;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-2xl);
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-out);
  opacity: 0;
  animation: fadeInUp 0.8s var(--ease-out) 0.5s forwards;
}

.envelope-open-btn:hover {
  background: var(--gold);
  color: var(--charcoal);
  box-shadow: var(--shadow-glow);
}

.envelope-open-btn .open-btn-icon {
  width: 16px;
  height: 16px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Ambient Particles ── */
.envelope-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.env-particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--gold);
  border-radius: var(--radius-full);
  opacity: 0;
  animation: envFloat 6s infinite;
}

@keyframes envFloat {
  0% {
    opacity: 0;
    transform: translateY(100vh) scale(0);
  }
  20% {
    opacity: 0.6;
  }
  80% {
    opacity: 0.3;
  }
  100% {
    opacity: 0;
    transform: translateY(-10vh) scale(1);
  }
}

/* ── Screen fade out ── */
.envelope-screen.fade-out {
  opacity: 0;
  transition: opacity 1.2s ease;
}

@media (min-width: 768px) {
  .envelope-container {
    width: min(420px, 70vw);
    height: min(300px, 50vw);
  }

  .envelope-seal {
    width: 85px;
    height: 85px;
  }

  .seal-monogram {
    font-size: 1.3rem;
  }

  .envelope-open-btn {
    bottom: 12%;
  }
}

/* ── Hint text below button ── */
.envelope-hint {
  position: absolute;
  bottom: 11%;
  font-family: var(--font-body);
  font-size: 0.6rem;
  color: var(--text-on-dark-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0;
  animation: fadeInUp 0.8s var(--ease-out) 1.2s forwards;
  pointer-events: none;
}

@media (min-width: 768px) {
  .envelope-hint {
    bottom: 8.5%;
  }
}
