/* Gateway ambience follows the player's saved preference while its control is hidden. */
.welcome-page #welcome-motion[hidden] {
  display: none;
}

/* Same-origin document navigation. The browser still owns links, history and focus. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  ::view-transition {
    pointer-events: none;
  }

  ::view-transition-group(root) {
    animation-duration: 340ms;
  }

  ::view-transition-old(root) {
    animation: 340ms ease-out both zvsp-document-leave;
    mix-blend-mode: normal;
  }

  ::view-transition-new(root) {
    animation: 340ms cubic-bezier(.2, .7, .25, 1) both zvsp-document-enter;
    mix-blend-mode: normal;
  }

  /* Keep the phone transition opacity-only, including on coarse tablets. */
  @media (min-width: 901px) and (hover: hover) and (pointer: fine) {
    :root:not(.world-gateway-root):not(:has(#zvp-welcome[open]))::view-transition-new(root) {
      animation-name: zvsp-document-enter-desktop;
    }
  }

  /* Reveal the loaded page under both the welcome and its backdrop. */
  .nf-body #zvp-welcome[open].zvp-welcome-from-world:not(.is-leaving) {
    animation: zvsp-welcome-arrive 360ms ease-out both !important;
  }

  .nf-body #zvp-welcome[open].is-leaving {
    animation: zvsp-welcome-dismiss 380ms cubic-bezier(.23, .68, .29, 1) both !important;
  }

  .nf-body #zvp-welcome[open].is-leaving::backdrop {
    animation: zvsp-welcome-dismiss 380ms cubic-bezier(.23, .68, .29, 1) both;
  }

  /* Direct links and browsers that skip the document snapshot still get an entrance. */
  .china-world body.china-portal > #main {
    animation: 340ms ease-out both zvsp-page-enter;
  }

  @media (max-width: 900px), (hover: none), (pointer: coarse) {
    .nf-body:not(.zvp-welcome-seen, .zvp-welcome-open) #home.active .nf-hero-copy {
      animation: 340ms ease-out both zvsp-page-enter;
    }
  }

  /* Start with the scenery, then reveal the heading and description. Links and
     controls stay outside the sequence so the page can be used straight away. */
  :root:not([data-zvsp-scene="done"]) :is(
    .welcome-page .welcome-scenes,
    .china-portal [data-page="home"].is-active .hero-portrait-stage,
    .nf-body:not(.zvp-welcome-seen, .zvp-welcome-open) #home.active .zvp-city-depth.far
  ) {
    animation: 240ms ease-out both zvsp-scene-enter;
    animation-play-state: var(--zvsp-scene-state, running);
  }

  :root:not([data-zvsp-scene="done"]) .nf-body #zvp-welcome[open] .zvp-welcome-video-scene::after {
    position: absolute;
    inset: 0;
    background: #071025;
    content: "";
    pointer-events: none;
    animation: 240ms ease-out both zvsp-scene-uncover;
    animation-play-state: var(--zvsp-scene-state, running);
  }

  :root:not([data-zvsp-scene="done"]) :is(
    .china-portal [data-page="home"].is-active .hero-copy > :is(.eyebrow, h1, p:first-of-type),
    .nf-body:not(.zvp-welcome-seen, .zvp-welcome-open) #home.active .nf-hero-copy > :is(h1, p),
    .nf-body #zvp-welcome[open] .zvp-entry-greeting
  ) {
    animation: 430ms cubic-bezier(.2, .7, .25, 1) 190ms both zvsp-copy-enter;
    animation-play-state: var(--zvsp-scene-state, running);
  }

  :root:not([data-zvsp-scene="done"]) :is(
    .china-portal [data-page="home"].is-active .hero-copy > p:first-of-type,
    .nf-body:not(.zvp-welcome-seen, .zvp-welcome-open) #home.active .nf-hero-copy > p
  ) {
    animation-delay: 260ms;
  }

  /* Let the wordmark and supporting copy enter in distinct beats. The
     links keep their existing hit areas and remain readable during the fade. */
  :root:not([data-zvsp-scene="done"]) .welcome-page :is(
    .welcome-header-label, .welcome-kicker, .welcome-title, .welcome-subtitle,
    .welcome-world, .welcome-entry-copy, .welcome-entry-note, .welcome-footer > span
  ) {
    animation: 460ms cubic-bezier(.2, .7, .25, 1) var(--zvsp-gateway-delay, 190ms) both zvsp-gateway-copy;
    animation-play-state: var(--zvsp-scene-state, running);
  }

  :root:not([data-zvsp-scene="done"]) .welcome-page :is(
    .welcome-brand, .welcome-actions > a, .welcome-scene-controls > button, .welcome-footer > a
  ) {
    animation: 380ms ease-out var(--zvsp-gateway-delay, 0ms) both zvsp-gateway-control;
    animation-play-state: var(--zvsp-scene-state, running);
  }

  :root:not([data-zvsp-scene="done"]) .welcome-page :is(
    .welcome-brand, .welcome-actions > a, .welcome-scene-controls > button, .welcome-footer > a
  ):focus-visible {
    animation: none;
  }

  .welcome-page .welcome-title { --zvsp-gateway-delay: 250ms; }
  .welcome-page .welcome-subtitle { --zvsp-gateway-delay: 325ms; }
  .welcome-page .welcome-world { --zvsp-gateway-delay: 400ms; }
  .welcome-page .welcome-entry-copy { --zvsp-gateway-delay: 470ms; }
  .welcome-page .welcome-primary { --zvsp-gateway-delay: 520ms; }
  .welcome-page .welcome-secondary { --zvsp-gateway-delay: 565ms; }
  .welcome-page .welcome-entry-note { --zvsp-gateway-delay: 625ms; }
  .welcome-page .scene-choice { --zvsp-gateway-delay: 680ms; }
  .welcome-page .scene-choice + .scene-choice { --zvsp-gateway-delay: 725ms; }
  .welcome-page .welcome-footer { --zvsp-gateway-delay: 780ms; }

  @media (min-width: 901px) and (hover: hover) and (pointer: fine) {
    .welcome-page { --zvsp-gateway-rise: 0 7px; }
  }

  :root[data-zvsp-scene="waiting"] {
    --zvsp-scene-state: paused;
  }

  /* A first-time welcome keeps its full artwork and the Enter button.
     Use that hero's own greeting for the second stage. */
  :root .nf-body #zvp-welcome[open] .zvp-entry-logo {
    display: none;
  }

  :root[data-zvsp-scene="done"] .nf-body #zvp-welcome[open] .zvp-entry-greeting {
    animation: none;
  }

  .nf-body #account.active :is(#login-form, #register-form, #email-code-form, #account-user):not([hidden]),
  .cso-account-page main > :is(#login, #register, #recover, #profile):not([hidden]) {
    animation: 250ms ease-out both zvsp-account-enter;
  }
}

@keyframes zvsp-document-leave {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes zvsp-document-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes zvsp-document-enter-desktop {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

@keyframes zvsp-scene-enter {
  from { opacity: .68; }
}

@keyframes zvsp-scene-uncover {
  from { opacity: .32; }
  to { opacity: 0; }
}

@keyframes zvsp-copy-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes zvsp-gateway-copy {
  from { opacity: 0; translate: var(--zvsp-gateway-rise, none); }
  to { opacity: 1; translate: none; }
}

@keyframes zvsp-gateway-control {
  from { opacity: .64; }
  to { opacity: 1; }
}

@keyframes zvsp-account-enter {
  from { opacity: .72; }
  to { opacity: 1; }
}

@keyframes zvsp-page-enter {
  from { opacity: .64; }
  to { opacity: 1; }
}

/* Keep a classic scrollbar's space while the welcome locks scrolling. */
:root:has(> .nf-body.zvp-welcome-seen) {
  scrollbar-gutter: stable;
}

@keyframes zvsp-welcome-arrive {
  from { opacity: .68; }
  to { opacity: 1; }
}

@keyframes zvsp-welcome-dismiss {
  from { opacity: var(--zvsp-welcome-opacity, 1); }
  to { opacity: 0; }
}
