/* =========================================================================
   intro.css — abertura: livro 3D → lápis desenha o coração → logótipo → pátio

   Implementado só com CSS 3D, SVG e JavaScript simples. Sem WebGL, sem
   bibliotecas, sem modelos 3D. Duração total ~3,4 s, com opção de saltar.
   ========================================================================= */

.intro {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 46%, #2B3A78 0%, #1B2750 48%, #131C3B 100%);
  perspective: 1400px;
  perspective-origin: 50% 46%;
}
.intro[hidden] { display: none !important; }

/* halo de luz que sai de dentro do livro */
.intro::before {
  content: "";
  position: absolute;
  inset-block-start: 46%;
  inset-inline-start: 50%;
  translate: -50% -50%;
  inline-size: min(96vmin, 820px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 248, 218, .95) 0%, rgba(255, 236, 170, .40) 34%, transparent 66%);
  opacity: 0;
  transform: scale(.25);
}

/* ---------- Palco ------------------------------------------------------- */
.intro__stage {
  position: relative;
  inline-size: min(76vmin, 580px);
  aspect-ratio: 4 / 3;
  transform-style: preserve-3d;
  transform: rotateX(26deg) rotateZ(-7deg) scale(.92);
}

/* ---------- Livro -------------------------------------------------------
   Todos os painéis ocupam a metade direita e giram em torno da lombada.
   Fechado, o livro é um rectângulo vertical deslocado para a direita;
   ao abrir, desdobra-se para a esquerda e volta ao centro. */
.intro__book {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: translateX(-25%);
}

.intro__panel {
  position: absolute;
  inset-block: 5%;
  inset-inline-start: 50%;
  inline-size: 50%;
  transform-origin: left center;
  transform-style: preserve-3d;
  border-radius: 3px 7px 7px 3px;
}

/* cada folha tem duas faces reais: frente e verso */
.intro__face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.intro__face--back { transform: rotateY(180deg); border-radius: 7px 3px 3px 7px; }

