/* Motion shared by the home page and the product pages: slide content that
   arrives in turn, sections that rise into view while scrolling, and the app
   preview video on a product page's first slide. Everything here is an
   enhancement: without it, or with reduced motion, the page is unchanged. */

:root {
  --vn-deck-duration: 620ms;
  --vn-deck-easing: cubic-bezier(0.22, 1, 0.36, 1);
  --vn-deck-travel: 2.75rem;
}

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

@keyframes vn-settle {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

/* ------------------------------------------------------------------ */
/* Feature decks: a slide's content arrives label first, then headline,
   text, buttons, media and cards. The fill is backwards only, so an
   element keeps its own transform once it has arrived. scripts/header.js
   adds .vn-entrance at the first slide change, so the slide a page opens
   on is never held back.                                                */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
  .vn-entrance.deck-ready [data-vn-deck] > .current :is(.eyebrow, .qz-eyebrow, h1, h2, :is(h1, h2) ~ p, .inkline-actions, .hero-actions, .qz-actions, .featured-actions, .inkline-section-actions) {
    animation: vn-rise 420ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
    animation-delay: calc(40ms + var(--vn-step, 0) * 50ms);
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(h1, h2) {
    --vn-step: 1;
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(h1, h2) ~ p {
    --vn-step: 2;
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(.inkline-actions, .hero-actions, .qz-actions, .featured-actions, .inkline-section-actions) {
    --vn-step: 3;
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(figure, .qz-shot) {
    animation: vn-settle 460ms cubic-bezier(0.22, 1, 0.36, 1) 120ms backwards;
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li) {
    animation: vn-rise 420ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
    animation-delay: calc(140ms + var(--vn-card, 0) * 35ms);
  }

  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li):nth-child(2) { --vn-card: 1; }
  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li):nth-child(3) { --vn-card: 2; }
  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li):nth-child(4) { --vn-card: 3; }
  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li):nth-child(5) { --vn-card: 4; }
  .vn-entrance.deck-ready [data-vn-deck] > .current :is(article, .qz-checks li):nth-child(n + 6) { --vn-card: 5; }
}

/* ------------------------------------------------------------------ */
/* Scrolling pages enhance content as it comes into view. */
/* ------------------------------------------------------------------ */

@keyframes vn-enter {
  from {
    opacity: var(--vn-enter-opacity, 0.66);
    translate: 0 var(--vn-enter-distance, 17px);
  }
}

@media screen and (min-width: 761px) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .vn-reveal {
    animation: vn-enter var(--vn-enter-time, 410ms) cubic-bezier(0.22, 1, 0.36, 1);
  }

  .vn-reveal:has(:focus-visible) { animation: none; }
}

/* Both card grids zoom in around the bottom centre of each row. Their faces
   stay parallel to the screen, with the taper set by the card silhouette. */
.vn-home-page :is([data-vn-chapter="apps"] .section-heading, .game-row > h3, .vn-card-grid > .app-card) {
  --chapter-depth: 1000px;
  --chapter-rise: 60px;
  --chapter-zoom: -360px;
  --chapter-tilt: 0deg;
  --chapter-scale: 0.85;
  --chapter-opacity: 0.58;
}

/* scripts/reveal.js locates the middle of the grid relative to each card. */
.vn-home-page .vn-card-grid > .app-card {
  --chapter-origin: var(--card-origin-x, 50%) bottom;
}

@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  .vn-home-page :is([data-vn-chapter="apps"] .section-heading, .game-row > h3, .vn-card-grid > .app-card) {
    --chapter-rise: 40px;
    --chapter-zoom: -220px;
  }
}

/* Moving blocks are never the browser's scroll anchor: Safari would move the
   page to follow a card as it zooms in, so the page would jump. */
.vn-home-page :is([data-vn-chapter] > .chapter-content, [data-vn-chapter] .section-heading, .game-row > h3, .vn-card-grid > .app-card, [data-vn-mobile-opening]) {
  overflow-anchor: none;
}

