/* The scene remains connected while only the foreground changes pages. */
html[data-cosmic-scene] body { isolation: isolate; }
#page-shell { position: relative; isolation: isolate; min-height: 100vh; }
#page-shell main [tabindex="-1"]:focus { outline: none; }
#cosmic-stage {
  position: fixed;
  left: 0;
  width: 100%;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
  background: #0a0a0a;
  mask-image: linear-gradient(#000 72%, transparent 100%);
}
#cosmic-stage[data-visible="false"] { visibility: hidden; }
#cosmic-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 35%;
  transform: scale(1.015);
}
html[data-cosmic-scene] :is(.hero-video, .footer-video, .hero-atmosphere) { visibility: hidden; }
html[data-page-transition] #cosmic-stage {
  visibility: visible;
  transition: top 700ms cubic-bezier(0.16, 1, 0.3, 1), height 700ms cubic-bezier(0.16, 1, 0.3, 1);
}
html[data-page-transition] #cosmic-stage video { transition: transform 850ms cubic-bezier(0.16, 1, 0.3, 1); }
html[data-page-transition="leaving"] #cosmic-stage video { transform: scale(1.075); }
html[data-page-transition]::before,
html[data-page-transition]::after { content: ""; position: fixed; pointer-events: none; }
html[data-page-transition]::before {
  inset: 0;
  z-index: 10000;
  background: radial-gradient(ellipse at var(--transition-x, 50%) var(--transition-y, 45%), rgba(137, 170, 204, 0.16), rgba(8, 11, 16, 0.24) 65%);
}
html[data-page-transition]::after {
  z-index: 10001;
  left: var(--transition-x, 50%);
  top: var(--transition-y, 45%);
  width: 90vmax;
  height: 90vmax;
  margin: -45vmax;
  border: 1px solid rgba(185, 222, 255, 0.65);
  border-radius: 50%;
  box-shadow: 0 0 28px rgba(137, 170, 204, 0.3), 0 0 100px rgba(78, 133, 191, 0.2), inset 0 0 36px rgba(137, 170, 204, 0.18);
  /* Keep the same animation through both phases; arrival must not restart the ring. */
  animation: portal-ring-out 560ms cubic-bezier(0.7, 0, 0.2, 1) both;
}
html[data-page-transition="leaving"] { cursor: progress; }
html[data-page-transition="leaving"]::before { animation: scene-glow-in 560ms ease both; }
html[data-page-transition="leaving"] #page-shell { animation: foreground-out 560ms ease both; }
html[data-page-transition="arriving"]::before { animation: scene-glow-out 700ms ease both; }
html[data-page-transition="arriving"] #page-shell { animation: foreground-in 650ms ease both; }
html[data-page-transition="arriving"] :is(.hero-content, .hero-copy) { animation: portal-copy-in 850ms cubic-bezier(0.16, 1, 0.3, 1) both; }
html[data-page-transition="arriving"] .hero-scene { animation: portal-scene-in 950ms cubic-bezier(0.16, 1, 0.3, 1) both; }
html[data-page-transition="arriving"] :is(.site-header, .header) { animation: portal-header-in 600ms 100ms cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes scene-glow-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scene-glow-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes portal-ring-out { from { opacity: 0.9; transform: scale(0.02); } to { opacity: 0; transform: scale(3.4); } }
@keyframes foreground-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes foreground-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes portal-copy-in { from { opacity: 0; transform: translateY(28px); filter: blur(6px); } to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes portal-scene-in { from { opacity: 0; transform: translate(36px, 16px) scale(0.97); } to { opacity: 1; transform: translateY(-8px) scale(1); } }
@keyframes portal-header-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html[data-page-transition]::before, html[data-page-transition]::after { display: none; }
  html[data-page-transition] #page-shell,
  html[data-page-transition] :is(.hero-content, .hero-copy, .hero-scene, .site-header, .header) { animation: none; }
  html[data-page-transition] #cosmic-stage { transition: none; }
  html[data-page-transition] #cosmic-stage video { transition: none; transform: scale(1.015); }
}