/* capa: azul por fora, guarda creme por dentro */
.intro__cover--left .intro__face--front {
  background: linear-gradient(118deg, #32438C 0%, #26366F 58%, #1B2750 100%);
  border-inline-start: 3px solid var(--color-gold);
  box-shadow: inset -3px 0 10px rgba(0, 0, 0, .3), -8px 14px 32px rgba(8, 12, 30, .5);
}
.intro__cover--left .intro__face--back {
  background: linear-gradient(248deg, #FFF8EC 0%, #FFEFD8 100%);
  border-inline-end: 3px solid var(--color-gold);
  box-shadow: inset 3px 0 12px rgba(27, 39, 80, .16);
}

/* páginas: creme dos dois lados */
.intro__page .intro__face--front {
  background: linear-gradient(248deg, #FFFDF8 0%, #FFF6E6 100%);
  box-shadow: 2px 4px 12px rgba(20, 26, 54, .2);
}
.intro__page .intro__face--back  { background: linear-gradient(248deg, #FFFCF4 0%, #FFF3DE 100%); }

/* contracapa, por baixo de tudo */
.intro__cover--right {
  background: linear-gradient(242deg, #32438C 0%, #26366F 58%, #1B2750 100%);
  box-shadow: 10px 16px 40px rgba(8, 12, 30, .55);
  border-inline-end: 3px solid var(--color-gold);
  transform: translateZ(-2px);
}

/* página direita, sempre visível depois de o livro abrir */
.intro__page--right {
  background: linear-gradient(248deg, #FFFDF8 0%, #FFF4E2 100%);
  box-shadow: inset 3px 0 9px rgba(27, 39, 80, .10);
  transform: translateZ(0px);
}

/* páginas que viram para a esquerda */
.intro__page--a { transform: translateZ(3px); }
.intro__page--b { transform: translateZ(2px); }
.intro__page--c { transform: translateZ(1px); }

/* capa da frente, por cima de tudo quando o livro está fechado */
.intro__cover--left { transform: translateZ(5px); }

/* lombada */
.intro__spine {
  position: absolute;
  inset-block: 5%;
  inset-inline-start: calc(50% - 3px);
  inline-size: 6px;
  background: linear-gradient(90deg, #16204A, #2B3A78, #16204A);
  border-radius: 2px;
  transform: translateZ(-3px);
}

/* ---------- Coração desenhado pelo lápis -------------------------------- */
.intro__art {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: translateZ(26px);
  opacity: 0;
}
.intro__heart { inline-size: 62%; color: var(--color-secondary); overflow: visible; }
.intro__heart path {
  fill: none;
  stroke: currentColor;
  stroke-width: 22;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: var(--len, 4200);
  stroke-dashoffset: var(--len, 4200);
  filter: drop-shadow(0 3px 10px rgba(232, 64, 80, .45));
}

/* lápis que percorre o traço */
.intro__pencil {
  position: absolute;
  inline-size: 21%;
  transform-origin: 50% 88%;
  opacity: 0;
  filter: drop-shadow(0 6px 14px rgba(8, 12, 30, .5));
}

/* ---------- Logótipo e assinatura --------------------------------------- */
/* a marca aparece centrada no palco, à medida que o livro se apaga */
.intro__mark {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--space-5);
  text-align: center;
  transform: translateZ(90px);
  pointer-events: none;
}
.intro__mark img {
  inline-size: min(62vmin, 380px);
  opacity: 0;
  transform: translate3d(0, 18px, 0) scale(.92);
}
.intro__motto {
  font-family: var(--font-quote);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(1.15rem, .85rem + 1.5vw, 1.9rem);
  letter-spacing: .01em;
  color: var(--color-gold-tint);
  opacity: 0;
  transform: translate3d(0, 10px, 0);
}

/* ---------- Saltar ------------------------------------------------------- */
.intro__skip {
  position: absolute;
  inset-block-end: calc(env(safe-area-inset-bottom, 0px) + 22px);
  inset-inline-end: 22px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: var(--fs-tiny);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .78);
  background: rgba(255, 255, 255, .09);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius-pill);
  opacity: 0;
  transition: opacity var(--dur) var(--ease), background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.intro__skip:hover { background: rgba(255, 255, 255, .18); color: #fff; }
.intro__skip:focus-visible { outline: 3px solid #fff; outline-offset: 3px; opacity: 1; }
.intro.is-running .intro__skip { opacity: 1; }

/* =========================================================================
   Coreografia — accionada por .is-running
   ========================================================================= */
/* Curva própria para o virar de páginas: começa devagar, para o livro fechado
   ser realmente visto, e assenta com suavidade. */
.intro { --ease-turn: cubic-bezier(.52, .02, .22, 1); }

.intro.is-running .intro__stage       { animation: stageIn 3700ms var(--ease-out) both; }
.intro.is-running::before             { animation: glow 2100ms var(--ease-out) 900ms both; }
.intro.is-running .intro__book        { animation: unfold 1100ms var(--ease-turn) 340ms both,
                                                    bookOut 520ms var(--ease) 2420ms both; }
.intro.is-running .intro__cover--left { animation: turn 1000ms var(--ease-turn) 340ms both; }
.intro.is-running .intro__page--c     { animation: turn 960ms var(--ease-turn) 430ms both; }
.intro.is-running .intro__page--b     { animation: turn 960ms var(--ease-turn) 510ms both; }
.intro.is-running .intro__page--a     { animation: turn 960ms var(--ease-turn) 590ms both; }
.intro.is-running .intro__art         { animation: artIn 380ms var(--ease-out) 1240ms both, artOut 460ms var(--ease) 2460ms both; }
.intro.is-running .intro__heart path  { animation: drawHeart 1150ms var(--ease-out) 1300ms both; }
.intro.is-running .intro__pencil      { animation: pencilRun 1300ms var(--ease-out) 1270ms both; }
.intro.is-running .intro__mark img    { animation: markIn 700ms var(--ease-out) 2560ms both; }
.intro.is-running .intro__motto       { animation: markIn 640ms var(--ease-out) 2820ms both; }

/* a câmara avança e atravessa as páginas abertas */
@keyframes stageIn {
  0%   { transform: rotateX(28deg) rotateZ(-7deg) scale(.84); opacity: 0; }
  6%   { opacity: 1; }
  38%  { transform: rotateX(18deg) rotateZ(-3deg) scale(.98); }
  66%  { transform: rotateX(6deg)  rotateZ(0deg)  scale(1.02); opacity: 1; }
  88%  { transform: rotateX(0deg)  rotateZ(0deg)  scale(1.04); opacity: 1; }
  100% { transform: rotateX(0deg)  rotateZ(0deg)  scale(1.26); opacity: 0; }
}
@keyframes glow {
  0%   { opacity: 0; transform: scale(.32); }
  40%  { opacity: .92; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.65); }
}
@keyframes unfold {
  from { transform: translateX(-25%); }
  to   { transform: translateX(0); }
}
@keyframes turn {
  from { transform: rotateY(0deg) translateZ(var(--z, 4px)); }
  to   { transform: rotateY(-176deg) translateZ(var(--z, 4px)); }
}
@keyframes artIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes artOut { from { opacity: 1; transform: translateZ(26px) scale(1); }
                    to   { opacity: 0; transform: translateZ(26px) scale(1.18); } }
@keyframes bookOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes drawHeart { to { stroke-dashoffset: 0; } }
@keyframes markIn { to { opacity: 1; transform: none; } }

/* o lápis acompanha grosseiramente o traçado do coração */
@keyframes pencilRun {
  0%   { opacity: 0; transform: translate3d(-4%, 24%, 30px) rotate(-16deg); }
  10%  { opacity: 1; }
  32%  { transform: translate3d(-18%, -18%, 30px) rotate(-8deg); }
  56%  { transform: translate3d(6%, -30%, 30px) rotate(4deg); }
  78%  { transform: translate3d(24%, -6%, 30px) rotate(12deg); }
  94%  { opacity: 1; transform: translate3d(8%, 22%, 30px) rotate(6deg); }
  100% { opacity: 0; transform: translate3d(4%, 26%, 30px) rotate(4deg); }
}

/* saída: o palco desvanece e entrega o ecrã ao herói */
.intro.is-leaving {
  animation: introOut 620ms var(--ease) both;
  pointer-events: none;
}
@keyframes introOut {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; }
}

/* o herói recebe a passagem com uma ligeira aproximação */
:root.intro-active body { overflow: hidden; }
:root.intro-handoff .hero__media img { animation: heroHandoff 1500ms var(--ease-out) both; }
@keyframes heroHandoff {
  from { transform: scale(1.1); }
  to   { transform: scale(1); }
}

@media (max-width: 640px) {
  .intro__stage { inline-size: min(84vw, 340px); }
  .intro__mark img { inline-size: min(74vw, 280px); }
}

@media (prefers-reduced-motion: reduce) {
  .intro { display: none !important; }
  :root.intro-active body { overflow: auto; }
  :root.intro-handoff .hero__media img { animation: none !important; }
}
