/* Envelope gate */
.gate {
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 250, 244, 0.85), rgba(247, 240, 229, 0.6) 60%, rgba(233, 215, 194, 0.7)),
    url('/public/img/marble.webp') center / cover fixed,
    var(--paper);
}

.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3.5vh, 34px);
  padding: max(28px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  text-align: center;
}

/* ---------- intro text ---------- */
.intro { animation: rise 1.1s var(--ease) both; }
.monogram {
  margin: 0 0 6px;
  font-size: 30px;
  color: var(--sage);
}
.monogram span { font-size: 0.8em; opacity: 0.8; }
.intro .eyebrow { margin: 0; }
.names {
  margin: 4px 0 0;
  font-size: clamp(48px, 11vw, 84px);
  color: var(--ink);
  letter-spacing: 0.01em;
}

/* ---------- envelope ---------- */
.env {
  /* Shrink with screen height too, so title + envelope + password + button always fit on one screen. */
  --w: min(86vw, 500px, max(210px, calc((100vh - 360px) * 1.515)));
  --w: min(86vw, 500px, max(210px, calc((100dvh - 360px) * 1.515)));
  position: relative;
  width: var(--w);
  aspect-ratio: 971 / 641;
  perspective: 1400px;
  animation: drop 1.2s 0.15s var(--ease) both;
  filter: drop-shadow(0 18px 28px rgba(50, 47, 20, 0.22)) drop-shadow(0 3px 6px rgba(50, 47, 20, 0.15));
}
.env > * { position: absolute; inset: 0; }

.env-back {
  border-radius: 6px;
  background: linear-gradient(180deg, #4b4a23, #5d5b2b 60%, #66652f);
}

.env-letter {
  inset: 5% 5% 4%;
  border-radius: 4px;
  background: var(--cream);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.12);
  transform: translateY(0);
  transition: transform 1.1s var(--ease);
  overflow: hidden;
}
.env-letter::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(138, 131, 79, 0.45);
  border-radius: 2px;
}
.letter-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 9%;
}
.letter-inner .eyebrow { margin: 0; font-size: clamp(9px, 2.2vw, 11px); }
.letter-title { margin: 2px 0 0; font-size: clamp(34px, 9vw, 54px); color: var(--olive-deep); }
.letter-names { margin: 0; font-size: clamp(16px, 4vw, 22px); letter-spacing: 0.06em; }
.letter-names em { font-family: var(--script); font-style: normal; color: var(--sage); }

.env-pocket {
  background: url('/public/img/envelope.webp') center / 100% 100% no-repeat;
  border-radius: 6px;
  clip-path: polygon(0 6%, 50% 61%, 100% 6%, 100% 100%, 0 100%);
}

.env-flap {
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform 0.9s var(--ease);
  z-index: 3;
}
.flap-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  clip-path: polygon(0 0, 100% 0, 100% 6%, 50% 61%, 0 6%);
  border-radius: 6px 6px 0 0;
}
.flap-front { background: url('/public/img/envelope.webp') center / 100% 100% no-repeat; }
.flap-back {
  transform: rotateX(180deg);
  background: linear-gradient(0deg, #5a592a, #6f6d35);
}

.env-seal {
  inset: auto;
  left: 50%;
  top: 58%;
  width: 21%;
  z-index: 5;
  transform: translate(-50%, -50%);
  transition: transform 0.5s var(--ease), opacity 0.4s ease;
  filter: drop-shadow(0 4px 6px rgba(40, 30, 10, 0.35));
}
.env-seal img { width: 100%; height: auto; }

/* idle shimmer on the seal so it feels tappable */
.env-seal::after {
  content: '';
  position: absolute;
  inset: 8% 14%;
  border-radius: 50%;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.55) 50%, transparent 65%);
  background-size: 250% 100%;
  animation: shimmer 4.5s 1.6s ease-in-out infinite;
  mix-blend-mode: soft-light;
}

/* opening sequence */
.env.is-opening .env-seal { transform: translate(-50%, -30%) scale(0.7) rotate(-12deg); opacity: 0; }
.env.is-opening .env-flap { transform: rotateX(180deg); transition-delay: 0.25s; }
.env.is-open .env-flap { z-index: 0; }
.env.is-open .env-letter { transform: translateY(-58%); }
.env.is-open .env-pocket { z-index: 2; }
.env-letter { z-index: 1; }
.env-pocket { z-index: 2; }

