/* ==========================================================================
   Password Gate — Envelope flip → flap open → card reveal (GSAP animated)
   ========================================================================== */

.gate-bypass #password-gate {
  display: none !important;
}

#password-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    160deg,
    rgba(60, 12, 30, 0.95) 0%,
    rgba(100, 18, 45, 0.9) 40%,
    rgba(46, 26, 14, 0.92) 100%
  ),
  url('../images/background.webp');
  background-size: cover;
}

body:has(#password-gate:not(.gate-hidden)) {
  overflow: hidden;
}

body.gate-active {
  overflow: hidden;
}

#password-gate.gate-hidden {
  display: none;
}

/* ---------- Envelope Scene ---------- */
.envelope-scene {
  perspective: 1200px;
  width: min(520px, 88vw);
  aspect-ratio: 4 / 3;
}

/* ---------- Envelope Wrapper (flip container) ---------- */
.envelope-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

/* ==========================================================================
   FRONT FACE — Password Form
   ========================================================================== */
.envelope-front {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: rotateY(0deg);
  transform: rotateY(0deg);
  background: linear-gradient(170deg, #fffdf8 0%, #f8edd8 40%, #f2e4c9 100%);
  border-radius: 10px;
  border: 1px solid rgba(180, 140, 90, 0.35);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.3),
    inset 0 0 60px rgba(200, 160, 100, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.envelope-front::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1.5px solid rgba(180, 140, 90, 0.5);
  border-radius: 6px;
  pointer-events: none;
}

.envelope-front::after {
  content: '';
  position: absolute;
  inset: 20px;
  border: 1px solid rgba(180, 140, 90, 0.3);
  border-radius: 4px;
  pointer-events: none;
}

.envelope-front-inner {
  text-align: center;
  padding: var(--space-sm) var(--space-lg);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   BACK FACE — Envelope back with flap, seal, and card
   ========================================================================== */
.envelope-back {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  background: linear-gradient(170deg, #fffdf8 0%, #f8edd8 40%, #f2e4c9 100%);
  border-radius: 10px;
  border: none;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.3),
    inset 0 0 60px rgba(200, 160, 100, 0.06);
}

/* ---------- Flap ---------- */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 58%;
  transform-origin: top center;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6%;
}

.envelope-flap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(178deg, #6b1530 0%, #52112a 70%, #4a0e20 100%);
  -webkit-clip-path: url(#flap-clip);
  clip-path: url(#flap-clip);
  border-radius: 10px 10px 0 0;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
}

.envelope-flap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    178deg,
    rgba(200, 160, 100, 0.12) 0%,
    transparent 40%
  );
  -webkit-clip-path: url(#flap-clip);
  clip-path: url(#flap-clip);
  pointer-events: none;
}

.envelope-seal {
  position: relative;
  z-index: 2;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow:
    0 3px 12px rgba(0, 0, 0, 0.35);
}

.seal-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ---------- Card inside the envelope ---------- */
.envelope-card {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 5%;
  bottom: 5%;
  background: url('../images/background.webp') center / cover no-repeat;
  border-radius: 10px;
  border: none;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.6),
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 30px 90px rgba(40, 10, 20, 0.45),
    0 50px 120px rgba(0, 0, 0, 0.3),
    inset 0 0 0 4px rgba(80, 20, 40, 0.6),
    inset 0 0 40px rgba(0, 0, 0, 0.3);
  z-index: 10;
  opacity: 0;
}

/* Color overlay matching the hero gradient */
.envelope-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(100, 18, 50, 0.78) 0%,
    rgba(150, 28, 52, 0.6) 40%,
    rgba(120, 90, 20, 0.5) 100%
  );
  border-radius: 10px;
  opacity: 0.85;
  transition: opacity 1.2s ease;
}

/* Inner decorative frame — cohesive with card tones */
.envelope-card::after {
  content: '';
  position: absolute;
  inset: 12px;
  border: 2px solid rgba(255, 220, 180, 0.2);
  border-radius: 6px;
  box-shadow:
    inset 0 0 20px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 220, 180, 0.08);
  pointer-events: none;
  transition: opacity 1.4s ease;
}

.envelope-card.darkening::before {
  opacity: 1;
}

.envelope-card.darkening::after {
  opacity: 0;
}

/* ---------- Shake animation ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-8px); }
  30%      { transform: translateX(8px); }
  45%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
  75%      { transform: translateX(-3px); }
  90%      { transform: translateX(3px); }
}

.envelope-front-inner.shake {
  animation: shake 0.5s ease-in-out;
}

/* ---------- Gate form elements ---------- */
.gate-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(180, 140, 90, 0.4);
  margin: 0 auto 0.4rem;
  display: block;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 0 0 4px rgba(180, 140, 90, 0.08);
}

.gate-title {
  font-family: 'Great Vibes', cursive;
  font-size: 2.4rem;
  font-weight: 400;
  color: var(--color-heading);
  margin-bottom: 0.1rem;
}

.gate-subtitle {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--color-text-muted);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-sm);
}

.gate-input-group {
  display: flex;
  gap: 0;
  border-radius: var(--border-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  width: fit-content;
  margin: 0 auto;
}

#gate-password {
  width: 200px;
  padding: 0.7rem 1rem;
  border: 1px solid var(--color-card-border);
  border-right: none;
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--color-white);
  color: var(--color-text);
  outline: none;
  border-radius: var(--border-radius) 0 0 var(--border-radius);
}

#gate-password::placeholder {
  color: var(--color-text-muted);
}

#gate-password:focus {
  border-color: var(--color-accent);
}

#gate-submit {
  padding: 0.7rem 1.4rem;
  background-color: var(--color-accent);
  color: var(--color-white);
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  border: none;
  cursor: pointer;
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  transition: background-color var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  flex-shrink: 0;
}

#gate-submit:hover {
  background-color: var(--color-accent-hover);
}

.gate-error {
  color: var(--color-error);
  font-size: 0.85rem;
  margin-top: var(--space-xs);
  font-weight: 500;
}

#gate-submit.loading {
  opacity: 0.6;
  pointer-events: none;
}
