/*
 * The homepage hero. Its 12-second timeline:
 *   0–6%     "before" cards enter            33–47%   scan line passes
 *   6–36%    "before" holds                  36–48%   "before" cards fold into the centre
 *   46–54%   "after" items appear, each list in its loop-step-* order
 *   52–92%   "after" holds                   92–98%   "after" fades, then the loop restarts
 * Status label: "before" shows 0–44%, "after" 50–94%.
 *
 * With reduced motion, only the finished "after" state is shown, still: the "before" cards, the scan line
 * and the "before" label are hidden at rest, and their animations make them visible while they run.
 * The cards fold in from the positions the page gives each one (--x, --y, --r).
 */

:root {
  /* One full loop. */
  --loop-cycle: 12s;
}

@layer utilities {
  @media (prefers-reduced-motion: no-preference) {
    .motion-safe\:animate-loop-status-before {
      animation: loop-status-before var(--loop-cycle) var(--ease-in-out) infinite both;
    }

    .motion-safe\:animate-loop-status-after {
      animation: loop-status-after var(--loop-cycle) var(--ease-in-out) infinite both;
    }

    .motion-safe\:animate-loop-card {
      animation: loop-card var(--loop-cycle) var(--ease-smooth-out) calc(var(--loop-step, 0) * 110ms) infinite both;
    }

    .motion-safe\:animate-loop-sweep {
      animation: loop-sweep var(--loop-cycle) linear infinite both;
    }

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

    .motion-safe\:animate-loop-rise {
      animation: loop-rise var(--loop-cycle) var(--ease-smooth-out) calc(var(--loop-step, 0) * 180ms) infinite both;
    }

    .motion-safe\:animate-loop-pop {
      animation: loop-pop var(--loop-cycle) var(--ease-smooth-out) calc(var(--loop-step, 0) * 90ms) infinite both;
    }

    .motion-safe\:animate-loop-draw {
      animation: loop-draw var(--loop-cycle) var(--ease-smooth-out) calc(var(--loop-step, 0) * 180ms) infinite both;
    }

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

    .motion-safe\:before\:animate-flow-line:before {
      content: var(--tw-content);
      animation: flow-line var(--loop-cycle) var(--ease-smooth-out) infinite both;
    }
  }

  /* An item's place in its list (the cards, the steps, the finished jobs): each list's items start one after
     another, 110ms, 180ms and 90ms apart respectively. */
  .loop-step-0 {
    --loop-step: 0;
  }

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

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

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

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

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

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

  .loop-step-7 {
    --loop-step: 7;
  }
}

@keyframes loop-status-before {
  0%,
  44% {
    visibility: visible;
    opacity: 1;
    transform: none;
  }
  48%,
  96% {
    visibility: visible;
    opacity: 0;
    transform: translateY(-6px);
  }
  100% {
    visibility: visible;
    opacity: 1;
    transform: none;
  }
}

@keyframes loop-status-after {
  0%,
  46% {
    opacity: 0;
    transform: translateY(6px);
  }
  50%,
  94% {
    opacity: 1;
    transform: none;
  }
  98%,
  100% {
    opacity: 0;
    transform: none;
  }
}

@keyframes loop-card {
  0% {
    visibility: visible;
    opacity: 0;
    transform: translate(calc(-50% + var(--x) * 1cqw), calc(-50% + var(--y) * 1cqh + 14px)) rotate(var(--r, 0deg)) scale(0.94);
  }
  6%,
  36% {
    visibility: visible;
    opacity: 1;
    transform: translate(calc(-50% + var(--x) * 1cqw), calc(-50% + var(--y) * 1cqh)) rotate(var(--r, 0deg));
  }
  48%,
  100% {
    visibility: visible;
    opacity: 0;
    transform: translate(-50%, -50%) rotate(0deg) scale(0.35);
  }
}

@keyframes loop-sweep {
  0%,
  33% {
    visibility: visible;
    opacity: 0;
    transform: translateX(0);
  }
  35% {
    visibility: visible;
    opacity: 1;
  }
  46% {
    visibility: visible;
    opacity: 1;
    transform: translateX(100cqw);
  }
  47%,
  100% {
    visibility: visible;
    opacity: 0;
    transform: translateX(100cqw);
  }
}

@keyframes loop-scene-after {
  0%,
  46% {
    opacity: 0;
    transform: scale(0.97);
  }
  52%,
  92% {
    opacity: 1;
    transform: none;
  }
  98%,
  100% {
    opacity: 0;
    transform: none;
  }
}

@keyframes loop-rise {
  0%,
  49% {
    opacity: 0;
    transform: translateY(10px);
  }
  54%,
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes loop-pop {
  0%,
  58% {
    opacity: 0;
    transform: translateY(8px) scale(0.92);
  }
  63%,
  100% {
    opacity: 1;
    transform: none;
  }
}

/* The tick draws itself: the path is one dash (pathLength 1) that the offset slides into view. */
@keyframes loop-draw {
  0%,
  53% {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
  }
  60%,
  100% {
    stroke-dasharray: 1;
    stroke-dashoffset: 0;
  }
}

@keyframes loop-late {
  0%,
  62% {
    opacity: 0;
    transform: translateY(8px);
  }
  67%,
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes flow-line {
  0%,
  50% {
    transform: scaleX(0);
  }
  60%,
  100% {
    transform: scaleX(1);
  }
}