@media screen and (prefers-reduced-motion: no-preference) {
  [data-vn-crawl-active] {
    --chapter-remaining: calc(1 - var(--chapter-progress));
    --chapter-transform: perspective(var(--chapter-depth, 950px))
      translateY(calc(var(--chapter-remaining) * var(--chapter-rise, 72px)))
      translateZ(calc(var(--chapter-remaining) * var(--chapter-zoom, 0px)))
      rotateX(calc(var(--chapter-remaining) * var(--chapter-tilt, 20deg)))
      scale(calc(1 - var(--chapter-remaining) * (1 - var(--chapter-scale, 0.97))));
    transform-origin: var(--chapter-origin, center bottom);
    transform: var(--chapter-transform);
    opacity: calc(1 - var(--chapter-remaining) * (1 - var(--chapter-opacity, 0.72)));
    transition: none;
  }

  .vn-home-page .app-card[data-vn-crawl-active] {
    transform: var(--chapter-transform);
  }

  [data-vn-crawl-active]:focus-visible {
    --chapter-transform: none;
    opacity: 1;
  }

  [data-vn-crawl-active]:has(:focus-visible) {
    --chapter-transform: none;
    opacity: 1;
  }

  .section-heading[data-vn-crawl-active]::before,
  [data-vn-crawl-active] .section-heading::before {
    transform: scaleX(var(--chapter-progress));
    transform-origin: left center;
  }
}

/* Desktop browsers with view timelines can run the same chapter motion natively. */
@keyframes vn-crawl {
  from {
    opacity: var(--chapter-opacity, 0.72);
    transform: perspective(var(--chapter-depth, 950px)) translateY(var(--chapter-rise, 72px))
      translateZ(var(--chapter-zoom, 0px)) rotateX(var(--chapter-tilt, 20deg)) scale(var(--chapter-scale, 0.97));
    animation-timing-function: var(--chapter-easing, cubic-bezier(0.5, 0.5, 0.7, 1));
  }

  to {
    opacity: 1;
    transform: perspective(var(--chapter-depth, 950px)) translateY(0) translateZ(0) rotateX(0deg) scale(1);
  }
}

@keyframes vn-rule {
  from {
    transform: scaleX(0);
    animation-timing-function: var(--chapter-easing, cubic-bezier(0.5, 0.5, 0.7, 1));
  }
}

@supports (animation-timeline: view()) {
  @media screen and (min-width: 761px) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    [data-vn-chapter] {
      view-timeline: --vn-chapter block;
    }

    [data-vn-chapter]:not(:has(:focus-visible)) > .chapter-content {
      transform-origin: var(--chapter-origin, center bottom);
      animation: vn-crawl linear backwards;
    }

    [data-vn-chapter]:not(:has(:focus-visible)) .section-heading::before {
      transform-origin: left center;
      animation: vn-rule linear backwards;
    }

    [data-vn-chapter]:not(:has(:focus-visible)) > .chapter-content,
    [data-vn-chapter]:not(:has(:focus-visible)) .section-heading::before {
      animation-timeline: --vn-chapter;
      animation-range: entry calc(var(--chapter-entry-start, 3) * 1dvh) entry calc(var(--chapter-entry-end, 42) * 1dvh);
    }

    /* Card grids move row by row: the heading and every card follow their
       own place on the page, so each row zooms in as it arrives and out as
       it leaves the way it came. Cards in a row share a top, so they move
       exactly alike. */
    :is([data-vn-chapter="apps"], [data-vn-chapter="games"]):not(:has(:focus-visible)) > .chapter-content {
      animation: none;
    }

    :is([data-vn-chapter="apps"] .section-heading, .game-row > h3, .vn-card-grid > .app-card):not(:focus-within) {
      transform-origin: var(--chapter-origin, center bottom);
      animation: vn-crawl linear backwards;
      animation-timeline: view();
      animation-range: entry calc(var(--chapter-entry-start, 3) * 1dvh) entry calc(var(--chapter-entry-end, 42) * 1dvh);
    }
  }
}

.vn-home-page {
  --vn-enter-distance: 24px;
  --vn-enter-time: 490ms;
  /* The entrance keeps moving into the reading area before it settles. */
  --chapter-entry-start: -8;
  --chapter-entry-end: 84;
  --chapter-easing: cubic-bezier(0.33333, 0.33333, 0.66667, 0.8);
  --chapter-depth: 1000px;
  --chapter-rise: 38px;
  --chapter-zoom: -175px;
  --chapter-tilt: 14deg;
  --chapter-scale: 0.93;
  --chapter-origin: center bottom;
  --chapter-opacity: 0.8;
}

.vn-home-page [data-vn-chapter="featured"] {
  --chapter-zoom: -265px;
  --chapter-tilt: 22deg;
  --chapter-scale: 0.88;
  --chapter-opacity: 0.72;
}

