/* Page transitions: native cross-document view transitions.
   Copy this file whole. It needs no JavaScript; transitions.js is an optional
   extra that makes Back play in reverse.

   Browsers without cross-document view transitions (Firefox, Samsung
   Internet as of Oct 2026) ignore all of this and navigate normally. */

/* 1 · Opt in, but only for people who have not asked for less motion.
   Both pages of a navigation must include this rule. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}

/* 2 · The masthead is on every page and in the same place, so give it its own
   name. It then holds still while the page under it changes, instead of
   crossfading with everything else. Only do this for a sticky or fixed
   header: a header that has scrolled off the top would fly back down. */
.masthead { view-transition-name: masthead; }

/* 3 · Everything else is "root": old page lifts out, then new page settles
   in. Out and in barely overlap ("fade through"). If both are half-visible at
   once, two pages of text sit on top of each other and it reads as mush.
   Keep the whole thing under ~350ms. Every millisecond here is a
   millisecond the visitor waits for the page they asked for. */
::view-transition-old(root) { animation: vt-out 100ms cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: vt-in 240ms cubic-bezier(0, 0, .2, 1) 90ms both; }

@keyframes vt-out { to   { opacity: 0; transform: translateY(-10px); } }
@keyframes vt-in  { from { opacity: 0; transform: translateY(16px); } }

/* Back (set by transitions.js): the same move, the other way. */
html:active-view-transition-type(back)::view-transition-old(root) { animation-name: vt-out-back; }
html:active-view-transition-type(back)::view-transition-new(root) { animation-name: vt-in-back; }
@keyframes vt-out-back { to   { opacity: 0; transform: translateY(10px); } }
@keyframes vt-in-back  { from { opacity: 0; transform: translateY(-16px); } }

/* 4 · Shared element: a piece's artwork travels from its card into the
   detail page's hero. The name goes on the element in the HTML (inline
   style), unique per piece, identical on both pages:
     list:   <div class="art" style="view-transition-name: piece-moon-jar">
     detail: <div class="art" style="view-transition-name: piece-moon-jar">
   view-transition-class lets one rule style every piece's morph. */
.art { view-transition-class: piece; }

::view-transition-group(*.piece) {
  animation-duration: 420ms;
  animation-timing-function: cubic-bezier(.2, .7, .1, 1);
}

/* Every named element is lifted onto its own layer ABOVE the page. The cards
   you did not click have no partner on the detail page, so by default they
   hang there for the full 420ms, floating over the new page's text. Send
   them out and in with the page instead. (:only-child = no partner.) */
::view-transition-old(*.piece):only-child { animation: vt-out 100ms cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(*.piece):only-child { animation: vt-in 240ms cubic-bezier(0, 0, .2, 1) 90ms both; }
html:active-view-transition-type(back)::view-transition-old(*.piece):only-child { animation-name: vt-out-back; }
html:active-view-transition-type(back)::view-transition-new(*.piece):only-child { animation-name: vt-in-back; }

/* The card is square and the hero is 4:5. Without these two rules each
   snapshot keeps its own shape inside the morphing box, and you see the
   square overhang and then snap. With them, both snapshots fill the box and
   crop, like the real elements do. */
::view-transition-image-pair(*.piece) { overflow: clip; border-radius: 6px; }
::view-transition-old(*.piece),
::view-transition-new(*.piece) { height: 100%; object-fit: cover; }
