/* ==========================================================================
   PAGE TRANSITIONS
   The browser's own cross-document view transitions, given a type by the
   script in PageTransitions.liquid. The bars (app-header, tab-bar) are named,
   so they hold still while the screen under them moves, and the short lines
   that mark the current tab (header-marker, tab-marker) slide to the next one.
   Without motion, or in a browser without these transitions, the screen
   simply changes.
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

/* The ground behind the screens while they move: ink, so a screen stepping
   back darkens instead of flashing white (Safari does not paint the page's
   own background here). */
::view-transition {
  background-color: var(--ink);
}

::view-transition-group(*) {
  animation-duration: 560ms;
  animation-timing-function: var(--ease-screen);
}

::view-transition-group(header-marker),
::view-transition-group(tab-marker) {
  animation-duration: 600ms;
  animation-timing-function: var(--ease-spring);
}

/* While the join sheet rises or falls the bars belong to the screen it
   covers, and travel with it. */
.is-bars-travelling .site-header__bar,
.is-bars-travelling .site-header__marker,
.is-bars-travelling .tab-bar,
.is-bars-travelling .tab-bar__marker {
  view-transition-name: none;
}

/* FORWARD AND BACK */

/* The new screen slides in over the old one, which drifts the other way and
   darkens, as a pushed screen does on a phone. */
html:active-view-transition-type(forward)::view-transition-old(root) {
  animation: page-transitions-drift-left 560ms var(--ease-screen) both;
}

html:active-view-transition-type(forward)::view-transition-new(root) {
  animation: page-transitions-enter-right 560ms var(--ease-screen) both;
  box-shadow: -24px 0 60px -24px color-mix(in srgb, var(--ink) 55%, transparent);
}

html:active-view-transition-type(back)::view-transition-old(root) {
  z-index: 2;
  animation: page-transitions-leave-right 520ms var(--ease-screen) both;
  box-shadow: -24px 0 60px -24px color-mix(in srgb, var(--ink) 55%, transparent);
}

html:active-view-transition-type(back)::view-transition-new(root) {
  animation: page-transitions-return-left 520ms var(--ease-screen) both;
}

/* THE JOIN SHEET */

html:active-view-transition-type(sheet-up)::view-transition-old(root) {
  animation: page-transitions-recede 620ms var(--ease-screen) both;
}

html:active-view-transition-type(sheet-up)::view-transition-new(root) {
  animation: page-transitions-rise 620ms var(--ease-screen) both;
}

html:active-view-transition-type(sheet-down)::view-transition-old(root) {
  z-index: 2;
  animation: page-transitions-fall 460ms var(--ease-in-out) both;
}

html:active-view-transition-type(sheet-down)::view-transition-new(root) {
  animation: page-transitions-come-forward 460ms var(--ease-out) both;
}

/* THE PASS THAT GROWS */

html:active-view-transition-type(morph)::view-transition-group(pass-morph) {
  z-index: 3;
  animation-duration: 640ms;
  animation-timing-function: var(--ease-screen);
}

html:active-view-transition-type(morph)::view-transition-old(root) {
  animation: page-transitions-fade-out 180ms ease both;
}

html:active-view-transition-type(morph)::view-transition-new(root) {
  animation: page-transitions-fade-in 360ms ease 140ms both;
}

/* FADE */

html:active-view-transition-type(fade)::view-transition-old(root) {
  animation: page-transitions-fade-out 240ms ease both;
}

html:active-view-transition-type(fade)::view-transition-new(root) {
  animation: page-transitions-fade-in 320ms ease both;
}

/* KEYFRAMES */

@keyframes page-transitions-enter-right {
  from {
    translate: 100% 0;
  }
}

@keyframes page-transitions-drift-left {
  to {
    translate: -26% 0;
    opacity: 0.5;
  }
}

@keyframes page-transitions-leave-right {
  to {
    translate: 100% 0;
  }
}

@keyframes page-transitions-return-left {
  from {
    translate: -26% 0;
    opacity: 0.5;
  }
}

@keyframes page-transitions-recede {
  to {
    scale: 0.92;
    translate: 0 1.5%;
    opacity: 0.45;
    clip-path: inset(0 round 32px);
  }
}

@keyframes page-transitions-rise {
  from {
    translate: 0 100%;
    clip-path: inset(0 round 32px 32px 0 0);
  }
  to {
    clip-path: inset(0 round 0);
  }
}

@keyframes page-transitions-fall {
  from {
    clip-path: inset(0 round 32px 32px 0 0);
  }
  to {
    translate: 0 100%;
    clip-path: inset(0 round 32px 32px 0 0);
  }
}

@keyframes page-transitions-come-forward {
  from {
    scale: 0.92;
    translate: 0 1.5%;
    opacity: 0.45;
    clip-path: inset(0 round 32px);
  }
}

@keyframes page-transitions-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes page-transitions-fade-in {
  from {
    opacity: 0;
  }
}
