/* The Analytics hero. The order feed moves by the height of one of its rows, which the
   page sets as --row. Each daily bar takes a live-step-* class, so the bars settle out of step. */

:root {
  /* One full loop of the feed: four new orders arrive in each. */
  --live-cycle: 12s;
}

@layer utilities {
  @media (prefers-reduced-motion: no-preference) {
    .motion-safe\:animate-live-pulse {
      animation: live-pulse 2s var(--ease-in-out) infinite;
    }

    .motion-safe\:animate-live-stream {
      animation: live-stream 18s linear infinite;
    }

    .motion-safe\:animate-live-bar {
      animation: live-bar 5s var(--ease-in-out) calc(var(--live-step, 0) * -700ms) infinite alternate;
    }

    .motion-safe\:animate-live-feed {
      animation: live-feed var(--live-cycle) var(--ease-smooth-out) infinite both;
    }

    /* pops as each new order lands in the feed */
    .motion-safe\:animate-live-plus {
      animation: live-plus calc(var(--live-cycle) / 4) var(--ease-smooth-out) calc(var(--live-cycle) / 4 * 0.8) infinite both;
    }
  }

  /* A daily bar's place in the chart. */
  .live-step-0 {
    --live-step: 0;
  }

  .live-step-1 {
    --live-step: 1;
  }

  .live-step-2 {
    --live-step: 2;
  }

  .live-step-3 {
    --live-step: 3;
  }

  .live-step-4 {
    --live-step: 4;
  }

  .live-step-5 {
    --live-step: 5;
  }

  .live-step-6 {
    --live-step: 6;
  }
}

@keyframes live-pulse {
  50% {
    opacity: 0.35;
  }
}

/* one period is half the drawn line */
@keyframes live-stream {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-200px);
  }
}

@keyframes live-bar {
  from {
    transform: scaleY(0.9);
  }
  to {
    transform: scaleY(1);
  }
}

/* a new order arrives on top every quarter of the cycle */
@keyframes live-feed {
  0%,
  20% {
    transform: translateY(calc(var(--row) * -4));
  }
  25%,
  45% {
    transform: translateY(calc(var(--row) * -3));
  }
  50%,
  70% {
    transform: translateY(calc(var(--row) * -2));
  }
  75%,
  95% {
    transform: translateY(calc(var(--row) * -1));
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes live-plus {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  10%,
  60% {
    opacity: 1;
    transform: none;
  }
  80%,
  100% {
    opacity: 0;
    transform: translateY(-6px);
  }
}
