/*
 * Galactic Empires celestial motion system.
 *
 * The source PNG remains in the DOM as the accessible/static fallback. JavaScript
 * adds a canvas only for spherical axial motion and layers only the approved solar
 * and wormhole effects. Ownership, selection, shield, and map overlays are not
 * matched by the enhancer.
 */

.ge-celestial {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  max-width: none;
  max-height: none;
  line-height: 0;
  vertical-align: middle;
  isolation: isolate;
  transform-origin: center;
}

/* Rotated mobile maps use independent X/Y scaling; cancel that anisotropy so
 * enhanced spherical bodies remain circular after their counter-rotation. */
.ge-mobile-map-rotate .ge-celestial.ge-mobile-map-counter {
  transform: rotate(-90deg) scaleX(var(--ge-map-counter-scale-x, 1)) !important;
}

.ge-celestial-background-host {
  display: inline-grid;
  place-items: center;
}

.ge-celestial-background-host > .ge-celestial {
  grid-area: 1 / 1;
}

.ge-celestial > .ge-celestial__source,
.ge-celestial > .ge-celestial__canvas,
.ge-celestial > .ge-celestial__wormhole-layer {
  grid-area: 1 / 1;
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  object-fit: contain;
  transform-origin: center;
}

.ge-celestial__source {
  opacity: 1;
}

.ge-celestial--axial.ge-celestial--ready > .ge-celestial__source {
  opacity: 0;
}

.ge-celestial__canvas {
  z-index: 2;
  pointer-events: none;
}

.ge-celestial--planet .ge-celestial__canvas {
  width: var(--ge-planet-core-size, 100%) !important;
  height: var(--ge-planet-core-size, 100%) !important;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.58));
}

.ge-celestial--planet {
  overflow: visible;
}

.ge-celestial__orbit-scene {
  position: absolute;
  inset: 0;
  z-index: auto;
  display: block;
  overflow: visible;
  pointer-events: none;
}

.ge-celestial__orbit-track {
  position: absolute;
  inset: var(--ge-orbit-inset, -10%);
  z-index: 3;
  display: block;
  border-radius: 50%;
  animation:
    ge-development-orbit var(--ge-orbit-duration, 28s) linear var(--ge-orbit-delay, 0s) infinite,
    ge-development-orbit-depth var(--ge-orbit-duration, 28s) step-end var(--ge-orbit-delay, 0s) infinite;
  will-change: transform;
}

.ge-celestial__orbit-track--reverse {
  animation-direction: reverse, reverse;
}

.ge-celestial__orbiter {
  position: absolute;
  top: 50%;
  left: 100%;
  z-index: 1;
  display: block;
  width: 8%;
  min-width: 2px;
  max-width: 5px;
  height: 5%;
  min-height: 1px;
  max-height: 3px;
  background: #d7e6ea;
  box-shadow: 0 0 3px rgba(105, 224, 255, 0.88);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.85));
  transform: translate(-50%, -50%) scale(var(--ge-orbiter-scale, 1));
}

.ge-celestial__orbiter--satellite {
  width: 4%;
  min-width: 2px;
  max-width: 3px;
  height: 7%;
  min-height: 2px;
  max-height: 4px;
  border-radius: 1px;
  background: #e7f5f7;
}

.ge-celestial__orbiter--satellite::before,
.ge-celestial__orbiter--satellite::after {
  position: absolute;
  top: 25%;
  width: 125%;
  height: 50%;
  content: "";
  background: #3da4c6;
  box-shadow: inset 0 0 0 1px rgba(205, 248, 255, 0.42);
}

.ge-celestial__orbiter--satellite::before { right: 115%; }
.ge-celestial__orbiter--satellite::after { left: 115%; }

