:root {
  --#{$CSS_VAR_PFX}firework-color-main: var(--#{$CSS_VAR_PFX}color-blue-primary);
  --#{$CSS_VAR_PFX}firework-color-center-top-bottom: var(--#{$CSS_VAR_PFX}color-blue-primary);
  --#{$CSS_VAR_PFX}firework-color-center-left-right: var(--#{$CSS_VAR_PFX}color-blue-primary);
  --#{$CSS_VAR_PFX}firework-color-left-top-bottom: var(--#{$CSS_VAR_PFX}color-purple-primary);
  --#{$CSS_VAR_PFX}firework-color-right-top-bottom: var(--#{$CSS_VAR_PFX}color-purple-primary);
  --#{$CSS_VAR_PFX}firework-animation-delay: 0s;
  --#{$CSS_VAR_PFX}firework-animation-duration: 4s;
  --#{$CSS_VAR_PFX}firework-animation-iteration-count: infinite;
}

.fireworks {
  position: relative;
  z-index: $ZINDEX_FIREWORKS;
  width: 2.5em;
  height: 2em;
  background: transparent;
  animation: flatify-firework ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
    var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count);

  &:before,
  .spark:before,
  .spark:after {
    content: " ";
    position: absolute;
    height: 0.25em;
    border-radius: 50em;
    background: var(--#{$CSS_VAR_PFX}firework-color-main);
  }

  &:not(.simple):before {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 0.25em;
    margin: auto;
    animation: flatify-firework-main ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
      var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count) both;
  }

  .spark {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    animation: flatify-firework-sparks ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
      var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count) both;

    // left-right & top-bottom
    &:nth-child(1),
    &:nth-child(2) {
      &:before,
      &:after {
        top: 0;
        bottom: 0;
        width: 1.5em;
        margin: auto;
      }

      &:before {
        left: -0.25em;
        animation: flatify-firework-spark-left ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
          var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count);
      }
      &:after {
        right: -0.25em;
        animation: flatify-firework-spark-right ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
          var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count);
      }
    }

    &:nth-child(1) {
      --#{$CSS_VAR_PFX}firework-color-main: var(--#{$CSS_VAR_PFX}firework-color-center-left-right);
    }
    &:nth-child(2) {
      --#{$CSS_VAR_PFX}firework-color-main: var(--#{$CSS_VAR_PFX}firework-color-center-top-bottom);
      transform: rotate(90deg);
    }

    // top-left-top-right & bottom-left-bottom-right
    &:nth-child(3),
    &:nth-child(4) {
      left: 0;

      &:before,
      &:after {
        width: 0.75em;
      }

      &:before {
        top: 0;
        transform: rotate(45deg);
        animation: flatify-firework-spark-corner-top ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
          var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count);
      }
      &:after {
        bottom: 0;
        transform: rotate(-45deg);
        animation: flatify-firework-spark-corner-bottom ease-in-out var(--#{$CSS_VAR_PFX}firework-animation-duration)
          var(--#{$CSS_VAR_PFX}firework-animation-delay) var(--#{$CSS_VAR_PFX}firework-animation-iteration-count);
      }
    }

    &:nth-child(3) {
      --#{$CSS_VAR_PFX}firework-color-main: var(--#{$CSS_VAR_PFX}firework-color-left-top-bottom);
    }
    &:nth-child(4) {
      --#{$CSS_VAR_PFX}firework-color-main: var(--#{$CSS_VAR_PFX}firework-color-right-top-bottom);
      transform: rotate(180deg);
    }
  }
}

@keyframes flatify-firework {
  0%,
  20% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-1em);
  }
  80%,
  100% {
    transform: translateY(0.5em);
  }
}

@keyframes flatify-firework-main {
  0% {
    opacity: 0;
    transform: scale(0) translateY(1em);
  }
  5% {
    opacity: 1;
    transform: scale(0, 6) translateY(1em);
  }
  26% {
    transform: scaleY(2) translateY(0);
  }
  30% {
    transform: scale(9) translateY(0);
  }
  40%,
  100% {
    transform: scale(0) translateY(0);
  }
}

@keyframes flatify-firework-sparks {
  0%,
  30% {
    clip-path: circle(0 at center);
    opacity: 0;
  }
  38% {
    clip-path: circle(100% at center);
    opacity: 1;
  }
  65%,
  100% {
    opacity: 0;
  }
}

// corners
@keyframes flatify-firework-spark-corner-top {
  0%,
  30% {
    opacity: 1;
    clip-path: circle(100% at left);
    transform: scale(1) translate(0) rotate(45deg);
  }
  40% {
    clip-path: circle(100% at left);
  }
  60%,
  100% {
    opacity: 0;
    clip-path: circle(0 at left);
    transform: scale(1.5) translate(-0.5em, -0.25em) rotate(45deg);
  }
}

@keyframes flatify-firework-spark-corner-bottom {
  0%,
  30% {
    opacity: 1;
    clip-path: circle(100% at left);
    transform: scale(1) translate(0) rotate(-45deg);
  }
  40% {
    clip-path: circle(100% at left);
  }
  60%,
  100% {
    opacity: 0;
    clip-path: circle(0 at left);
    transform: scale(1.5) translate(-0.5em, 0.25em) rotate(-45deg);
  }
}

// left & right
@keyframes flatify-firework-spark-left {
  0%,
  30% {
    opacity: 1;
    clip-path: circle(100% at left);
    transform: scale(1) translate(0);
  }
  40% {
    clip-path: circle(100% at left);
  }
  60%,
  100% {
    opacity: 0;
    clip-path: circle(0 at left);
    transform: scaleX(2) translate(-0.5em);
  }
}

@keyframes flatify-firework-spark-right {
  0%,
  30% {
    opacity: 1;
    clip-path: circle(100% at right);
    transform: scale(1) translate(0);
  }
  40% {
    clip-path: circle(100% at right);
  }
  60%,
  100% {
    opacity: 0;
    clip-path: circle(0 at right);
    transform: scaleX(2) translate(0.5em);
  }
}
