/*
 * Page transition between the home page and the game: the footer's game link
 * grows into the game frame, and the frame shrinks back into it on the way
 * home when that link is on screen. Both pages opt in to cross-document view
 * transitions (Chrome and Edge 126+, Safari 18.2+); other browsers and reduced
 * motion keep the instant switch. game-transition.js skips the transition for
 * the other navigations between these pages (the language switch, the logo)
 * and lets the frame simply fade when the home page opens at the top.
 *
 * The page being opened styles the motion: body[data-page="game"] on the way
 * in, body[data-page="home"] on the way back.
 */
@view-transition {
  navigation: auto;
}

body[data-page="game"] .game,
.site-footer [data-footer-game] {
  view-transition-name: game-frame;
}

::view-transition-old(root) {
  animation: 220ms cubic-bezier(.4, 0, 1, 1) both tx-fade-out;
}

::view-transition-new(root) {
  animation: 300ms cubic-bezier(0, 0, .2, 1) 160ms both tx-fade-in;
}

::view-transition-group(game-frame) {
  animation-duration: 520ms;
  animation-timing-function: cubic-bezier(.2, 0, 0, 1);
}

::view-transition-image-pair(game-frame) {
  overflow: clip;
  border-radius: 22px;
}

/* The frame fills the growing layer from the top; the link keeps its size. */
::view-transition-old(game-frame),
::view-transition-new(game-frame) {
  height: 100%;
  object-fit: cover;
  object-position: 50% 0;
}

html:has(> body[data-page="game"])::view-transition-old(game-frame),
html:has(> body[data-page="home"])::view-transition-new(game-frame) {
  width: auto;
  height: auto;
  object-fit: fill;
}

/* Home to game: the link's label goes at once and the frame shows. */
html:has(> body[data-page="game"])::view-transition-old(game-frame) {
  animation: 90ms linear both tx-fade-out;
}

html:has(> body[data-page="game"])::view-transition-new(game-frame) {
  animation: 160ms linear 40ms both tx-fade-in;
}

/* Game to home: the frame fades into the link near the end. */
html:has(> body[data-page="home"])::view-transition-old(game-frame) {
  animation: 200ms linear 260ms both tx-fade-out;
}

html:has(> body[data-page="home"])::view-transition-new(game-frame) {
  animation: 160ms linear 320ms both tx-fade-in;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

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

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

