/* Motion: on a computer a project opens the way Jason Yuan's do. The picture you click flies out of
   the grid into the project on a spring, the page behind goes soft under the white blur, and the
   words follow. Closing flies it back. On a phone a project just swaps in. Pictures arrive on a
   soft grey card that breathes, then fade in. Pages load straight away; the pill you tapped eases
   back into place as the new one appears. With reduced motion, none of it. */

:root {
  --soft-out: cubic-bezier(0.23, 1, 0.32, 1);
  /* A spring, sampled: it barely overshoots (3%) and settles. It starts moving at once, so a tap
     never waits. */
  --fly: linear(0, 0.036, 0.123, 0.239, 0.365, 0.489, 0.604, 0.705, 0.79, 0.86, 0.914, 0.955, 0.985, 1.005, 1.018, 1.025, 1.028, 1.028, 1.026, 1.023, 1.02, 1.016, 1.013, 1.01, 1.007, 1.005, 1.003, 1.002, 1.001, 1, 1, 0.999, 1);
}

/* --- A project ----------------------------------------------------------------------------- */

/* The picture in flight: a copy over the work (focus.js animates it on --fly) and under the top
   bar and the dock. The work fades in beneath it with its own fade and its real blur. */
.f-ghost {
  z-index: 440;
  pointer-events: none;
  will-change: transform, clip-path;
}

/* The words follow the picture, one line after another, then the rest of the pictures. */
.e-proj.is-arriving .e-proj__text > *,
.e-proj.is-arriving .e-proj__media > :not(:first-child) {
  animation: arrive 560ms var(--soft-out) both;
  animation-delay: calc(80ms + var(--n, 6) * 40ms);
}

.e-proj.is-arriving .e-proj__text > :nth-child(1) { --n: 0; }
.e-proj.is-arriving .e-proj__text > :nth-child(2) { --n: 1; }
.e-proj.is-arriving .e-proj__text > :nth-child(3) { --n: 2; }
.e-proj.is-arriving .e-proj__text > :nth-child(4) { --n: 3; }
.e-proj.is-arriving .e-proj__text > :nth-child(5) { --n: 4; }

@keyframes arrive { from { opacity: 0; transform: translateY(12px); } }

.f-focus.is-closing { transition: opacity 200ms cubic-bezier(0.215, 0.61, 0.355, 1); }

/* On a phone a project swaps in and out at once, like a screen in an app. */
@media (max-width: 900px) {
  .page-s .f-focus { animation: none; }
  .page-s .f-focus.is-closing { transition: none; }
}

/* --- Moving between pages ------------------------------------------------------------------ */

/* Pages load straight away (the browser readies them while a finger or pointer heads for a link).
   The pill you tapped eases back up from a press as the page it opens appears: no bounce. */
[data-tap="home"] .o-top .e-name,
[data-tap="work"] :is(.o-top, .r-dock) a[href$="/work"],
[data-tap="about"] :is(.o-top, .r-dock) a[href$="/about"] { animation: settle 280ms var(--soft-out); }

@keyframes settle { from { scale: 0.94; } }

/* --- Pictures ------------------------------------------------------------------------------- */

/* Only boxes that hold a picture; the "soon" tiles keep their plain grey. Cut-outs need the card to
   go once they're in, so it fades rather than stays. */
.reveal .media:has(> img, > video)::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-color: var(--surface);
  animation: breathe 1600ms ease-in-out infinite alternate;
  transition: background-color 300ms var(--soft-out);
}

.reveal .media.is-loaded::before { background-color: transparent; animation-play-state: paused; }
.reveal .media.is-instant::before { transition: none; }

.reveal .media:not(.is-loaded) > img,
.reveal .media:not(.is-loaded) > video { opacity: 0; }

.reveal .media.is-loaded:not(.is-instant) > img,
.reveal .media.is-loaded:not(.is-instant) > video { animation: picture-in 500ms cubic-bezier(0.33, 0, 0.2, 1); }

@keyframes breathe { from { opacity: 0.6; } }
@keyframes picture-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .e-proj.is-arriving .e-proj__text > *,
  .e-proj.is-arriving .e-proj__media > *,
  [data-tap] a { animation: none !important; }
}
