/* PolySculpt's own motion on top of the kit's micro-interactions (motion/motion.css): what moves as the
   page scrolls. Each section's heading and then its pieces rise into place once as they come into view,
   pictures unmask from below, a hairline under the header shows how far down the page you are, the nav
   marks the section you are reading, and the hero's window leans a little toward a mouse.
   Only transforms, opacity and clip-path move, so nothing lays out again while it plays. reveal.js marks
   what moves; until it runs (or if it never does) nothing is hidden. Under prefers-reduced-motion
   nothing is hidden and nothing moves: the nav mark and the colours still change. */

:root {
  --rv-ease: cubic-bezier(.22, 1, .36, 1);   /* a long soft landing, never past its mark */
  --rv-time: 760ms;
  --rv-rise: 28px;
}

@media screen and (prefers-reduced-motion: no-preference) {
  /* waiting: below its place and clear (only once reveal.js runs, so a page without it shows everything) */
  html.rv-on [data-rv]:not(.rv-in) { opacity: 0; transform: translateY(var(--rv-rise)); }
  html.rv-on [data-rv="pic"]:not(.rv-in) { opacity: 1; transform: none; clip-path: inset(18% 0 0 0 round var(--r-md, 12px)); }
  html.rv-on [data-rv="pic"]:not(.rv-in) img { scale: 1.08; }

  html.rv-on [data-rv] {
    transition: opacity var(--rv-time) var(--rv-ease), transform var(--rv-time) var(--rv-ease), clip-path 1100ms var(--rv-ease);
    transition-delay: calc(var(--rv-i, 0) * 70ms);
  }
  html.rv-on [data-rv="pic"] img { transition: scale 1400ms var(--rv-ease); transition-delay: calc(var(--rv-i, 0) * 70ms); }
  html.rv-on [data-rv="pic"].rv-in { clip-path: inset(0 0 0 0 round var(--r-md, 12px)); }
  /* once in, the kit's own hover lift and zoom take over without the reveal's delay */
  html.rv-on [data-rv].rv-done { transition-delay: 0ms; }
  html.rv-on [data-rv].rv-done img { transition-delay: 0ms; }

  /* the hero's window leans toward a mouse (reveal.js sets --tx and --ty, -1 to 1); never on touch */
  @media (hover: hover) and (pointer: fine) {
    .hero__art > .ly-piece--main { transform: perspective(1400px) rotateY(calc(var(--tx, 0) * 3deg)) rotateX(calc(var(--ty, 0) * -2.5deg)); transition: transform 600ms var(--rv-ease); will-change: transform; }
    .hero__art > .ly-piece--note { translate: calc(var(--tx, 0) * 10px) calc(var(--ty, 0) * 8px); transition: translate 600ms var(--rv-ease); }
  }

  /* how far down the page: a 2px sea-green line under the header, driven by the scroll itself (no script) */
  @supports (animation-timeline: scroll()) {
    .nav::after {
      content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none;
      background: linear-gradient(90deg, color-mix(in oklab, var(--p-accent) 40%, transparent), var(--p-accent));
      transform-origin: 0 50%; transform: scaleX(0);
      animation: rv-progress linear both; animation-timeline: scroll(root);
    }
    @keyframes rv-progress { to { transform: scaleX(1); } }
  }

  /* a chapter in the Documentation list: an arrow slides in beside its name */
  .docs-group a b::after { content: "→"; display: inline-block; margin-left: 6px; opacity: 0; transform: translateX(-6px);
                           transition: opacity 150ms var(--rv-ease), transform 150ms var(--rv-ease); }
  .docs-group a:is(:hover, :focus-visible) b::after { opacity: 1; transform: none; }

  /* a question: a sea-green rule draws along its foot under the pointer */
  .faq > .faq__item { position: relative; }
  .faq > .faq__item::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--p-accent);
                             transform: scaleX(0); transform-origin: 0 50%; transition: transform 500ms var(--rv-ease); }
  @media (hover: hover) { .faq > .faq__item:hover::after { transform: scaleX(1); } }
}