.input-wrap.shake { animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both; }

/* ---------- form ---------- */
.unlock {
  width: min(100%, 380px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  animation: rise 1.1s 0.45s var(--ease) both;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.unlock.is-hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
.field label {
  display: block;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.input-wrap { position: relative; }
.input-wrap input {
  width: 100%;
  height: 52px;
  padding: 0 48px;
  text-align: center;
  font-size: 20px;
  letter-spacing: 0.08em;
  border-radius: 999px;
  border: 1px solid rgba(110, 108, 52, 0.35);
  background: rgba(255, 250, 244, 0.82);
  backdrop-filter: blur(4px);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.input-wrap input::placeholder { color: rgba(50, 47, 20, 0.3); letter-spacing: 0.2em; }
.input-wrap input:focus {
  border-color: var(--olive);
  background: var(--cream);
  box-shadow: 0 0 0 4px rgba(110, 108, 52, 0.12);
}
.peek {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--sage);
  cursor: pointer;
}
.peek[aria-pressed='true'] { color: var(--olive-deep); }

.err {
  min-height: 1.3em;
  margin: 0;
  font-style: italic;
  font-size: 17px;
  color: var(--wine);
}

.open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 54px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: var(--olive);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(75, 74, 35, 0.28);
  transition: background 0.25s, transform 0.25s var(--ease), box-shadow 0.25s;
}
.open-btn:hover { background: var(--olive-deep); transform: translateY(-1px); box-shadow: 0 14px 30px rgba(75, 74, 35, 0.32); }
.open-btn:active { transform: translateY(1px); }
.open-btn[disabled] { opacity: 0.7; cursor: progress; }
.open-btn svg { transition: transform 0.3s var(--ease); }
.open-btn:hover svg { transform: translateX(4px); }

/* when already signed in we only show the button */
.gate.authed #pwField, .gate.authed .err { display: none; }
.signed-in { display: none; margin: 0; font-style: italic; font-size: 17px; color: var(--ink-soft); }
.gate.authed .signed-in { display: block; }

/* Short screens (in-app browsers like Messenger/Instagram, small phones) */
@media (max-height: 720px) {
  .stage { gap: 14px; padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .monogram { font-size: 24px; margin-bottom: 2px; }
  .names { font-size: clamp(40px, 10vw, 64px); }
  .field label { margin-bottom: 6px; }
  .input-wrap input { height: 48px; }
  .open-btn { height: 50px; }
  .err { min-height: 1.1em; font-size: 16px; }
}
@media (max-height: 600px) {
  .monogram { display: none; }
  .names { font-size: clamp(36px, 9vw, 52px); }
  .unlock { gap: 6px; }
}

/* ---------- decor ---------- */
.decor { position: fixed; z-index: 1; pointer-events: none; user-select: none; }
.decor-bouquet {
  right: max(-40px, calc(50vw - 640px));
  bottom: -60px;
  height: min(78vh, 720px);
  transform: rotate(-8deg);
  opacity: 0.95;
  animation: sway 1.6s 0.3s var(--ease) both;
}
.decor-heart {
  left: max(16px, calc(50vw - 600px));
  top: 9vh;
  width: 120px;
  rotate: -14deg;
  opacity: 0.9;
  animation: rise 1.4s 0.6s var(--ease) both;
}
@media (max-width: 900px) {
  .decor-bouquet { height: 300px; right: -70px; bottom: -40px; opacity: 0.55; }
  .decor-heart { width: 64px; top: 18px; left: 14px; opacity: 0.75; }
}
@media (max-height: 640px) and (max-width: 900px) {
  .decor-bouquet { display: none; }
}

.veil {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--paper);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease;
}
.veil.on { opacity: 1; }

/* ---------- keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-24px) rotate(-2deg); } to { opacity: 1; transform: none; } }
@keyframes sway { from { opacity: 0; transform: translateY(40px) rotate(-2deg); } to { opacity: 0.95; transform: rotate(-8deg); } }
@keyframes shimmer { 0%, 70% { background-position: 150% 0; } 100% { background-position: -50% 0; } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
