/* =========================================================
   Anita Doces — motion.css
   1) Entradas no scroll (classe .is-in aplicada pelo main.js)
   2) Efeitos presos à rolagem em CSS puro (animation-timeline),
      com versão estática completa onde não há suporte.
   3) prefers-reduced-motion
   ========================================================= */

/* 1. Entradas --------------------------------------------------- */
.js [data-reveal] {
  opacity: 0;
  translate: 0 1.5rem;
  transition:
    opacity 0.8s var(--ease-out) var(--d, 0s),
    translate 1s var(--ease-out) var(--d, 0s);
}
.js [data-reveal].is-in { opacity: 1; translate: 0 0; }
.js [data-reveal="fade"] { translate: none; }

/* Títulos: cada linha sobe de dentro de uma máscara, com leve inclinação */
.js [data-reveal="lines"] { opacity: 1; translate: none; }
.js [data-reveal="lines"] .line { overflow: clip; padding-bottom: 0.14em; margin-bottom: -0.14em; }
.js [data-reveal="lines"] .line > span {
  display: inline-block;
  translate: 0 112%;
  rotate: 3deg;
  transform-origin: 0 100%;
  transition: translate 1.05s var(--ease-out), rotate 1.05s var(--ease-out);
}
.js [data-reveal="lines"] .line:nth-child(2) > span { transition-delay: 0.08s; }
.js [data-reveal="lines"] .line:nth-child(3) > span { transition-delay: 0.16s; }
.js [data-reveal="lines"].is-in .line > span { translate: 0 0; rotate: 0deg; }

/* Fotos: abrem de dentro para fora, com zoom que assenta */
.js [data-reveal="clip"] {
  opacity: 1;
  translate: none;
  clip-path: inset(10% 10% 10% 10% round 2.5rem);
  transition: clip-path 1.25s var(--ease-out) var(--d, 0s);
}
.js [data-reveal="clip"] img { scale: 1.22; transition: scale 1.7s var(--ease-out) var(--d, 0s); }
.js [data-reveal="clip"].is-in { clip-path: inset(0 0 0 0 round 0); }
.js [data-reveal="clip"].is-in img { scale: 1; }

/* Selos, cartões e bilhetes: entram com um pulinho */
.js [data-reveal="pop"] {
  translate: none;
  scale: 0.82;
  transition: opacity 0.6s var(--ease-out) var(--d, 0s), scale 0.9s var(--ease-spring) var(--d, 0s);
}
.js [data-reveal="pop"].is-in { scale: 1; }

.js [data-reveal="scale"] { translate: none; scale: 0.93; transition: opacity 0.9s var(--ease-out) var(--d, 0s), scale 1.1s var(--ease-out) var(--d, 0s); }
.js [data-reveal="scale"].is-in { scale: 1; }

/* Cascatas */
.js .treats > :nth-child(2) { --d: 0.08s; }
.js .treats > :nth-child(3) { --d: 0.04s; }
.js .treats > :nth-child(4) { --d: 0.12s; }
.js .gallery > :nth-child(3n + 2) { --d: 0.07s; }
.js .gallery > :nth-child(3n + 3) { --d: 0.14s; }
.js .flavors li { transition-delay: calc(var(--i, 0) * 35ms); }

