/* ==========================================================================
   envelope.css — homepage: envelope, selo, cartão e acesso
   Depende de base.css (variáveis e tipografia).
   ========================================================================== */

/* ==========================================================================
   4. HOMEPAGE
   ========================================================================== */

/* Durante a abertura a página não faz scroll (evita saltos) */
.page-home.is-animating { overflow: hidden; }

.stage {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  /* Vinheta muito suave: concentra o olhar no centro */
  background: radial-gradient(ellipse at 50% 45%, rgba(255, 255, 255, .45), rgba(255, 255, 255, 0) 65%);
}


/* --------------------------------------------------------------------------
   4.1 Cena e dimensões do envelope
   --env-w: o maior de entre: 760 px · 90% da largura · 84% da altura.
   Proporção 3:2 (como no Save the Date). A altura reservada (1,6 × H)
   inclui a aba aberta, para que nada saia do ecrã durante a abertura.
   -------------------------------------------------------------------------- */
.scene-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.scene {
  --env-w: min(760px, 90vw, 84vh);
  --env-h: calc(var(--env-w) / 1.5);
  position: relative;
  width: var(--env-w);
  height: var(--env-h);
  pointer-events: auto;
  cursor: pointer;
  transition: transform 1s var(--ease-paper);
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 1svh) {
  .scene { --env-w: min(760px, 90vw, 84svh); }
}

/* Ao abrir, a cena desce 30% da altura: a aba aberta e o cartão
   ganham espaço por cima sem sair do enquadramento. */
.is-open .scene {
  transform: translateY(calc(var(--env-h) * .3));
  cursor: default;
}

.envelope {
  position: absolute;
  inset: 0;
  transition: transform 1.3s var(--ease-settle);
}


/* --------------------------------------------------------------------------
   4.2 Peças do envelope
   -------------------------------------------------------------------------- */

/* Interior (fundo) — também transporta a sombra do envelope inteiro */
.envelope__back {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--env-inside) var(--grain);
  border-radius: 2px;
  box-shadow:
    0 1px 2px rgba(60, 52, 34, .10),
    0 18px 40px -18px rgba(60, 52, 34, .38),
    0 40px 80px -40px rgba(60, 52, 34, .30);
}

/* Bolsa: abas laterais numa única forma (sem triângulos separados) */
.envelope__pocket {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  /* Sombra projetada sobre o cartão, ao longo do recorte em V */
  filter: drop-shadow(0 -1px 1.5px rgba(60, 52, 34, .12));
}

.pocket__sides {
  position: absolute;
  inset: 0;
  background-color: var(--env-pocket);
  background-image:
    linear-gradient(90deg, rgba(60, 52, 34, .035), rgba(60, 52, 34, 0) 22%, rgba(60, 52, 34, 0) 78%, rgba(60, 52, 34, .035)),
    var(--grain);
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
  border-radius: 0 0 2px 2px;
}

/* Aba inferior, sobreposta às laterais, com sombra própria */
.pocket__bottom-shadow {
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 -1px 2.5px rgba(60, 52, 34, .16));
}

.pocket__bottom {
  position: absolute;
  inset: 0;
  background-color: var(--env-paper);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 40%),
    var(--grain);
  clip-path: polygon(
    0 100%, 7% 92.5%, 15% 85%, 24% 77%, 33% 69.5%, 41% 63%, 46% 59.3%,
    48.6% 57.8%, 50% 57.3%, 51.4% 57.8%, 54% 59.3%, 59% 63%, 67% 69.5%,
    76% 77%, 85% 85%, 93% 92.5%, 100% 100%
  );
}

/* Aba superior: roda sobre o vinco (topo) com perspetiva */
.envelope__flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60%;
  z-index: 5;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transform: perspective(1600px) rotateX(0deg);
  transition: transform 1.05s var(--ease-paper);
  pointer-events: none;
}

.is-open .envelope__flap { transform: perspective(1600px) rotateX(180deg); }

/* A partir dos 90º a aba passa para trás do cartão */
.envelope__flap.is-behind { z-index: 2; }

.flap-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transition: opacity .6s ease;
}

.flap-face--front { filter: drop-shadow(0 2px 3px rgba(60, 52, 34, .18)); }

