/* PoMiniGames Motion & Reduced-Motion Tokens (Rule 5) */
/* ── Reduce motion (single source of truth) ─────────────────────────────────
   `data-motion="reduce"` is set when EITHER the user opted in (Profile →
   Preferences) OR the OS asks for reduced motion. Both are resolved to this one
   attribute by the pre-paint script in index.html and kept live by appPrefs.js,
   mirroring how `data-theme` resolves `prefers-color-scheme`. Resolving in JS is
   what lets the two sources share one rule instead of needing a duplicate
   `@media (prefers-reduced-motion)` copy of every declaration below — see the
   note at the foot of this file.

   Collapsing the motion tokens is most of the job, since animated components
   read their timing from them. The blanket rule catches the hand-rolled keyframe
   animations that predate the tokens. `!important` is load-bearing: it has to
   beat per-component scoped-CSS animation declarations it knows nothing about. */
:root[data-motion="reduce"] {
  --dur-fast: 0s;
  --dur-base: 0s;
  --dur-slow: 0s;
  --dur-spring: 0s;
}

:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
  scroll-behavior: auto !important;
}
:root[data-motion="reduce"] .skeleton {
  animation: none !important;
}

/* Cross-document navigation transition — uses the browser's native
   View Transitions API where supported (Chrome/Edge 111+). */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--dur-fast);
  animation-timing-function: var(--ease-standard);
}

/* Card-to-game morph. js/app.js names the pressed hub card's heading `po-hero` and, once the
   router has swapped the page in place, the game's title in the top bar, so the card's icon
   and title travel into the title instead of cross-fading with the page. */

::view-transition-group(po-hero) {
  animation-duration: 420ms;
  animation-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1);
}
:root[data-motion='reduce']::view-transition-group(po-hero),
:root[data-motion='reduce']::view-transition-old(po-hero),
:root[data-motion='reduce']::view-transition-new(po-hero) {
  animation: none;
}

/* Shared launch choreography (deck idea #18). js/platform/app.js names the top bar `po-hud`
   for the length of a hub launch, so the one HUD surface both pages share holds still
   instead of cross-fading with itself, and sets data-hero-dir so the new page wipes in from
   the edge nearest the pressed card while that card flies into the title. Reduced motion and
   browsers without the API never get here: PoHubNav navigates instantly. */
::view-transition-group(po-hud) {
  animation: none;
}
::view-transition-old(po-hud) {
  display: none;
}
::view-transition-new(po-hud) {
  animation: none;
}

:root[data-hero-nav]::view-transition-new(root) {
  animation: po-route-edge-ltr 420ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
:root[data-hero-nav][data-hero-dir='rtl']::view-transition-new(root) {
  animation-name: po-route-edge-rtl;
}
:root[data-hero-nav]::view-transition-old(root) {
  animation: po-route-edge-out 420ms ease-in both;
}

@keyframes po-route-edge-ltr {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
@keyframes po-route-edge-rtl {
  from { clip-path: inset(0 0 0 100%); }
  to { clip-path: inset(0 0 0 0); }
}
@keyframes po-route-edge-out {
  from { opacity: 1; }
  to { opacity: 0.55; }
}

:root[data-motion='reduce'][data-hero-nav]::view-transition-new(root),
:root[data-motion='reduce'][data-hero-nav]::view-transition-old(root) {
  animation: none;
}

/* a11y: honour reduced-motion for the cross-document transition too — the
   root cross-fade is motion the user opted out of. Skipping the animation makes
   the swap instant (the API still no-ops gracefully where unsupported). */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }}

/* ── PoRacer results reveal ──────────────────────────────────────────────
   js/poracer/index.js `reveal` puts `racer-vt` on <html> for the length of one View
   Transition: the zoomed-out circuit falls back and dims while the results dialog rises
   in over it. Global because ::view-transition-* hang off the root, out of reach of a
   component's scoped stylesheet. */
html.racer-vt::view-transition-old(root) {
  animation: racer-vt-out 0.34s ease-in both;
}

html.racer-vt::view-transition-new(root) {
  animation: racer-vt-in 0.52s cubic-bezier(0.2, 0.9, 0.3, 1.05) both;
  clip-path: inset(0 0 0 0);
}

@keyframes racer-vt-out {
  to { opacity: 0; transform: scale(0.965); filter: blur(2px); }
}

/* The results arrive as a wipe up from the bottom rather than a fade: the race falls back
   underneath while the sheet rises over the part of it it replaces. */
@keyframes racer-vt-in {
  from { opacity: 0; clip-path: inset(100% 0 0 0); transform: translateY(10px) scale(0.985); }
  to { opacity: 1; clip-path: inset(0 0 0 0); }
}
