/* Page-open transitions for the regular site pages. Loaded only with site-motion
   (never on Game Library, game.html or Estate). */

/* Avoid a blank/white frame while the snapshot is held. */
html {
  background-color: var(--paper, #f4efe4);
}
html:has(body.study-page) {
  background-color: var(--study-dusk, #120e0c);
}
::view-transition {
  background-color: inherit;
}

/* Skip the Study boot overlay on a view-transition arrival so the snapshot is the settled room. */
html.page-open-vt-arrival #study-boot {
  display: none !important;
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  /* Site chrome stays put, never scales, and paints above the root snapshot. */
  html[data-site-motion] header.top {
    view-transition-name: vt-header;
  }
  /* The header snaps to the new page's header: a solid bar (so the pages below never
     show through) and no cross-fade (so nav text is never doubled). */
  ::view-transition-group(vt-header) {
    z-index: 10;
    animation: none; /* stay put; never scale or slide */
    background-color: var(--navy, #0e1c36);
  }
  html:has(body.study-page)::view-transition-group(vt-header) {
    background-color: rgb(26, 20, 16);
  }
  ::view-transition-old(vt-header) {
    animation: none;
    opacity: 0;
  }
  ::view-transition-new(vt-header) {
    animation: none;
    opacity: 1;
  }

  /* Tile / study hero morph. Assigned per navigation, never on two live elements at rest. */
  .page-open-hero {
    view-transition-name: vt-hero;
  }
  ::view-transition-group(vt-hero) {
    z-index: 1;
    animation-duration: 260ms;
    animation-timing-function: cubic-bezier(.2, .8, .2, 1);
  }
  /* The hero never comes from the header, nav or footer (page-open.js); header and
     footer links get the plain fade below. */
  /* The arriving page grows as one viewport-tall sheet, not the full scroll height.
     Removed as soon as the transition finishes (all of it sits below the fold). */
  html.page-open-arriving main.page-open-hero {
    max-height: 100vh;
    max-height: 100dvh;
    overflow: clip;
  }
  /* Uneven snapshot fade so the button is not seen stretched to stage size.
     Do not set object-fit; leave the UA default. */
  ::view-transition-old(vt-hero) {
    animation: page-open-hero-old 260ms cubic-bezier(.2, .8, .2, 1) both;
  }
  ::view-transition-new(vt-hero) {
    animation: page-open-hero-new 260ms cubic-bezier(.2, .8, .2, 1) both;
  }
  html.page-open-back::view-transition-old(vt-hero) {
    animation-name: page-open-hero-old-back;
  }
  html.page-open-back::view-transition-new(vt-hero) {
    animation-name: page-open-hero-new-back;
  }

  /* Forward root: old page eases out (200ms I), new page fades in (220ms E, 40ms delay). */
  ::view-transition-old(root) {
    animation: page-open-old 200ms cubic-bezier(.2, 0, 0, 1) both;
  }
  ::view-transition-new(root) {
    animation: page-open-new 220ms cubic-bezier(.2, .8, .2, 1) 40ms both;
  }

  html.page-open-back::view-transition-old(root) {
    animation-name: page-open-old-back;
  }

  /* Header/footer links: root cross-fade only, no grow, 180ms E. */
  html.page-open-plain::view-transition-old(root) {
    animation: page-open-fade-old 180ms cubic-bezier(.2, .8, .2, 1) both;
  }
  html.page-open-plain::view-transition-new(root) {
    animation: page-open-fade-new 180ms cubic-bezier(.2, .8, .2, 1) both;
  }
  html.page-open-plain::view-transition-group(vt-hero) {
    animation: none;
  }
  /* A Back whose source is gone: any leftover old hero fades with the page, never lingers. */
  html.page-open-plain::view-transition-old(vt-hero) {
    animation: page-open-fade-old 180ms cubic-bezier(.2, .8, .2, 1) both;
  }
  html.page-open-plain::view-transition-new(vt-hero) {
    animation: page-open-fade-new 180ms cubic-bezier(.2, .8, .2, 1) both;
  }
}

@keyframes page-open-old {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(.98); }
}
@keyframes page-open-old-back {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.02); }
}
@keyframes page-open-new {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes page-open-fade-old {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes page-open-fade-new {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes page-open-hero-old {
  0% { opacity: 1; }
  6% { opacity: 1; }
  18% { opacity: 0; }
  100% { opacity: 0; }
}
@keyframes page-open-hero-new {
  0% { opacity: 0; }
  4% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 1; }
}
@keyframes page-open-hero-old-back {
  0% { opacity: 1; }
  40% { opacity: 1; }
  80% { opacity: 0; }
  100% { opacity: 0; }
}
@keyframes page-open-hero-new-back {
  0% { opacity: 0; }
  60% { opacity: 0; }
  100% { opacity: 1; }
}