/* 2. Scroll-driven (CSS puro) ----------------------------------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {

    /* Barra de progresso do header */
    .site-header__progress {
      animation: progress linear both;
      animation-timeline: scroll(root);
    }
    @keyframes progress { from { scale: 0 1; } to { scale: 1 1; } }

    /* Hero: a mordida cresce, a foto assenta e o texto sobe */
    .hero__photo {
      animation: photo-in 1.4s var(--ease-out) 0.15s both, bite-more linear both;
      animation-timeline: auto, view();
      animation-range: normal, cover 45% exit 100%;
    }
    @keyframes bite-more {
      from { --bite: clamp(2.4rem, 6.5vw, 5rem); }
      to { --bite: clamp(4rem, 11vw, 8.5rem); }
    }
    .hero__photo img {
      animation: hero-img linear both;
      animation-timeline: view();
      animation-range: cover 40% exit 100%;
    }
    @keyframes hero-img { from { scale: 1; } to { scale: 1.14; translate: 0 5%; } }
    .hero__head {
      animation: hero-leave linear both;
      animation-timeline: view();
      animation-range: exit 0% exit 100%;
    }
    @keyframes hero-leave { to { translate: 0 -12%; opacity: 0.35; } }

    /* A Anita: retrato respira; foto dos bastidores desliza */
    .anita__photo img {
      animation: breathe linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    @keyframes breathe { from { scale: 1.12; translate: 0 -3%; } to { scale: 1; translate: 0 3%; } }
    .backstage__photo {
      animation: drift-up linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    @keyframes drift-up { from { translate: 0 2.5rem; } to { translate: 0 -2.5rem; } }

    /* Desejo: seção presa; a foto aparece dentro de um coração mordido
       que cresce até ocupar a tela, e as frases entram em sequência */
    .desejo { height: 340svh; view-timeline: --desejo block; }
    .desejo__sticky { position: sticky; top: 0; height: 100svh; overflow: hidden; }
    .desejo__media {
      position: absolute;
      inset: 0;
      aspect-ratio: auto;
      max-height: none;
      -webkit-mask-image: url("../img/brand/coracao-mordido.svg");
      mask-image: url("../img/brand/coracao-mordido.svg");
      -webkit-mask-repeat: no-repeat;
      mask-repeat: no-repeat;
      -webkit-mask-position: 50% 50%;
      mask-position: 50% 50%;
      animation: heart-open linear both;
      animation-timeline: --desejo;
      animation-range: contain 0% contain 36%;
    }
    @keyframes heart-open {
      from { -webkit-mask-size: 46vmin; mask-size: 46vmin; }
      55% { -webkit-mask-size: 130vmax; mask-size: 130vmax; }
      to { -webkit-mask-size: 560vmax; mask-size: 560vmax; }
    }
    .desejo__media img {
      animation: desejo-zoom linear both;
      animation-timeline: --desejo;
      animation-range: contain 0% contain 100%;
    }
    @keyframes desejo-zoom { from { scale: 1.2; } to { scale: 1; } }
    .desejo__shade {
      opacity: 0;
      background: rgba(43, 21, 16, 0.58);
      animation: to-visible linear both;
      animation-timeline: --desejo;
      animation-range: contain 30% contain 42%;
    }
    @keyframes to-visible { to { opacity: 1; } }
    .desejo__hint {
      display: block;
      position: absolute;
      left: 50%;
      bottom: 12svh;
      translate: -50% 0;
      font-family: var(--font-hand);
      font-size: clamp(1.4rem, 1.1rem + 1vw, 2rem);
      color: var(--creme);
      white-space: nowrap;
      animation: to-hidden linear both;
      animation-timeline: --desejo;
      animation-range: contain 0% contain 12%;
    }
    @keyframes to-hidden { to { opacity: 0; translate: -50% 1rem; } }
    .desejo__beats {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      padding: var(--header-h) var(--gutter) 2rem;
      text-align: center;
    }
    .dbeat { grid-area: 1 / 1; opacity: 0; }
    .dbeat p { max-width: 13ch; margin-inline: auto; }
    .dbeat--1 { animation: dbeat linear both; animation-timeline: --desejo; animation-range: contain 38% contain 58%; }
    .dbeat--2 { animation: dbeat linear both; animation-timeline: --desejo; animation-range: contain 58% contain 78%; }
    .dbeat--3 { animation: dbeat-last linear both; animation-timeline: --desejo; animation-range: contain 78% contain 94%; }
    @keyframes dbeat {
      0% { opacity: 0; translate: 0 3rem; scale: 0.96; }
      30%, 70% { opacity: 1; translate: 0 0; scale: 1; }
      100% { opacity: 0; translate: 0 -3rem; scale: 1.02; }
    }
    @keyframes dbeat-last {
      0% { opacity: 0; translate: 0 3rem; scale: 0.96; }
      45%, 100% { opacity: 1; translate: 0 0; scale: 1; }
    }

    /* Doces: fotos com parallax curtinho */
    .treat__media img {
      scale: 1.1;
      animation: treat-drift linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
    .treat:hover .treat__media img { scale: 1.16; }
    @keyframes treat-drift { from { translate: 0 -4%; } to { translate: 0 4%; } }

    /* História: barra de progresso da linha do tempo */
    .timeline { view-timeline: --linha block; }
    .historia__bar span {
      transition: none;
      animation: grow-x linear both;
      animation-timeline: --linha;
      animation-range: cover 20% cover 85%;
    }
    @keyframes grow-x { from { scale: 0 1; } to { scale: 1 1; } }

    /* Feira: a folha rosa se abre, as linhas do título deslizam
       e os dias de feira ganham um círculo feito à mão */
    .feira::before {
      animation: sheet-in linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 70%;
    }
    @keyframes sheet-in { from { scale: 0.9 1; border-radius: 5rem; } to { scale: 1 1; } }
    .feira__title .line:nth-child(odd) {
      animation: from-left linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 40%;
    }
    .feira__title .line:nth-child(even) {
      animation: from-right linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 40%;
    }
    @keyframes from-left { from { translate: -5% 0; } to { translate: 0 0; } }
    @keyframes from-right { from { translate: 6% 0; } to { translate: 0 0; } }
    .week { view-timeline: --week block; }
    .week svg path {
      stroke-dasharray: 1;
      stroke-dashoffset: 1;
      animation: draw linear both;
      animation-timeline: --week;
      animation-range: entry 80% cover 55%;
    }
    .week li:nth-child(6) svg path { animation-range: cover 45% cover 70%; }
    @keyframes draw { to { stroke-dashoffset: 0; } }

    /* A casa: o fundo vai ficando da cor da fachada */
    .casa { view-timeline: --casa block; }
    .casa::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: -1;
      background: var(--lilas);
      opacity: 0;
      animation: to-visible linear both;
      animation-timeline: --casa;
      animation-range: entry 40% contain 45%;
    }
    .casa__facade-frame img {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 55%;
    }
    @keyframes settle { from { scale: 1.2; } to { scale: 1; } }
    .casa__varanda-frame {
      animation: drift-up linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }

    /* Instagram: no desktop as fileiras deslizam em sentidos opostos */
    @media (min-width: 64em) {
      .insta__row { overflow: visible; width: max-content; padding-inline: 0; }
      .insta__row li { width: clamp(14rem, 17vw, 18rem); }
      .insta__row--1 {
        animation: row-left linear both;
        animation-timeline: view();
        animation-range: cover 0% cover 100%;
      }
      .insta__row--2 {
        animation: row-right linear both;
        animation-timeline: view();
        animation-range: cover 0% cover 100%;
      }
      @keyframes row-left { from { translate: 4vw 0; } to { translate: calc(-100% + 92vw) 0; } }
      @keyframes row-right { from { translate: calc(-100% + 96vw) 0; } to { translate: 8vw 0; } }
    }

    /* Chamada final: a foto assenta e o título cresce */
    .final__frame img {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 60%;
    }
    .final__title {
      animation: grow linear both;
      animation-timeline: view();
      animation-range: entry 5% cover 40%;
    }
    @keyframes grow { from { scale: 0.9; opacity: 0.25; transform-origin: 0 100%; } to { scale: 1; opacity: 1; } }
  }
}

/* 3. Movimento reduzido ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .js [data-reveal],
  .js [data-reveal] img,
  .js [data-reveal="lines"] .line > span {
    opacity: 1 !important;
    translate: none !important;
    rotate: none !important;
    scale: none !important;
    clip-path: none !important;
  }
  .map__heart { animation: none !important; }
}
