/* Autonomous layers share one viewport-aware clock switch per visual. */
[data-ambient] { --ambient-clock: paused; }
[data-ambient][data-ambient-live] { --ambient-clock: running; }
html[data-motion="paused"] [data-ambient] { --ambient-clock: paused; }

.domain-image[data-ambient]::before {
  content: "";
  position: absolute;
  inset: -26% -34%;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 29%, var(--glint, #c4e6ff) 47%, transparent 64%);
  opacity: .11;
  animation: mg-domain-light 9.6s ease-in-out infinite alternate;
  animation-play-state: var(--ambient-clock);
}
.domain-card:nth-child(2n) .domain-image[data-ambient]::before { animation-delay: -4.5s; }
.domain-card:nth-child(3n) .domain-image[data-ambient]::before { animation-delay: -7.8s; }
@keyframes mg-domain-light {
  0% { transform: translate3d(-30%,0,0); opacity: .07; }
  56% { opacity: .15; }
  100% { transform: translate3d(30%,0,0); opacity: .09; }
}

/* Only the authored domain illustrations receive camera movement.
   The image's original hover transform can still act independently. */
.domain-card.spatial .domain-image[data-ambient] img,
.domain-card.engineering .domain-image[data-ambient] img {
  animation: mg-object-camera 13s ease-in-out infinite alternate;
  animation-play-state: var(--ambient-clock);
}
.domain-card.engineering .domain-image[data-ambient] img { animation-delay: -8s; }
@keyframes mg-object-camera {
  from { scale: 1.025; translate: -.35% .22%; }
  to { scale: 1.085; translate: .7% -.4%; }
}

/* A passing highlight is confined to the candidate's actual range.
   Values, endpoints and the original reference remain stationary. */
#execution-instrument[data-ambient] .xi-candidate .xi-span {
  --ambient-range: #5d96a3;
  background: linear-gradient(110deg,transparent 38%,#d1f6ef 49%,transparent 61%) 90% 0 / 250% 100%,
              var(--ambient-range);
  animation: mg-read-span 4.8s ease-in-out infinite;
  animation-play-state: var(--ambient-clock);
}
#execution-instrument[data-ambient] .xi-separated .xi-candidate .xi-span {
  --ambient-range: #bf8f96;
  background-image: linear-gradient(110deg,transparent 38%,#fae1df 49%,transparent 61%);
}
@keyframes mg-read-span {
  0%, 10% { background-position: 100% 0; }
  75%, 100% { background-position: 0% 0; }
}

/* Individual translate/rotate properties compose with the authored 3D pose. */
.wafer-bay[data-ambient] .wafer-stack {
  animation: mg-wafer-float 7.2s ease-in-out infinite alternate;
  animation-play-state: var(--ambient-clock);
}
.wafer-bay[data-ambient] .wafer-halo {
  animation: mg-wafer-light 7.2s ease-in-out infinite alternate;
  animation-play-state: var(--ambient-clock);
}
@keyframes mg-wafer-float {
  from { translate: -1px 3px; rotate: -.75deg; }
  to { translate: 2px -6px; rotate: 1.15deg; }
}
@keyframes mg-wafer-light {
  from { scale: .97; opacity: .66; }
  to { scale: 1.05; opacity: .86; }
}

/* Inside the atlas, only its introductory spatial preview drifts. Full-size
   task evidence and all browsing controls keep their original position. */
.preview-strip[data-ambient] .preview-tile[data-category="3d-property"] img {
  animation: mg-atlas-preview 12s ease-in-out infinite alternate;
  animation-play-state: var(--ambient-clock);
}
@keyframes mg-atlas-preview {
  from { scale: 1.025; translate: -.25% .15%; }
  to { scale: 1.10; translate: .55% -.45%; }
}

/* The pre-existing one-shot glints follow the same suspension state. */
.domain-card.is-lit .domain-image[data-ambient]::after,
.wafer-bay.is-lit[data-ambient] .wafer-stack::after,
#execution-instrument[data-ambient].instrument-enter .xi-span,
#execution-instrument[data-ambient] .xi-signal { animation-play-state: var(--ambient-clock); }

@media (prefers-reduced-motion: reduce) {
  [data-ambient][data-ambient-live], [data-ambient] { --ambient-clock: paused; }
  .domain-image[data-ambient]::before { visibility: hidden; }
}
