/* Pixel transition: a work card's image opens into the case page hero as one shot.

   Chrome / Edge / Safari 18.2+: cross-document View Transitions. The clicked card's
   image and the case hero share the name pt-hero (set per navigation in
   pixel-transition.js, so it stays unique). The box travels on a 14-step
   staircase of an ease-out curve (about 40ms a step), so the motion reads as
   pixel frames while staying one continuous move. The card image stays on top
   of the box the whole way (no blank frames if the hero is still loading), and
   the hero resolves over it through a 4x4 ordered dither in 4 frames. The rest of
   the page steps out, then steps in around the image. Firefox and older Safari
   get the JS fallback (overlay clone, see the .pt-ov rules below). */

:root {
  --pt-stair: linear(0 0%, 0.0 3.57%, 0.1993 3.57%, 0.1993 10.71%, 0.3703 10.71%, 0.3703 17.86%, 0.5149 17.86%, 0.5149 25.0%, 0.6356 25.0%, 0.6356 32.14%, 0.7343 32.14%, 0.7343 39.29%, 0.8134 39.29%, 0.8134 46.43%, 0.875 46.43%, 0.875 53.57%, 0.9213 53.57%, 0.9213 60.71%, 0.9544 60.71%, 0.9544 67.86%, 0.9767 67.86%, 0.9767 75.0%, 0.9902 75.0%, 0.9902 82.14%, 0.9971 82.14%, 0.9971 89.29%, 0.9996 89.29%, 0.9996 96.43%, 1.0 96.43%, 1 100%);
  --pt-d4: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' shape-rendering='crispEdges'%3E%3Crect x='0' y='0' width='2' height='2'/%3E%3Crect x='4' y='0' width='2' height='2'/%3E%3Crect x='0' y='4' width='2' height='2'/%3E%3Crect x='4' y='4' width='2' height='2'/%3E%3C/svg%3E");
  --pt-d8: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' shape-rendering='crispEdges'%3E%3Crect x='0' y='0' width='2' height='2'/%3E%3Crect x='4' y='0' width='2' height='2'/%3E%3Crect x='2' y='2' width='2' height='2'/%3E%3Crect x='6' y='2' width='2' height='2'/%3E%3Crect x='0' y='4' width='2' height='2'/%3E%3Crect x='4' y='4' width='2' height='2'/%3E%3Crect x='2' y='6' width='2' height='2'/%3E%3Crect x='6' y='6' width='2' height='2'/%3E%3C/svg%3E");
  --pt-d12: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' shape-rendering='crispEdges'%3E%3Crect x='0' y='0' width='2' height='2'/%3E%3Crect x='2' y='0' width='2' height='2'/%3E%3Crect x='4' y='0' width='2' height='2'/%3E%3Crect x='6' y='0' width='2' height='2'/%3E%3Crect x='2' y='2' width='2' height='2'/%3E%3Crect x='6' y='2' width='2' height='2'/%3E%3Crect x='0' y='4' width='2' height='2'/%3E%3Crect x='2' y='4' width='2' height='2'/%3E%3Crect x='4' y='4' width='2' height='2'/%3E%3Crect x='6' y='4' width='2' height='2'/%3E%3Crect x='2' y='6' width='2' height='2'/%3E%3Crect x='6' y='6' width='2' height='2'/%3E%3C/svg%3E");
  --pt-dur: 560ms;
}

@view-transition {
  navigation: auto;
  types: pt-open;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* --- the shared image --------------------------------------------------- */
html:active-view-transition-type(pt-open)::view-transition-group(pt-hero) {
  animation-duration: var(--pt-dur);
  animation-timing-function: var(--pt-stair);
  z-index: 10;
}
html:active-view-transition-type(pt-open)::view-transition-image-pair(pt-hero) {
  overflow: clip;
}
html:active-view-transition-type(pt-open)::view-transition-old(pt-hero),
html:active-view-transition-type(pt-open)::view-transition-new(pt-hero) {
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  mix-blend-mode: normal;
}
html:active-view-transition-type(pt-open)::view-transition-old(pt-hero) {
  /* Held on top until the dither has filled in, then dropped, so transparent
     card art never shows the other image through it. */
  animation: pt-hold-out var(--pt-dur) steps(1, end) both;
}
@keyframes pt-hold-out {
  0%, 90% { opacity: 1; }
  96%, 100% { opacity: 0; }
}
html:active-view-transition-type(pt-open)::view-transition-new(pt-hero) {
  animation: pt-dither-in var(--pt-dur) steps(1, end) both;
}
@keyframes pt-dither-in {
  0%, 50%  { -webkit-mask: linear-gradient(transparent, transparent); mask: linear-gradient(transparent, transparent); }
  57%      { -webkit-mask: var(--pt-d4) 0 0 / 8px 8px repeat; mask: var(--pt-d4) 0 0 / 8px 8px repeat; }
  71%      { -webkit-mask: var(--pt-d8) 0 0 / 8px 8px repeat; mask: var(--pt-d8) 0 0 / 8px 8px repeat; }
  86%      { -webkit-mask: var(--pt-d12) 0 0 / 8px 8px repeat; mask: var(--pt-d12) 0 0 / 8px 8px repeat; }
  96%, 100% { -webkit-mask: none; mask: none; }
}

/* --- the rest of the page -------------------------------------------------
   Overrides the theme toggle's root rules (pixel-toggle.css), which are meant for
   the same-page theme switch and carry no type. */
html:active-view-transition-type(pt-open)::view-transition-group(root) {
  animation-duration: var(--pt-dur);
}
html:active-view-transition-type(pt-open)::view-transition-old(root) {
  -webkit-mask-image: none;
  mask-image: none;
  animation: pt-root-out 200ms steps(3, end) both;
}
html:active-view-transition-type(pt-open)::view-transition-new(root) {
  -webkit-mask-image: none;
  mask-image: none;
  animation: pt-root-in 320ms steps(4, end) 240ms both;
}
@keyframes pt-root-out { to { opacity: 0; } }
@keyframes pt-root-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* --- fallback: overlay clone --------------------------------------------- */
.pt-ov {
  position: fixed;
  z-index: 2147483000;
  margin: 0;
  object-fit: cover;
  pointer-events: none;
  image-rendering: auto;
}
html.pt-leaving body > * {
  opacity: 0 !important;
  transition: opacity 200ms steps(3, end);
}
html.pt-arriving body > * {
  opacity: 0 !important;
}
html.pt-settle body > * {
  animation: pt-settle-in 320ms steps(4, end) both;
}
@keyframes pt-settle-in { from { opacity: 0; } to { opacity: 1; } }
/* Back to Projects: the case page steps out quicker (the script times the
   home page's settle itself, from 240ms into the move). */
html.pt-leaving.pt-leaving-back body > * {
  transition-duration: 150ms;
}
.pt-ov.pt-ov-out {
  animation: pt-ov-out 160ms steps(1, end) both;
}
@keyframes pt-ov-out {
  0%   { -webkit-mask: var(--pt-d12) 0 0 / 8px 8px repeat; mask: var(--pt-d12) 0 0 / 8px 8px repeat; }
  25%  { -webkit-mask: var(--pt-d8) 0 0 / 8px 8px repeat; mask: var(--pt-d8) 0 0 / 8px 8px repeat; }
  50%  { -webkit-mask: var(--pt-d4) 0 0 / 8px 8px repeat; mask: var(--pt-d4) 0 0 / 8px 8px repeat; }
  75%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html.pt-leaving body > *, html.pt-settle body > * { transition: none; animation: none; }
}