.flap-face--front .flap-face__paper {
  position: absolute;
  inset: 0;
  background-color: var(--env-paper);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0) 55%, rgba(60, 52, 34, .025)),
    var(--grain);
  clip-path: polygon(
    0 0, 100% 0, 57.5% 87%, 55% 93%, 52.6% 97.6%, 50% 99.6%,
    47.4% 97.6%, 45% 93%, 42.5% 87%
  );
}

/* Forro: mesma forma, desenhada «de pernas para o ar» porque a face
   é virada 180º sobre si própria antes da rotação da aba. */
.flap-face--inner {
  transform: rotateX(180deg);
  filter: drop-shadow(0 1px 2px rgba(60, 52, 34, .16));   /* destaca o forro aberto sobre o fundo */
}

.flap-face--inner .flap-face__paper {
  position: absolute;
  inset: 0;
  background-color: var(--env-liner);
  background-image:
    linear-gradient(0deg, rgba(60, 52, 34, .06), rgba(60, 52, 34, 0) 35%),
    var(--grain);
  clip-path: polygon(
    0 100%, 100% 100%, 57.5% 13%, 55% 7%, 52.6% 2.4%, 50% .4%,
    47.4% 2.4%, 45% 7%, 42.5% 13%
  );
}


/* --------------------------------------------------------------------------
   4.3 Selo
   Centro do selo = ponta da aba (57% da altura) no eixo do envelope.
   Diâmetro = 17% da largura do envelope (como no Save the Date).
   -------------------------------------------------------------------------- */
.seal {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 57%;
  width: 17%;
  aspect-ratio: 104 / 106;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  filter:
    drop-shadow(0 1px 1px rgba(30, 30, 12, .35))
    drop-shadow(0 4px 6px rgba(40, 38, 20, .22));
  transition: transform .35s var(--ease-out), filter .35s var(--ease-out), opacity .55s ease;
  -webkit-tap-highlight-color: transparent;
}

.seal:disabled { cursor: default; }

.seal__svg { display: block; width: 100%; height: 100%; overflow: visible; }

.mono-letter {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 22px;
}
.mono-and {
  font-family: var(--font-script);
  font-size: 12.5px;
}

@media (hover: hover) {
  .seal:not(:disabled):hover {
    transform: translate(-50%, -50%) scale(1.035);
    filter:
      drop-shadow(0 1px 1px rgba(30, 30, 12, .35))
      drop-shadow(0 7px 10px rgba(40, 38, 20, .26));
  }
}

.seal:focus-visible {
  outline: 1px solid var(--olive-600);
  outline-offset: 6px;
}

/* Toque: o selo afunda ligeiramente */
.seal.is-pressed {
  transform: translate(-50%, -50%) scale(.96);
  filter: drop-shadow(0 1px 1px rgba(30, 30, 12, .3)) drop-shadow(0 2px 3px rgba(40, 38, 20, .18));
  transition-duration: .2s;
}

/* Depois de a aba abrir, o selo desvanece (como no vídeo) */
.seal.is-released {
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.04);
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   4.4 Indicação
   -------------------------------------------------------------------------- */
.scene__hint {
  position: absolute;
  left: 50%;
  top: calc(100% + clamp(1.5rem, 4vh, 2.75rem));
  margin: 0;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--font-caps);
  font-weight: 400;
  font-size: .8rem;
  letter-spacing: .28em;
  text-transform: lowercase;          /* em Cormorant SC, minúsculas = versaletes */
  color: var(--neutral-600);
  opacity: 0;
  transition: opacity .9s ease;
  pointer-events: none;
}
.is-ready .scene__hint { opacity: 1; transition-delay: .9s; }
.is-open  .scene__hint { opacity: 0; transition-delay: 0s; transition-duration: .3s; }


/* --------------------------------------------------------------------------
   4.5 Manga e cartão
   A manga recorta o cartão pela base do envelope; acima do vinco não
   há recorte (o cartão pode sair). A bolsa (z 4) cobre o resto.
   -------------------------------------------------------------------------- */
.envelope__sleeve {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  clip-path: polygon(-80% -1200%, 180% -1200%, 180% 100%, -80% 100%);
}

/* Proporção 2:3. Dentro do envelope ocupa 88% da largura:
   a escala é calculada em envelope.js (fitCardToEnvelope). */
