/* =====================================================================
   Portal: céu, grama e a caixa de correio com os dois envelopes.
   ===================================================================== */

.portal {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--portal-sky);
  color: var(--portal-ink);
  isolation: isolate;
}

.portal__clouds { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.portal__cloud { position: absolute; display: block; animation: drift 28s ease-in-out infinite alternate; }
.portal__cloud svg { width: 100%; height: auto; display: block; }
.portal__cloud--1 { left: 6%; top: 12%; width: 190px; }
.portal__cloud--2 { right: 4%; top: 8%; width: 240px; animation-duration: 34s; animation-delay: -12s; }
.portal__cloud--3 { left: 58%; top: 30%; width: 130px; opacity: 0.85; animation-duration: 40s; }
.portal__cloud--4 { left: -40px; top: 46%; width: 160px; opacity: 0.8; animation-delay: -20s; }

.portal__scene {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  align-items: center;
  padding: clamp(28px, 6vh, 64px) 16px 0;
}

.portal__title {
  font-family: var(--f-portal-display);
  font-weight: 800;
  font-size: clamp(2.3rem, 6.4vw, 4.4rem);
  line-height: 1;
  letter-spacing: -0.01em;
  text-align: center;
  color: #b8436f;
  -webkit-text-stroke: 8px #fff;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(255, 255, 255, 0.35);
}

.portal__box {
  position: relative;
  width: min(500px, 86vw, 62dvh);
  aspect-ratio: 1;
  margin-top: 2vh;
  align-self: end;
}
.mailbox-svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.portal__flag {
  position: absolute;
  z-index: 0;
  left: 82%;
  top: 6%;
  width: 21%;
  transform-origin: 14% 95%;
  animation: flag-wave 3.4s ease-in-out infinite;
}
.portal__flag svg { width: 100%; height: auto; display: block; }

/* A boca da caixa: os envelopes saem daqui (a parte de baixo fica escondida dentro). */
.portal__slot {
  position: absolute;
  z-index: 2;
  left: 19.5%;
  width: 61%;
  top: -12%;
  bottom: 47.6%;
  clip-path: inset(-200% -60% 0 -60%);
}

.portal__env {
  position: absolute;
  bottom: 2%;
  width: 66%;
  transition: transform 520ms var(--ease-out), opacity 300ms ease;
}
.portal__env--han { left: -12%; rotate: -9deg; }
.portal__env--juju { right: -12%; rotate: 8deg; }
@media (hover: hover) and (pointer: fine) {
  .portal__env:hover { transform: translateY(-14%); }
}
.portal__env:active { transform: translateY(-10%) scale(0.98); }
.portal__env:focus-visible { outline-offset: 6px; }
.portal.is-pulling .portal__env:not(.is-pulled) { opacity: 0.35; }
.portal__env.is-pulled { transform: translateY(-120%) rotate(calc(var(--r, 0deg))); }
.portal__env--han.is-pulled { --r: 11deg; }
.portal__env--juju.is-pulled { --r: -9deg; }
.portal__env.is-returning { animation: env-return 900ms var(--ease-out) both; }
@keyframes env-return {
  from { transform: translateY(-130%); opacity: 0; }
  60% { opacity: 1; }
  to { transform: none; }
}

.mail-env {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1.5;
  filter: drop-shadow(0 8px 10px rgba(58, 35, 30, 0.28));
}
.mail-env__body { position: absolute; inset: 0; border-radius: 8px; }
.mail-env__flap {
  position: absolute;
  inset: 0 0 auto;
  height: 56%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.mail-env__to {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  text-align: center;
  font-family: var(--f-portal-hand);
  font-weight: 700;
  font-size: clamp(1.25rem, 3.6vw, 1.7rem);
  line-height: 1;
}

/* Han: papel cinza-claro com renda e laço malva */
.mail-env--han .mail-env__body {
  background: #f4f1f5;
  border: 3px solid #b98aa1;
  box-shadow: inset 0 0 0 5px #fff, inset 0 0 0 7px #d8c8d2;
}
.mail-env--han .mail-env__body::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -9px;
  height: 12px;
  background: radial-gradient(circle at 7px 0, #fff 5px, #d8c8d2 5.5px, transparent 6.5px) 0 0 / 14px 12px repeat-x;
}
.mail-env--han .mail-env__flap { background: #e7dfe9; }
.mail-env__bow { position: absolute; left: 50%; top: 38%; width: 34%; translate: -50% -50%; color: #f5c6d6; --shape-line: #a8436c; }
.mail-env--han .mail-env__to { color: #2c2430; }

/* Juju: xadrez rosa com adesivo de estrela */
.mail-env--juju .mail-env__body {
  background-color: #fff;
  background-image:
    repeating-linear-gradient(0deg, rgba(244, 166, 194, 0.55) 0 12px, transparent 12px 24px),
    repeating-linear-gradient(90deg, rgba(244, 166, 194, 0.55) 0 12px, transparent 12px 24px);
  border: 3px solid #8fc6e8;
}
.mail-env--juju .mail-env__flap { background: #d9effc; }
.mail-env__star { position: absolute; right: 4%; top: -14%; width: 30%; color: #fde58a; --shape-line: #d4a72c; rotate: 12deg; }
.mail-env--juju .mail-env__to {
  color: #b8436f;
  -webkit-text-stroke: 5px #fff;
  paint-order: stroke fill;
}

.portal__hint {
  position: relative;
  z-index: 2;
  margin: 18px 0 calc(clamp(110px, 20vh, 190px) - 74px);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  font-family: var(--f-portal-hand);
  font-size: clamp(1.3rem, 3.4vw, 1.6rem);
  font-weight: 700;
  color: var(--portal-ink);
}
.portal__grass {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(110px, 20vh, 190px);
  background: var(--portal-grass);
  border-top: 10px solid var(--portal-grass-deep);
  z-index: 0;
}

/* ---------- introdução (o envelope aberto) ---------- */
.intro-layer:empty { display: none; }
.portal.is-intro .intro-layer { position: fixed; inset: 0; z-index: 20; }
.portal.is-intro .portal__scene,
.portal.is-intro .portal__clouds { visibility: hidden; transition: visibility 0s linear 400ms; }

.intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px 14px;
  overflow-y: auto;
}
.intro__backdrop { position: fixed; inset: 0; animation: fade-in 420ms ease both; }
.intro__card {
  position: relative;
  width: min(540px, 100%);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: clamp(40px, 7vw, 56px) clamp(22px, 6vw, 48px) 56px;
  text-align: center;
}
.intro__to { position: absolute; left: 22px; bottom: 16px; margin: 0; font-family: var(--f-hand); font-size: 1.5rem; line-height: 1; rotate: -4deg; }
.intro__title { font-family: var(--f-display); font-weight: 400; line-height: 1; text-wrap: balance; }
.intro__phrase { max-width: 32ch; }
.intro__chars { display: flex; justify-content: center; gap: 8px; margin: 4px 0 6px; }
.intro__char { width: 84px; height: 84px; rotate: var(--rot); font-size: 12px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2)); }
.intro__char .smart-img img { object-fit: contain; }
.intro__char .ph-char { border: 3px solid #fff; outline: 2px dashed var(--c-line); outline-offset: -7px; }
.intro__enter {
  min-height: 54px;
  padding: 12px 30px;
  border-radius: 999px;
  font-size: 1.2rem;
  font-family: var(--f-body);
  transition: transform 160ms var(--ease-out), box-shadow 200ms ease;
}
.intro__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 6px 12px;
  font-size: 0.95rem;
  border-radius: 999px;
}

/* --- Han: preto, branco, rosa e azul; laço que desamarra --- */
.intro--han .intro__backdrop {
  background-color: #1c171d;
  background-image:
    radial-gradient(circle, #f5c6d6 1.6px, transparent 2px),
    radial-gradient(circle, #c3dbf1 1.4px, transparent 1.8px);
  background-size: 46px 46px, 64px 64px;
  background-position: 0 0, 22px 30px;
}
.intro--han .intro__card {
  background: #fff;
  color: #2c2430;
  border-radius: 6px;
  box-shadow: inset 0 0 0 10px #fff, inset 0 0 0 12.5px #e7a9c2, inset 0 0 0 16px #fff, inset 0 0 0 17.5px #1c171d, 0 30px 60px -20px rgba(0, 0, 0, 0.6);
  transform-origin: 50% 0;
  animation: unfold 720ms var(--ease-out) both;
}
@keyframes unfold {
  from { opacity: 0; transform: perspective(900px) rotateX(-70deg) scaleY(0.6); }
  to { opacity: 1; transform: none; }
}
.intro__lace {
  position: absolute;
  left: 0;
  right: 0;
  height: 26px;
  background:
    radial-gradient(circle at 10px 17px, #1c171d 1.6px, transparent 2.1px) 0 0 / 20px 26px repeat-x,
    radial-gradient(circle at 10px 17px, #fff 4px, #f0b9cd 4.5px, #f0b9cd 5.5px, transparent 6px) 0 0 / 20px 26px repeat-x,
    radial-gradient(circle at 10px 12px, #fff 9px, #f0b9cd 9.5px, #f0b9cd 11px, transparent 11.5px) 0 0 / 20px 26px repeat-x,
    radial-gradient(circle at 0 6px, #fff 5px, #f0b9cd 5.5px, #f0b9cd 6.5px, transparent 7px) 0 0 / 20px 26px repeat-x;
}
.intro__lace--top { top: -25px; rotate: 180deg; }
.intro__lace--bottom { bottom: -17px; }
.intro__ribbon {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 16px;
  background: #f0b9cd;
  border-left: 2px solid #1c171d;
  border-right: 2px solid #1c171d;
  z-index: 1;
  animation: untie-l 900ms var(--ease-in-out) 520ms both;
}
.intro__ribbon--l { left: calc(50% - 8px); }
.intro__ribbon--r { left: calc(50% - 8px); animation-name: untie-r; }
@keyframes untie-l { to { transform: translateX(-260px) rotate(-18deg); opacity: 0; } }
@keyframes untie-r { to { transform: translateX(260px) rotate(18deg); opacity: 0; } }
.intro__bow {
  position: absolute;
  top: -22px;
  left: 50%;
  width: 92px;
  translate: -50% 0;
  color: #f5c6d6;
  --shape-line: #a8436c;
  animation: bow-off 760ms var(--ease-in-out) 420ms both;
}
@keyframes bow-off {
  0% { transform: none; }
  40% { transform: scale(1.12) rotate(-6deg); }
  100% { transform: translate(140px, -40px) rotate(28deg) scale(0.8); }
}
.intro__key { position: absolute; right: 18px; bottom: 30px; width: 90px; color: #b98aa1; rotate: -18deg; }
.intro--han .intro__to { font-family: 'Nanum Pen Script', cursive; font-size: 1.8rem; color: #64576a; }
.intro--han .intro__title { font-family: 'Grenze Gotisch', serif; font-size: clamp(2.6rem, 9vw, 3.6rem); color: #1c171d; }
.intro--han .intro__phrase { font-family: 'Nanum Pen Script', cursive; font-size: 1.8rem; line-height: 1.25; }
.intro--han .intro__enter { background: #1c171d; color: #fbe3ec; box-shadow: 0 10px 20px -10px rgba(168, 67, 108, 0.8); }
.intro--han .intro__enter:hover { box-shadow: 0 0 0 4px #f5c6d6, 0 10px 20px -10px rgba(168, 67, 108, 0.8); }
.intro--han .intro__back { color: #64576a; }
.intro--han .intro__back:hover { color: #a8436c; }

/* --- Juju: rosa e azul, florzinhas que desabrocham --- */
.intro--juju .intro__backdrop {
  background-color: #d4eefc;
  background-image:
    repeating-linear-gradient(0deg, rgba(251, 202, 219, 0.7) 0 22px, transparent 22px 44px),
    repeating-linear-gradient(90deg, rgba(251, 202, 219, 0.7) 0 22px, transparent 22px 44px);
}
.intro--juju .intro__card {
  background: #fff;
  color: var(--j-ink);
  border: 4px solid #f4a6c2;
  border-radius: 30px;
  box-shadow: 0 0 0 8px #fff, 0 26px 50px -18px rgba(0, 0, 0, 0.2);
  animation: card-bounce 640ms var(--ease-spring) both;
}
@keyframes card-bounce {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to { opacity: 1; transform: none; }
}
.intro__flower { position: absolute; width: 46px; color: #f7b5cf; animation: bloom 620ms var(--ease-spring) both; }
.intro__flower--0 { left: -18px; top: 30px; animation-delay: 300ms; }
.intro__flower--1 { right: -16px; top: 60px; width: 38px; color: #a9d8f5; animation-delay: 380ms; }
.intro__flower--2 { left: 18px; bottom: -16px; width: 36px; color: #fde58a; --flower-heart: #f4a6c2; animation-delay: 460ms; }
.intro__flower--3 { right: 24px; bottom: -20px; width: 50px; animation-delay: 540ms; }
.intro__flower--4 { left: 40%; top: -22px; width: 34px; color: #a9d8f5; animation-delay: 620ms; }
.intro__flower--5 { right: 30%; bottom: 38%; width: 0; }
.intro__star { position: absolute; width: 26px; color: #fde58a; --shape-line: #d4a72c; animation: twinkle 2.8s ease-in-out infinite; }
.intro__star--0 { left: 14%; top: 14px; }
.intro__star--1 { right: 12%; top: 22%; animation-delay: -0.8s; }
.intro__star--2 { left: 8%; bottom: 30%; animation-delay: -1.6s; width: 20px; }
.intro__star--3 { right: 18%; bottom: 14px; animation-delay: -2.2s; }
.intro--juju .intro__to { color: #2a62a8; font-weight: 700; }
.intro--juju .intro__title {
  font-family: 'Sniglet', sans-serif;
  font-weight: 800;
  font-size: clamp(2.4rem, 8.4vw, 3.4rem);
  color: #c2457a;
  -webkit-text-stroke: 7px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 3px 0 #f4a6c2);
}
.intro--juju .intro__phrase { font-family: 'Gaegu', sans-serif; font-size: 1.6rem; line-height: 1.25; }
.intro--juju .intro__enter { background: #c2457a; color: #fff; box-shadow: 0 10px 18px -8px rgba(0, 0, 0, 0.3); }
.intro--juju .intro__enter:hover { box-shadow: 0 10px 18px -8px rgba(0, 0, 0, 0.3), 0 0 0 4px #fde58a; }
.intro--juju .intro__back { color: #4a3846; }
.intro--juju .intro__back:hover { color: #c2457a; }

.intro.is-folding .intro__card { animation: fold-away 300ms var(--ease-out) both; }
@keyframes fold-away { to { opacity: 0; transform: translateY(40px) scale(0.92); } }

/* ---------- saída do portal ao entrar no universo ---------- */
.portal.is-leaving { position: fixed; inset: 0; z-index: 80; background: transparent; pointer-events: none; }
.portal.is-leaving .intro__backdrop { animation: fade-out 700ms ease 200ms both; }
.portal.is-leaving .intro--han .intro__card { animation: lift-away 760ms var(--ease-in-out) both; }
@keyframes lift-away {
  to { opacity: 0; transform: translateY(-70vh) rotate(-6deg) scale(0.9); }
}
.portal.is-leaving .intro--juju .intro__card { animation: zoom-away 620ms var(--ease-in-out) 120ms both; }
.portal.is-leaving .intro--juju .intro__flower { animation: petal-burst 700ms var(--ease-out) both; }
@keyframes zoom-away { to { opacity: 0; transform: scale(1.25); } }
@keyframes petal-burst { to { transform: translate(var(--bx, 0), var(--by, -120px)) rotate(180deg) scale(1.4); opacity: 0; } }
.intro__flower--0 { --bx: -160px; --by: -80px; }
.intro__flower--1 { --bx: 170px; --by: -60px; }
.intro__flower--2 { --bx: -140px; --by: 140px; }
.intro__flower--3 { --bx: 160px; --by: 150px; }
.intro__flower--4 { --bx: 0; --by: -180px; }

@media (max-width: 520px) {
  .intro__char { width: 66px; height: 66px; }
  .intro__key { width: 64px; bottom: 18px; right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .portal__cloud,
  .portal__flag { animation: none; }
}