/* the nav word of the section in view (reveal.js sets aria-current), in every motion setting */
.nav__links .nav__link[aria-current="true"] { color: var(--p-accent); }

/* ---------------------------------------------------------------- round two */
@media screen and (prefers-reduced-motion: no-preference) {
  /* headings rise word by word, each word in its own mask (reveal.js wraps them in .rv-w > .rv-w__in) */
  .rv-w { display: inline-block; overflow: clip; vertical-align: top; padding-bottom: .14em; margin-bottom: -.14em; }
  .rv-w__in { display: inline-block; }
  html.rv-on [data-rv="words"] { opacity: 1; transform: none; }
  html.rv-on [data-rv="words"]:not(.rv-in) .rv-w__in { transform: translateY(105%); }
  html.rv-on [data-rv="words"] .rv-w__in { transition: transform 900ms var(--rv-ease); transition-delay: calc(var(--rv-wi, 0) * 38ms); }

  /* cards lean toward the pointer and a soft light follows it (reveal.js sets --mx, --my in 0..1); fine pointers only */
  @media (hover: hover) and (pointer: fine) {
    html:not([data-motion="off"]) main .card.rv-done:hover {
      transform: perspective(1100px) translateY(-3px) rotateX(calc((0.5 - var(--my, .5)) * 4deg)) rotateY(calc((var(--mx, .5) - 0.5) * 5deg));
      transition: transform 260ms var(--rv-ease), border-color 180ms, box-shadow 180ms;
    }
    main .card { position: relative; }
    main .card::after {
      content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 2; opacity: 0;
      background: radial-gradient(420px circle at calc(var(--mx, .5) * 100%) calc(var(--my, .5) * 100%), rgb(255 255 255 / .07), transparent 60%);
      transition: opacity 300ms var(--rv-ease);
    }
    main .card:hover::after { opacity: 1; }
  }

  /* pictures drift against the scroll inside their frames, a few per cent, driven by the scroll itself */
  @supports (animation-timeline: view()) {
    main :is(.panel--flush, .frame--split) > img {
      animation: rv-drift linear both; animation-timeline: view(); animation-range: cover;
    }
    @keyframes rv-drift { from { translate: 0 -4%; } to { translate: 0 4%; } }
    main :is(.panel--flush, .frame--split) > img { scale: 1.1; }
    html.rv-on [data-rv="pic"]:not(.rv-in) > img { scale: 1.18; }
  }

  /* the beta button: one light sweeps across it after the hero settles, then again every so often */
  .hero .btn--primary, footer.closing .btn--primary { overflow: hidden; isolation: isolate; }
  .hero .btn--primary::before, footer.closing .btn--primary::before {
    content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
    background: linear-gradient(105deg, transparent 35%, rgb(94 214 196 / .35) 50%, transparent 65%);
    transform: translateX(-120%); animation: rv-sheen 7s 1.4s var(--rv-ease) infinite;
  }
  @keyframes rv-sheen { 0% { transform: translateX(-120%); } 18%, 100% { transform: translateX(120%); } }

  /* the hero's ground: its two lights drift slowly, so the screenshot sits in a living room, not a flat fill */
  .hero__art { background-size: 140% 140%, 140% 140%, auto; animation: rv-ground 18s ease-in-out infinite alternate; }
  @keyframes rv-ground { from { background-position: 0% 0%, 100% 100%, 0 0; } to { background-position: 30% 20%, 70% 80%, 0 0; } }

  /* a chapter in a group comes in a beat after its group's heading */
  html.rv-on .docs-group[data-rv] li { transition: opacity 600ms var(--rv-ease), transform 600ms var(--rv-ease); transition-delay: calc(var(--rv-i, 0) * 70ms + var(--rv-li, 0) * 45ms + 120ms); }
  html.rv-on .docs-group[data-rv]:not(.rv-in) li { opacity: 0; transform: translateY(12px); }
}
