/* Shared-stage GPU portal shell & cross-document transitions across tools.zzerfu.cn. */

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

/* Prevent subpage entry animations from being snapshotted at opacity: 0 during transitions. */
html.vt-entering .hero,
html.vt-entering .statusbar,
html.vt-entering .panel,
html.vt-settled .hero,
html.vt-settled .statusbar,
html.vt-settled .panel {
  animation: none !important;
}

/* Reserve stable scrollbar gutters everywhere so vertical scrollbars never cause horizontal twitching. */
html:not(.portal-open) {
  scrollbar-gutter: stable;
}

html.portal-open,
html.portal-open body {
  overflow: hidden !important;
  scrollbar-gutter: auto !important;
}

::view-transition {
  background: var(--bg, #f4f6f9);
}

::view-transition-group(root) {
  z-index: 1;
}

::view-transition-group(tool-portal) {
  z-index: 10;
}

:root[data-vt-dir="expand"]::view-transition-group(tool-portal),
:root[data-vt-dir="expand"]::view-transition-group(root) {
  animation-duration: 500ms;
  animation-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
}

:root[data-vt-dir="shrink"]::view-transition-group(tool-portal),
:root[data-vt-dir="shrink"]::view-transition-group(root) {
  animation-duration: 480ms;
  animation-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
}

::view-transition-image-pair(tool-portal) {
  overflow: clip;
  isolation: isolate;
}

:root[data-vt-dir="expand"]::view-transition-image-pair(tool-portal) {
  animation: vt-pair-expand 500ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

:root[data-vt-dir="shrink"]::view-transition-image-pair(tool-portal) {
  animation: vt-pair-shrink 480ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

::view-transition-old(tool-portal),
::view-transition-new(tool-portal) {
  animation: none;
  mix-blend-mode: normal;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: inherit;
  overflow: clip;
}

/* Expand: homepage recedes while the stage expands & cross-morphs gradually into the subpage. */
:root[data-vt-dir="expand"]::view-transition-old(root) {
  animation: vt-root-recede 500ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

:root[data-vt-dir="expand"]::view-transition-old(tool-portal) {
  animation: vt-stage-fade-out 500ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

:root[data-vt-dir="expand"]::view-transition-new(tool-portal) {
  animation: vt-page-fade-in 500ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

/* Shrink: homepage restores around the shrinking subpage back into the stage slot. */
:root[data-vt-dir="shrink"]::view-transition-new(root) {
  animation: vt-root-restore 480ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

:root[data-vt-dir="shrink"]::view-transition-old(tool-portal) {
  animation: vt-page-fade-out 480ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

:root[data-vt-dir="shrink"]::view-transition-new(tool-portal) {
  animation: vt-stage-fade-in 480ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes vt-pair-expand {
  0% {
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(15, 17, 23, 0.18), 0 2px 8px rgba(15, 17, 23, 0.10);
  }
  22% {
    border-radius: 20px;
  }
  100% {
    border-radius: 0px;
    box-shadow: 0 24px 64px rgba(15, 17, 23, 0.08), 0 0 0 rgba(15, 17, 23, 0);
  }
}

@keyframes vt-pair-shrink {
  0% {
    border-radius: 0px;
    box-shadow: 0 24px 64px rgba(15, 17, 23, 0.08), 0 0 0 rgba(15, 17, 23, 0);
  }
  32% {
    border-radius: 20px;
  }
  100% {
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(15, 17, 23, 0.14), 0 2px 8px rgba(15, 17, 23, 0.08);
  }
}

@keyframes vt-root-recede {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0.42;
    transform: scale(0.978);
  }
}

@keyframes vt-root-restore {
  from {
    opacity: 0.45;
    transform: scale(0.978);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes vt-stage-fade-out {
  0% { opacity: 1; }
  16% { opacity: 0.86; }
  56% { opacity: 0.26; }
  86%, 100% { opacity: 0; }
}

@keyframes vt-page-fade-in {
  0% { opacity: 0.16; }
  48% { opacity: 0.82; }
  86%, 100% { opacity: 1; }
}

@keyframes vt-page-fade-out {
  0% { opacity: 1; }
  30% { opacity: 0.86; }
  86%, 100% { opacity: 0; }
}

@keyframes vt-stage-fade-in {
  0% { opacity: 0; }
  16% { opacity: 0.10; }
  58% { opacity: 0.74; }
  86%, 100% { opacity: 1; }
}

/* Same-document GPU Portal Shell (cross-browser expand/shrink over live subpage iframe). */
.portal-home-recede {
  transform-origin: center 35vh;
  will-change: transform, opacity;
}

.portal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  pointer-events: none;
  background: rgba(15, 17, 23, 0.30);
  opacity: 0;
  will-change: opacity;
}

[data-theme="dark"] .portal-backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.portal-shell {
  position: fixed;
  z-index: 901;
  overflow: clip;
  background: var(--bg, #f4f6f9);
  box-shadow: 0 24px 68px rgba(15, 17, 23, 0.26), 0 4px 16px rgba(15, 17, 23, 0.12);
  will-change: left, top, width, height, border-radius;
}

.portal-shell.is-settled {
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.portal-frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  transform-origin: 0 0;
  background: var(--bg, #f4f6f9);
  will-change: transform, opacity;
}

.portal-shell.is-settled .portal-frame {
  width: 100%;
  height: 100%;
  transform: none !important;
  opacity: 1 !important;
}

.portal-cover {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  transform-origin: 0 0;
  overflow: hidden;
  will-change: transform, opacity, filter;
}

.portal-cover > .portal-stage-clone {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
  border-radius: 0 !important;
  transform: none !important;
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .portal-backdrop,
  .portal-shell {
    display: none !important;
  }
}
