/* Sparkles: tiny four-pointed stars that twinkle around a `.sparkle-host` while it is hovered or has the keyboard
   focus (`<Sparkles />`, src/common/views/sparkles.tsx). Placed in percentages of the host (--x, --y), so they ring a
   round button and a wide pill alike; each has its own size, colour and delay. Decorative; reduced motion stops them
   (base.css). Used by the developers' links on About and the header's Contribute button. */

.sparkle-host {
  position: relative;
}

.sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sparkles i {
  position: absolute;
  top: var(--y);
  left: var(--x);
  width: var(--star, var(--space-3));
  height: var(--star, var(--space-3));
  background: var(--star-color, var(--color-sparkle));
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
  translate: -50% -50%;
  scale: 0;
}

.sparkles i:nth-child(1) {
  --x: -12%;
  --y: 10%;
  --d: 0s;
}

.sparkles i:nth-child(2) {
  --x: 108%;
  --y: -8%;
  --d: 0.15s;
  --star: var(--space-4);
  --star-color: var(--color-accent);
}

.sparkles i:nth-child(3) {
  --x: 118%;
  --y: 70%;
  --d: 0.3s;
}

.sparkles i:nth-child(4) {
  --x: -16%;
  --y: 88%;
  --d: 0.45s;
  --star: var(--space-4);
}

.sparkles i:nth-child(5) {
  --x: 40%;
  --y: -42%;
  --d: 0.6s;
  --star-color: var(--color-accent);
}

.sparkles i:nth-child(6) {
  --x: 70%;
  --y: 135%;
  --d: 0.75s;
  --star: var(--space-2);
}

.sparkle-host:hover .sparkles i,
.sparkle-host:focus-visible .sparkles i {
  animation: twinkle 1.2s var(--ease-out) var(--d) infinite;
}

@keyframes twinkle {
  0% {
    opacity: 0;
    scale: 0;
    rotate: 0deg;
  }

  40% {
    opacity: 1;
    scale: 1;
  }

  100% {
    opacity: 0;
    scale: 0.4;
    rotate: 90deg;
  }
}

/* A burst (public/js/burst.js): stars flying out from the middle of an answer button, each at its own angle, distance,
   spin and delay (set by the script), while the button pops. */
.popped {
  animation: pop calc(1.5 * var(--duration-base)) var(--ease-out);
}

@keyframes pop {
  40% {
    scale: 1.15;
  }
}

.burst {
  position: absolute;
  inset: 50% auto auto 50%;
  pointer-events: none;
}

.burst i {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--space-3);
  height: var(--space-3);
  margin: calc(-1 * var(--space-3) / 2);
  background: var(--color-sparkle);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
  animation: burst-out calc(3 * var(--duration-base) + var(--duration-fast)) var(--ease-out)
    var(--delay) forwards;
}

.burst-right i:nth-child(odd) {
  background: var(--color-right);
}

.burst-wrong i:nth-child(odd) {
  background: var(--color-wrong);
}

.burst i:nth-child(3n) {
  width: var(--space-2);
  height: var(--space-2);
}

@keyframes burst-out {
  0% {
    opacity: 1;
    transform: rotate(var(--angle)) translateX(0) scale(0.3);
  }

  70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateX(var(--distance)) rotate(var(--spin)) scale(1);
  }
}
