.slide-motion { position: absolute; z-index: 1; inset: 0; overflow: clip; }
.motion-scene { position: absolute; inset-inline-end: -5%; inset-block-start: 50%; width: min(68cqw, 92cqh, 52rem); aspect-ratio: 1; translate: 0 -50%; }
.slide.signal .motion-scene { inset-inline: -5% auto; }
.motion-piece {
  position: absolute;
  --tone: var(--slide-primary);
  --delay: 0ms;
  --strength: .8;
  --ease: cubic-bezier(.2, .72, .22, 1);
  opacity: var(--strength);
  background: var(--tone);
  animation: var(--motion) var(--duration, 3.6s) var(--ease) var(--delay) both;
}
.motion-piece:nth-child(even) { --tone: var(--slide-secondary); }
.motion-piece:nth-child(2) { --delay: 110ms; }
.motion-piece:nth-child(3) { --delay: 220ms; }
.motion-piece:nth-child(4) { --delay: 330ms; }

/* The drift layers travel different distances, then settle into a quiet composition. */
[data-background="drift"] .motion-scene { --motion: slide-drift; --duration: 4s; }
[data-background="drift"] .motion-piece { inset: 22% 4% 12% 28%; border-radius: 43% 57% 64% 36% / 48% 31% 69% 52%; --travel: 22%; }
[data-background="drift"] .motion-piece:nth-child(2) { inset: 8% 28% 36% 18%; --travel: -28%; }
[data-background="drift"] .motion-piece:nth-child(3) { inset: 62% 11% 12% 53%; --travel: 34%; }
[data-background="drift"] .motion-piece:nth-child(4) { inset: 18% 12% 68% 72%; --travel: -46%; }
@keyframes slide-drift {
  from { opacity: 0; translate: var(--travel) 32%; rotate: -17deg; }
  55% { opacity: var(--strength); translate: calc(-.3 * var(--travel)) -7%; rotate: 5deg; }
  to { translate: 0 0; rotate: 0deg; }
}

/* Sweep is a diagonal pass with a staggered stack of ribbons. */
[data-background="sweep"] .motion-scene { --motion: slide-sweep; --duration: 3.2s; }
[data-background="sweep"] .motion-piece { top: 22%; left: 8%; width: 122%; height: 13%; rotate: -29deg; border-radius: .25rem; }
[data-background="sweep"] .motion-piece:nth-child(2) { top: 40%; left: 1%; height: 8%; }
[data-background="sweep"] .motion-piece:nth-child(3) { top: 56%; left: 12%; height: 17%; }
[data-background="sweep"] .motion-piece:nth-child(4) { top: 78%; left: 18%; height: 4%; }
@keyframes slide-sweep {
  from { opacity: 0; translate: 62% -60%; }
  45% { opacity: var(--strength); }
  to { translate: 0 0; }
}

[data-background="pulse"] .motion-scene { --motion: slide-ripple; --duration: 3.8s; }
[data-background="pulse"] .motion-piece { inset: 7%; border: clamp(2px, .6cqw, 6px) solid var(--tone); border-radius: 50%; background: none; }
[data-background="pulse"] .motion-piece:nth-child(2) { inset: 16%; }
[data-background="pulse"] .motion-piece:nth-child(3) { inset: 25%; }
[data-background="pulse"] .motion-piece:nth-child(4) { inset: 34%; }
@keyframes slide-ripple {
  from { opacity: 0; scale: .58; }
  55% { opacity: var(--strength); scale: 1.05; }
  to { scale: 1; }
}