.ge-celestial__orbiter--shuttle {
  border-radius: 70% 18% 18% 70%;
  background: linear-gradient(90deg, #f1f7f5 0 58%, #63d7ff 60% 100%);
}

.ge-celestial__orbiter--station {
  width: 8%;
  min-width: 3px;
  max-width: 5px;
  height: 8%;
  min-height: 3px;
  max-height: 5px;
  border: 1px solid rgba(215, 239, 242, 0.92);
  border-radius: 50%;
  background: radial-gradient(circle, #8fe8ff 0 22%, #263f4a 28% 55%, #d7e6ea 60% 72%, transparent 76%);
  box-shadow: 0 0 4px rgba(105, 224, 255, 0.72);
}

.ge-celestial__orbiter--station::after {
  position: absolute;
  top: 45%;
  left: -55%;
  width: 210%;
  height: 1px;
  content: "";
  background: rgba(215, 239, 242, 0.82);
  rotate: -22deg;
}

.ge-celestial__orbiter--ship {
  width: 10%;
  min-width: 3px;
  max-width: 6px;
  height: 7%;
  min-height: 2px;
  max-height: 4px;
  clip-path: polygon(0 50%, 72% 0, 100% 50%, 72% 100%);
  background: linear-gradient(90deg, #53d8ff 0 18%, #eef8f6 26% 100%);
  box-shadow: none;
  filter: drop-shadow(-2px 0 2px rgba(54, 209, 255, 0.86)) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.9));
}

.ge-celestial--paused .ge-celestial__orbit-track {
  animation-play-state: paused !important;
}

.ge-celestial--asteroid {
  animation: none !important;
}

.ge-celestial--asteroid img {
  animation: none !important;
}

/* Solar palettes are sampled from the production PNG families. */
.ge-celestial--sun {
  --ge-solar-flare-rgb: 255, 137, 58;
  --ge-solar-hot-rgb: 255, 229, 150;
  --ge-solar-glow-rgb: 255, 94, 45;
  --ge-solar-glow-opacity: 0.62;
  --ge-solar-pulse-scale: 1.045;
  --ge-solar-prominence-speed: 4.6s;
  --ge-sun-core-size: 100%;
  --ge-sun-glow-size: 92%;
  --ge-sun-visual-scale: 1;
}

.ge-celestial--sun-1 {
  --ge-solar-flare-rgb: 250, 83, 255;
  --ge-solar-hot-rgb: 255, 205, 255;
  --ge-solar-glow-rgb: 201, 71, 255;
}

.ge-celestial--sun-2 {
  --ge-solar-flare-rgb: 255, 82, 42;
  --ge-solar-hot-rgb: 255, 224, 142;
  --ge-solar-glow-rgb: 255, 49, 67;
}

.ge-celestial--sun-3 {
  --ge-solar-flare-rgb: 58, 211, 255;
  --ge-solar-hot-rgb: 207, 252, 255;
  --ge-solar-glow-rgb: 38, 139, 255;
}

.ge-celestial--sun-4 {
  --ge-solar-flare-rgb: 255, 167, 43;
  --ge-solar-hot-rgb: 255, 240, 156;
  --ge-solar-glow-rgb: 255, 112, 32;
}

.ge-celestial--sun::before {
  position: absolute;
  inset: 4%;
  z-index: 0;
  border-radius: 50%;
  content: "";
  opacity: var(--ge-solar-glow-opacity);
  background: radial-gradient(
    circle,
    rgba(var(--ge-solar-hot-rgb), 0.58) 0 29%,
    rgba(var(--ge-solar-flare-rgb), 0.28) 48%,
    rgba(var(--ge-solar-glow-rgb), 0.08) 66%,
    transparent 76%
  );
  filter: blur(7px);
  pointer-events: none;
  animation: ge-solar-breathe 4.8s ease-in-out infinite;
}

.ge-celestial--sun-tiny::before {
  inset: 8%;
  filter: blur(2px);
  animation: none;
}

.ge-celestial--sun-full::before {
  inset: auto;
  top: 50%;
  left: 50%;
  width: var(--ge-sun-glow-size);
  height: var(--ge-sun-glow-size);
  translate: -50% -50%;
}

.ge-celestial--sun-full > .ge-celestial__source,
.ge-celestial--sun-full > .ge-celestial__canvas {
  width: var(--ge-sun-core-size) !important;
  height: var(--ge-sun-core-size) !important;
}

.ge-celestial--sun .ge-celestial__canvas {
  z-index: 2;
  opacity: 0.94;
  rotate: var(--ge-axis-tilt, 0deg);
  filter: drop-shadow(0 0 5px rgba(var(--ge-solar-glow-rgb), 0.52));
  animation: ge-solar-surface-fire 1.8s steps(12, end) infinite;
}

/* Sector-map suns keep axial motion without a luminosity/size pulse. */
.ge-celestial--sun-tiny .ge-celestial__canvas {
  animation: none;
}

.ge-solar-prominences {
  position: absolute;
  inset: -16%;
  z-index: 1;
  border-radius: 50%;
  scale: var(--ge-sun-visual-scale);
  pointer-events: none;
}

.ge-solar-prominence {
  position: absolute;
  inset: 0;
  rotate: var(--ge-flare-angle);
}

.ge-solar-prominence::before {
  position: absolute;
  top: -1%;
  left: 50%;
  width: var(--ge-flare-width);
  height: var(--ge-flare-height);
  border-radius: 52% 48% 16% 20% / 84% 72% 28% 16%;
  content: "";
  opacity: 0.28;
  background: linear-gradient(
    to top,
    rgba(var(--ge-solar-flare-rgb), 0.94),
    rgba(var(--ge-solar-hot-rgb), 0.68) 38%,
    rgba(var(--ge-solar-hot-rgb), 0.26) 67%,
    transparent 100%
  );
  filter: blur(1.25px) drop-shadow(0 0 4px rgba(var(--ge-solar-glow-rgb), 0.62));
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  animation: ge-solar-prominence var(--ge-solar-prominence-speed) steps(9, end) var(--ge-flare-delay) infinite;
}

.ge-solar-prominence::after {
  position: absolute;
  top: 7%;
  left: 50%;
  width: var(--ge-loop-width);
  height: var(--ge-loop-height);
  border: 1.5px solid rgba(var(--ge-solar-flare-rgb), 0.78);
  border-bottom-color: transparent;
  border-radius: 55% 55% 16% 16%;
  content: "";
  opacity: 0.28;
  filter: blur(0.65px) drop-shadow(0 0 3px rgba(var(--ge-solar-glow-rgb), 0.68));
  transform: translateX(-50%) rotate(var(--ge-loop-tilt)) scale(0.72);
  transform-origin: 50% 100%;
  animation: ge-solar-loop-flare var(--ge-solar-prominence-speed) ease-in-out var(--ge-flare-delay) infinite;
}

.ge-solar-prominence:nth-child(even)::after {
  display: none;
}

/* Wormholes keep the approved counterflow but intentionally have no outer pulse ring. */
.ge-celestial--wormhole {
  --ge-wormhole-outer-speed: 11s;
  --ge-wormhole-inner-speed: 7.2s;
  --ge-wormhole-depth-speed: 4.9s;
  --ge-wormhole-infall-speed: 3.2s;
  --ge-wormhole-pulse-speed: 3.8s;
  --ge-wormhole-energy: 0.7;
}

.ge-celestial--wormhole > .ge-celestial__source {
  z-index: 3;
  opacity: 1;
  filter: saturate(1.1) contrast(1.05) drop-shadow(0 0 7px rgba(53, 200, 255, 0.48));
  animation: ge-wormhole-spin-forward var(--ge-wormhole-outer-speed) linear infinite;
}

.ge-celestial__wormhole-layer {
  pointer-events: none;
}

.ge-celestial__wormhole-layer--inner {
  z-index: 4;
  width: 78% !important;
  height: 78% !important;
  opacity: 0.72;
  filter: saturate(1.5) brightness(1.12) contrast(1.16);
  mix-blend-mode: screen;
  animation:
    ge-wormhole-spin-reverse var(--ge-wormhole-inner-speed) linear infinite,
    ge-wormhole-layer-pulse var(--ge-wormhole-pulse-speed) ease-in-out infinite;
}

.ge-celestial__wormhole-layer--depth {
  z-index: 5;
  width: 57% !important;
  height: 57% !important;
  opacity: 0.64;
  filter: saturate(1.8) brightness(0.72) contrast(1.3);
  animation:
    ge-wormhole-spin-forward var(--ge-wormhole-depth-speed) linear infinite,
    ge-wormhole-depth-dive var(--ge-wormhole-infall-speed) ease-in-out infinite;
}

.ge-celestial__wormhole-infall {
  position: absolute;
  inset: 8%;
  z-index: 6;
  border: 1px solid rgba(114, 230, 255, 0.52);
  border-radius: 50%;
  opacity: 0;
  box-shadow: 0 0 6px rgba(50, 199, 255, 0.3);
  animation: ge-wormhole-infall var(--ge-wormhole-infall-speed) linear infinite;
  pointer-events: none;
}

.ge-celestial__wormhole-infall--two {
  animation-delay: -1.06s;
}

.ge-celestial__wormhole-infall--three {
  animation-delay: -2.11s;
}

.ge-celestial--wormhole-full::after {
  position: absolute;
  inset: 33%;
  z-index: 8;
  border: 1px solid rgba(142, 239, 255, 0.58);
  border-radius: 50%;
  content: "";
  background: radial-gradient(circle, #000 0 42%, rgba(0, 8, 15, 0.98) 60%, rgba(44, 196, 255, 0.14) 72%, transparent 76%);
  box-shadow: 0 0 9px rgba(69, 210, 255, 0.48), inset 0 0 7px rgba(0, 0, 0, 0.95);
  animation: ge-wormhole-core var(--ge-wormhole-pulse-speed) ease-in-out infinite;
  pointer-events: none;
}

.ge-celestial--wormhole-tiny {
  --ge-wormhole-outer-speed: 8s;
}

.ge-celestial--wormhole-tiny .ge-celestial__wormhole-layer,
.ge-celestial--wormhole-tiny .ge-celestial__wormhole-infall {
  display: none;
}

/* Static fallback if animation setup is interrupted. */
.ge-celestial-motion-disabled .ge-celestial--axial > .ge-celestial__source {
  opacity: 1 !important;
}

.ge-celestial-motion-disabled .ge-celestial__canvas,
.ge-celestial-motion-disabled .ge-celestial__orbit-scene,
.ge-celestial-motion-disabled .ge-solar-prominences,
.ge-celestial-motion-disabled .ge-celestial__wormhole-layer,
.ge-celestial-motion-disabled .ge-celestial__wormhole-infall,
.ge-celestial-motion-disabled .ge-celestial--wormhole-full::after {
  display: none !important;
}

.ge-celestial-motion-disabled .ge-celestial--sun::before,
.ge-celestial-motion-disabled .ge-celestial--wormhole > .ge-celestial__source {
  animation: none !important;
}

@keyframes ge-solar-breathe {
  0%, 100% {
    opacity: calc(var(--ge-solar-glow-opacity) * 0.76);
    scale: 0.985;
  }
  50% {
    opacity: var(--ge-solar-glow-opacity);
    scale: var(--ge-solar-pulse-scale);
  }
}

@keyframes ge-development-orbit {
  from {
    transform: rotate(var(--ge-orbit-inclination, 0deg)) scaleY(0.58) rotate(0deg);
  }
  to {
    transform: rotate(var(--ge-orbit-inclination, 0deg)) scaleY(0.58) rotate(360deg);
  }
}

@keyframes ge-development-orbit-depth {
  0%, 49.999% {
    z-index: 1;
  }
  50%, 100% {
    z-index: 3;
  }
}

@keyframes ge-solar-surface-fire {
  0%, 100% {
    filter: saturate(1.08) contrast(1.03) brightness(0.95) drop-shadow(0 0 5px rgba(var(--ge-solar-glow-rgb), 0.46));
    scale: 0.998;
  }
  16% {
    filter: saturate(1.22) contrast(1.08) brightness(1.07) drop-shadow(0 0 8px rgba(var(--ge-solar-flare-rgb), 0.58));
    scale: 1.006;
  }
  34% {
    filter: saturate(1.13) contrast(1.04) brightness(0.99) drop-shadow(0 0 6px rgba(var(--ge-solar-glow-rgb), 0.52));
    scale: 1.002;
  }
  62% {
    filter: saturate(1.26) contrast(1.08) brightness(1.1) drop-shadow(0 0 9px rgba(var(--ge-solar-hot-rgb), 0.66));
    scale: 1.009;
  }
  84% {
    filter: saturate(1.18) contrast(1.06) brightness(1.03) drop-shadow(0 0 7px rgba(var(--ge-solar-flare-rgb), 0.56));
    scale: 1.004;
  }
}

@keyframes ge-solar-prominence {
  0%, 100% {
    opacity: 0.22;
    transform: translateX(-50%) scaleY(0.38) scaleX(0.9);
  }
  18% {
    opacity: 0.74;
    transform: translateX(-50%) scaleY(1.08) scaleX(1.02);
  }
  48% {
    opacity: 0.62;
    transform: translateX(-50%) scaleY(1.28) scaleX(0.84);
  }
  64% {
    opacity: 0.25;
    transform: translateX(-50%) scaleY(0.5) scaleX(1.08);
  }
  82% {
    opacity: 0.5;
    transform: translateX(-50%) scaleY(0.92) scaleX(0.96);
  }
}

@keyframes ge-solar-loop-flare {
  0%, 100% {
    opacity: 0.22;
    transform: translateX(-50%) rotate(var(--ge-loop-tilt)) scale(0.64, 0.42);
  }
  28% {
    opacity: 0.72;
    transform: translateX(-50%) rotate(calc(var(--ge-loop-tilt) - 12deg)) scale(1.08, 1.18);
  }
  53% {
    opacity: 0.52;
    transform: translateX(-50%) rotate(calc(var(--ge-loop-tilt) + 5deg)) scale(0.9, 0.82);
  }
  76% {
    opacity: 0.34;
    transform: translateX(-50%) rotate(calc(var(--ge-loop-tilt) - 6deg)) scale(1.2, 0.62);
  }
}

@keyframes ge-wormhole-spin-forward {
  to { rotate: 1turn; }
}

@keyframes ge-wormhole-spin-reverse {
  to { rotate: -1turn; }
}

@keyframes ge-wormhole-core {
  0%, 100% {
    opacity: 0.86;
    scale: 0.94;
    box-shadow: 0 0 7px rgba(69, 210, 255, 0.34), inset 0 0 7px rgba(0, 0, 0, 0.95);
  }
  42% {
    opacity: 1;
    scale: 1.08;
    box-shadow: 0 0 14px rgba(69, 210, 255, 0.72), inset 0 0 10px rgba(0, 0, 0, 1);
  }
  66% {
    opacity: 0.92;
    scale: 0.99;
    box-shadow: 0 0 9px rgba(69, 210, 255, 0.5), inset 0 0 8px rgba(0, 0, 0, 0.98);
  }
}

@keyframes ge-wormhole-layer-pulse {
  0%, 100% {
    opacity: 0.48;
    scale: 0.92;
  }
  34% {
    opacity: 0.82;
    scale: 1.06;
  }
  69% {
    opacity: 0.62;
    scale: 0.98;
  }
}

@keyframes ge-wormhole-depth-dive {
  0%, 100% {
    opacity: 0.44;
    scale: 1.08;
  }
  52% {
    opacity: 0.78;
    scale: 0.86;
  }
}

@keyframes ge-wormhole-infall {
  0% {
    opacity: 0;
    scale: 1.24;
  }
  18% {
    opacity: calc(var(--ge-wormhole-energy) * 0.62);
  }
  72% {
    opacity: calc(var(--ge-wormhole-energy) * 0.28);
  }
  100% {
    opacity: 0;
    scale: 0.36;
  }
}