.card {
  position: absolute;
  left: 6%;
  top: 6%;
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  container-type: inline-size;
  transform-origin: 0 0;
  visibility: hidden;                  /* invisível até a aba abrir: nada transparece nas juntas */
  background-color: var(--card-paper);
  box-shadow:
    0 0 0 .5px rgba(60, 52, 34, .08),
    0 2px 4px rgba(60, 52, 34, .06),
    0 26px 50px -24px rgba(60, 52, 34, .35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
}

/* Relevo de papel de algodão */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--cotton);
  background-size: 420px 420px;
  mix-blend-mode: multiply;
  opacity: .24;
  pointer-events: none;
}

.is-open .card { visibility: visible; }

/* Subida do cartão para fora da bolsa (deslocamento definido em JS) */
.card.is-rising { transition: transform 1.15s var(--ease-out); }

.card.is-settling { transition: transform 1.3s var(--ease-settle); }

/* Saída do envelope: desce (deslocamento definido em JS) e desvanece.
   O cartão não herda a opacidade: só as peças do envelope desvanecem. */
.is-leaving .envelope__back,
.is-leaving .envelope__pocket,
.is-leaving .flap-face {
  opacity: 0;
  transition: opacity .8s ease .35s;
}


/* Conteúdo do cartão: tamanhos em cqw (percentagem da largura do cartão)
   → a composição é idêntica em qualquer ecrã e nunca sai do cartão. */
.card__content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: none;
  padding: 9.5cqw 8cqw 0;
  text-align: center;
}

.card__names {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  font-weight: inherit;
  line-height: 1;
}

.card__name {
  font-family: var(--font-caps);
  font-weight: 500;
  font-size: 7.9cqw;
  letter-spacing: .085em;
  text-transform: uppercase;
  color: var(--olive-900);
  /* compensa o espaçamento da última letra para centrar opticamente */
  margin-right: -.085em;
}

.card__and {
  font-family: var(--font-script);
  font-size: 12cqw;
  line-height: .62;
  margin: 1.2cqw 0 1.6cqw;
  color: var(--olive-800);
}

.card__date {
  margin: 5cqw 0 0;
  font-family: var(--font-caps);
  font-weight: 400;
  font-size: max(12px, 3.5cqw);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--khaki);
}

.card__venue {
  display: flex;
  flex-direction: column;
  gap: .4cqw;
  margin: 3.2cqw 0 0;
  font-family: var(--font-caps);
  font-weight: 400;
  font-size: max(12px, 3.3cqw);
  letter-spacing: .13em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--khaki);
}

.card__rule {
  position: relative;
  width: 16cqw;
  height: 1px;
  margin: 5cqw 0 4.4cqw;
  background: var(--rule);
}
.card__rule::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.3cqw;
  height: 1.3cqw;
  background: var(--card-paper);
  border: 1px solid var(--rule);
  transform: translate(-50%, -50%) rotate(45deg);
}


/* --------------------------------------------------------------------------
   4.6 Acesso (dentro do cartão)
   -------------------------------------------------------------------------- */
.access {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .8s ease, transform .8s var(--ease-out);
  pointer-events: none;
}
.card.is-revealed .access {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.access__title {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: max(17px, 5.4cqw);
  line-height: 1.2;
  color: var(--olive-900);
}

.access__text {
  margin: 1.6cqw 0 0;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: max(13.5px, 3.55cqw);
  line-height: 1.4;
  color: var(--neutral-600);
}

/* Campo: apenas uma linha de escrita, como no papel.
   Tamanho mínimo de 16 px para o iPhone não ampliar a página. */
.access__input {
  width: min(100%, 70cqw);
  margin-top: 3cqw;
  padding: 1.4cqw 0 1.2cqw;
  border: 0;
  border-bottom: 1px solid rgba(57, 59, 32, .45);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-caps);
  font-weight: 500;
  font-size: max(16px, 4.4cqw);
  letter-spacing: .12em;
  text-indent: .12em;                  /* compensa o espaçamento para centrar */
  text-align: center;
  text-transform: uppercase;
  color: var(--olive-900);
  caret-color: var(--olive-600);
  outline: none;
  transition: border-color .25s ease;
  -webkit-appearance: none;
  appearance: none;
}
.access__input::placeholder {
  font-family: var(--font-caps);
  font-weight: 400;
  text-transform: lowercase;
  letter-spacing: .14em;
  color: rgba(110, 105, 91, .55);
}
.access__input:focus { border-bottom-color: var(--olive-900); }
.access__input[aria-invalid="true"] { border-bottom-color: var(--error); }