[data-background="orbit"] .motion-scene { --motion: slide-orbit; --duration: 4.1s; }
[data-background="orbit"] .motion-piece { inset: 8%; border: 2px solid var(--tone); border-radius: 50%; background: none; --angle: 10deg; }
[data-background="orbit"] .motion-piece::after { content: ""; position: absolute; inset-block-start: 0; inset-inline-start: 50%; width: clamp(6px, 2cqw, 16px); aspect-ratio: 1; translate: -50% -50%; border-radius: 50%; background: var(--tone); }
[data-background="orbit"] .motion-piece:nth-child(2) { inset: 17%; --angle: 135deg; }
[data-background="orbit"] .motion-piece:nth-child(3) { inset: 28%; --angle: 250deg; }
[data-background="orbit"] .motion-piece:nth-child(4) { inset: 37%; --angle: 310deg; }
@keyframes slide-orbit {
  from { opacity: 0; rotate: calc(var(--angle) - 220deg); }
  25% { opacity: var(--strength); }
  to { rotate: var(--angle); }
}

[data-background="steps"] .motion-scene { inset-block: auto 0; translate: none; --motion: slide-steps; --duration: 2.8s; }
[data-background="steps"] .motion-piece { bottom: 0; left: 10%; width: 16%; height: 26%; transform-origin: center bottom; border-radius: .5rem .5rem 0 0; }
[data-background="steps"] .motion-piece:nth-child(2) { left: 30%; height: 43%; }
[data-background="steps"] .motion-piece:nth-child(3) { left: 50%; height: 61%; }
[data-background="steps"] .motion-piece:nth-child(4) { left: 70%; height: 80%; }
@keyframes slide-steps {
  from { opacity: 0; scale: 1 .04; }
  58% { opacity: var(--strength); scale: 1 1.04; }
  to { scale: 1 1; }
}

[data-background="wipe"] .motion-scene { inset-block: 0; aspect-ratio: auto; translate: none; --motion: slide-wipe; --duration: 3s; }
[data-background="wipe"] .motion-piece { inset: 0 0 0 46%; }
[data-background="wipe"] .motion-piece:nth-child(2) { inset-inline: 36% 48%; }
[data-background="wipe"] .motion-piece:nth-child(3) { inset-inline: 29% 66%; }
[data-background="wipe"] .motion-piece:nth-child(4) { inset-inline: 23% 75%; }
@keyframes slide-wipe {
  from { clip-path: inset(0 0 0 100%); }
  to { clip-path: inset(0); }
}

[data-background="fold"] .motion-scene { perspective: 70cqw; --motion: slide-fold; --duration: 3.7s; }
[data-background="fold"] .motion-piece { inset: 12% 0 8% 17%; clip-path: polygon(0 0, 100% 22%, 100% 100%, 0 74%); transform-origin: left center; }
[data-background="fold"] .motion-piece:nth-child(2) { inset: 24% 12% 22% 27%; }
[data-background="fold"] .motion-piece:nth-child(3) { inset: 34% 24% 34% 37%; }
[data-background="fold"] .motion-piece:nth-child(4) { inset: 45% 36% 46% 47%; }
@keyframes slide-fold {
  from { opacity: 0; rotate: y -78deg; }
  62% { opacity: var(--strength); rotate: y 10deg; }
  to { rotate: y 0deg; }
}

[data-background="spark"] .motion-scene { --motion: slide-starburst; --duration: 3.25s; }
[data-background="spark"] .motion-piece { inset: 18% 25% 30% 23%; clip-path: polygon(50% 0, 61% 37%, 100% 50%, 61% 63%, 50% 100%, 39% 63%, 0 50%, 39% 37%); --angle: 14deg; }
[data-background="spark"] .motion-piece:nth-child(2) { inset: 56% 18% 18% 56%; --angle: -12deg; }
[data-background="spark"] .motion-piece:nth-child(3) { inset: 7% 14% 73% 66%; --angle: 27deg; }
[data-background="spark"] .motion-piece:nth-child(4) { inset: 68% 63% 16% 21%; --angle: -25deg; }
@keyframes slide-starburst {
  from { opacity: 0; scale: .08; rotate: calc(var(--angle) - 85deg); }
  52% { opacity: var(--strength); scale: 1.09; }
  to { scale: 1; rotate: var(--angle); }
}

@media (prefers-reduced-motion: reduce), (forced-colors: active) {
  .slide-motion { display: none; }
}