@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  html:not(.vn-home-page) body {
    --chapter-entry-start: -12;
    --chapter-entry-end: 64;
    --chapter-rise: 62px;
    --chapter-tilt: 10deg;
    --chapter-scale: 0.9;
    --chapter-opacity: 0.78;
    --chapter-origin: center min(25vh, 190px);
  }

  .vn-home-page {
    --chapter-rise: 30px;
    --chapter-zoom: -125px;
    --chapter-tilt: 13deg;
    --chapter-scale: 0.92;
  }

  .vn-home-page [data-vn-chapter="featured"] {
    --chapter-rise: 24px;
    --chapter-zoom: -175px;
    --chapter-tilt: 18deg;
    --chapter-scale: 0.9;
  }
}

@media (max-height: 480px) {
  .vn-home-page {
    --chapter-entry-end: 78;
  }

  /* The shorter pivot brings tall content into view sooner. */
  .vn-home-page [data-vn-chapter="featured"] {
    --chapter-origin: center min(100%, 55dvh);
  }

  .vn-home-page .vn-card-grid > .app-card {
    --chapter-origin: var(--card-origin-x, 50%) min(100%, 55dvh);
    --chapter-rise: 20px;
  }
}

/* ------------------------------------------------------------------ */
/* App preview video over a slide's screenshot. The screenshot
   stays underneath: it is what shows before the video plays, without
   the script and with reduced motion.                                   */
/* ------------------------------------------------------------------ */

.inkline-benchmark-slide {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  align-content: safe center;
  align-items: center;
  gap: clamp(1rem, 2.5vw, 2.5rem);
}

.inkline-benchmark-slide .inkline-tool-directory {
  grid-column: 1 / -1;
  margin-top: 0;
}

.inkline-benchmark-clip {
  width: min(100%, 52rem);
  margin: 0;
  justify-self: center;
}

.inkline-benchmark-clip figcaption {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.inkline-benchmark-frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--component-button-radius, 12px);
  box-shadow: var(--component-window-shadow);
}

.inkline-benchmark-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.inkline-benchmark-frame .vn-preview:not(.has-video) .vn-preview-bar {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.inkline-benchmark-frame .vn-preview-bar > .vn-preview-clip {
  display: none;
}

.vn-preview-frame {
  position: relative;
}

.vn-preview-frame > .vn-preview > video:not(:fullscreen) {
  border-radius: var(--component-button-radius, 12px);
}

.vn-preview {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: block;
  line-height: 1;
}

.vn-preview[hidden] {
  display: none;
}

/* The clip covers the screenshot's frame, so the window keeps its own edges
   instead of dark bands; full screen shows the whole clip. */
.vn-preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0b0d14;
  object-fit: cover;
  opacity: 0;
}

.vn-preview.has-video .vn-preview-video {
  opacity: 1;
}

.vn-preview-video:fullscreen {
  object-fit: contain;
  opacity: 1;
}

.vn-preview-bar {
  position: absolute;
  z-index: 3;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  opacity: 0.72;
}

.vn-preview:hover .vn-preview-bar,
.vn-preview-bar:focus-within {
  opacity: 1;
}

.vn-preview-clip {
  display: grid;
  width: var(--bar-size);
  height: var(--bar-size);
  place-items: center;
  border: var(--bar-inset) solid transparent;
  border-inline-width: 0;
  border-radius: var(--bar-inner-radius);
  background: transparent padding-box;
  padding: 0;
  color: var(--bar-ink);
  cursor: pointer;
}

.vn-preview-bar button[hidden] {
  display: none;
}

.vn-preview-bar svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.vn-preview-clip::before {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  content: "";
}

.vn-preview-clip[aria-pressed="true"]::before {
  width: 16px;
  background: #ffffff;
}

/* A single clip needs no picker: it is the only clip beside the two controls. */
.vn-preview-bar > .vn-preview-clip:first-child:nth-last-child(3) {
  display: none;
}

.vn-preview .vn-icon-play,
.vn-preview.is-playing .vn-icon-pause {
  display: block;
}

.vn-preview .vn-icon-pause,
.vn-preview.is-playing .vn-icon-play {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .vn-preview-video {
    transition: opacity 320ms ease-out;
  }

  .vn-preview-clip::before {
    transition: width 200ms ease-out, background-color 200ms ease-out;
  }

  .vn-preview-bar {
    transition: opacity 160ms ease-out;
  }
}

@media (max-width: 560px) {
  .vn-preview-bar {
    top: 0.3rem;
    left: 0.3rem;
  }
}