.access__message {
  min-height: 1.4em;
  margin: 1cqw 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: max(13px, 3.3cqw);
  line-height: 1.4;
  color: var(--neutral-600);
}
.access__message.is-error { color: var(--error); }

.access__button {
  margin-top: .6cqw;
  min-width: 34cqw;
  min-height: 44px;                    /* área de toque mínima */
  padding: 1.6cqw 6cqw;
  border: 1px solid var(--olive-600);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-caps);
  font-weight: 500;
  font-size: max(13px, 3.4cqw);
  letter-spacing: .3em;
  text-indent: .3em;
  text-transform: uppercase;
  color: var(--olive-900);
  cursor: pointer;
  transition: background-color .3s ease, color .3s ease, border-color .3s ease;
  -webkit-appearance: none;
  appearance: none;
}
.access__button:hover,
.access__button:focus-visible {
  background-color: var(--olive-600);
  border-color: var(--olive-600);
  color: var(--card-paper);
  outline: none;
}
.access__button[aria-busy="true"] { cursor: progress; opacity: .7; }


/* Saída do formulário depois da validação */
.card .access.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .45s ease, transform .45s ease;
  pointer-events: none;
}

/* Boas-vindas: ocupa o lugar do formulário */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 34cqw;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .9s ease, transform .9s var(--ease-out);
}
.welcome.is-visible { opacity: 1; transform: none; }
.welcome[hidden],
.access[hidden] { display: none; }   /* o atributo hidden prevalece sobre display: flex */

.welcome__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 5cqw;
  padding: 1.8cqw 5cqw;
  border: 1px solid var(--olive-600);
  font-family: var(--font-caps);
  font-weight: 500;
  font-size: max(12.5px, 3.1cqw);
  letter-spacing: .22em;
  text-indent: .22em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--olive-900);
  transition: background-color .3s ease, color .3s ease;
}
.welcome__button:hover,
.welcome__button:focus-visible {
  background-color: var(--olive-600);
  color: var(--card-paper);
  outline: none;
}

.welcome__text {
  max-width: 70cqw;
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: max(20px, 6.4cqw);
  line-height: 1.3;
  text-wrap: balance;
  color: var(--olive-900);
}


/* --------------------------------------------------------------------------
   4.7 Aguarela da quinta
   Ocupa o espaço que sobra no fundo do cartão: nunca se sobrepõe ao
   texto nem ao botão. Multiplicação: o branco da imagem funde-se no papel.
   -------------------------------------------------------------------------- */
.card__painting {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 2cqw;
  opacity: 0;
  transition: opacity 1.2s ease;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 26%);
  mask-image: linear-gradient(180deg, transparent 0, #000 26%);
}
.card__painting img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 22%;   /* em ecrãs baixos corta-se a relva, nunca os telhados */
  mix-blend-mode: multiply;
}
.card.is-painted .card__painting { opacity: 1; }


/* --------------------------------------------------------------------------
   4.8 Camada final
   O cartão termina aqui, em fluxo normal: centrado, responsivo,
   e com scroll apenas se o ecrã for mais baixo que o convite.
   Largura: 92% do ecrã, no máximo 33 rem, e limitada pela altura.
   -------------------------------------------------------------------------- */
.final-layer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 3vh 4vw;
  padding: 3svh 4vw;
  visibility: hidden;
  pointer-events: none;
}
.is-final .final-layer {
  visibility: visible;
  pointer-events: auto;
}

.card-slot {
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  flex: none;
}

.card.is-final {
  position: relative;
  flex: none;
  left: auto;
  top: auto;
  transform: none;
  transition: none;
  visibility: visible;
}

.is-final .scene-wrap { display: none; }


/* --------------------------------------------------------------------------
   4.9 Movimento reduzido: sem animação, convite aberto de imediato
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .scene, .envelope, .envelope__flap, .card, .seal,
  .access, .card__painting, .scene__hint {
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
}
