/* Momentos de celebração (#422, design.md#movimento). O estado final é o CSS de cada tela; aqui só o movimento, que
   começa quando o controller marca o elemento com data-celebration="playing". Nada fica coberto ou desabilitado, nada
   repete em loop e, com movimento reduzido, a regra global em application.css desliga as animações. */

[data-celebration] {
  --celebration-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --celebration-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Momento 1, catálogo montado: uma reação. O segmento recém-concluído do guia enche e o selo surge com mola. Só na tela
   do selo: as outras telas da jornada não celebram o progresso. */
[data-celebration="playing"]:has(.page-steps-badge) .journey-progress-bar li[data-done]:has(+ li:not([data-done])) {
  background: linear-gradient(var(--text) 0 0) no-repeat left / 100% 100% var(--hairline);
  animation: celebration-fill var(--celebration-short) var(--celebration-out) both;
}

[data-celebration="playing"] .page-steps-badge {
  animation: celebration-pop var(--celebration-short) var(--celebration-spring) both;
}

[data-celebration="playing"] .page-steps-badge path {
  stroke-dasharray: 24;
  animation: celebration-draw 240ms 160ms var(--celebration-out) both;
}

/* Momento 2, a página se montando: uma sequência. As partes da prévia entram com 110 ms de intervalo, até 1,2 s. */
[data-celebration="playing"] :is(.page-preview-url, .page-preview-body > :not(ul), .page-preview-services li) {
  animation: celebration-assemble 420ms var(--celebration-out) calc(var(--celebration-order, 0) * 110ms) both;
}

.page-preview-body > h2 { --celebration-order: 1; }
.page-preview-body > p { --celebration-order: 2; }
.page-preview-services li { --celebration-order: 3; }
.page-preview-services li:nth-child(2) { --celebration-order: 4; }
.page-preview-services li:nth-child(n + 3) { --celebration-order: 5; }
.page-preview-body > .service-note { --celebration-order: 6; }
.page-preview-action { --celebration-order: 7; }

/* Momento 3, página no ar: o pico. O halo se abre, a porta surge com mola e solta três ondas, o selo e o título sobem;
   as partículas são do controller. Até 2,4 s. */
[data-celebration="playing"] .page-steps-live-heading::before {
  animation: celebration-glow 1800ms var(--celebration-out) both;
}

[data-celebration="playing"] .live-orb {
  animation: celebration-pop 760ms var(--celebration-spring) both;
}

[data-celebration="playing"] .live-orb svg {
  animation: celebration-door 900ms 200ms var(--celebration-spring) both;
}

[data-celebration="playing"] .live-orb-wave {
  animation: celebration-wave 1400ms var(--celebration-out) both;
}

[data-celebration="playing"] .live-orb-wave:nth-child(2) { animation-delay: 380ms; }
[data-celebration="playing"] .live-orb-wave:nth-child(3) { animation-delay: 760ms; }

[data-celebration="playing"] .page-steps-live-heading .badge {
  animation: celebration-pop 520ms 520ms var(--celebration-spring) both;
}

[data-celebration="playing"] .page-steps-live-heading :is(h1, p) {
  animation: celebration-rise 600ms 640ms var(--celebration-out) both;
}

/* "Como a solicitação chega", parte do Momento 3: os números acendem um a um, até 2,3 s; "Ver de novo" repete. */
.page-steps-how[data-celebration="playing"] li::before {
  animation: celebration-light 300ms 600ms ease-out both;
}

.page-steps-how[data-celebration="playing"] li:nth-child(2)::before { animation-delay: 1300ms; }
.page-steps-how[data-celebration="playing"] li:nth-child(3)::before { animation-delay: 2000ms; }

/* Momento 4, primeira solicitação: uma explosão menor. O aviso surge, a linha desce com um contorno que se apaga. */
[data-celebration="playing"] .first-request-notice {
  animation: celebration-pop 460ms 120ms var(--celebration-spring) both;
}

[data-celebration="playing"] [data-first-request] {
  animation:
    celebration-arrive 520ms var(--celebration-out) both,
    celebration-outline 800ms 400ms ease-out backwards;
}

@keyframes celebration-fill {
  from { background-size: 0 100%; }
}

@keyframes celebration-pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@keyframes celebration-draw {
  from { stroke-dashoffset: 24; }
}

@keyframes celebration-assemble {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
}

@keyframes celebration-glow {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }

  40% { opacity: 1; }
}

@keyframes celebration-door {
  from {
    opacity: 0;
    transform: scale(0.4) rotate(-12deg);
  }
}

@keyframes celebration-wave {
  0% {
    opacity: 0.8;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(2.8);
  }
}

@keyframes celebration-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes celebration-light {
  from {
    background: var(--surface);
    color: var(--text);
  }
}

@keyframes celebration-arrive {
  from {
    opacity: 0;
    transform: translateY(-24px);
  }
}

@keyframes celebration-outline {
  from {
    border-radius: var(--radius);
    box-shadow: 0 0 0 4px var(--accent);
  }

  to {
    border-radius: var(--radius);
    box-shadow: 0 0 0 0 transparent;
  }
}
