/* Sending: a Newton's cradle, a label with a light sweeping across it, and the time so far.
   Built by scripts/send-loader.js. Everything takes currentColor. */

.send-loader {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  white-space: nowrap;
}

/* ---- the cradle: four balls on strings from one bar; the end ones swing in turn ---- */
.send-loader__cradle {
  --ball: 6px;
  --string: 9px;
  display: inline-flex;
  gap: 0;
  height: calc(var(--string) + var(--ball));
  padding-inline: 4px;   /* room for the end balls to swing out */
}
.send-loader__cradle i {
  position: relative;
  width: var(--ball);
  height: 100%;
  transform-origin: 50% 0;
}
.send-loader__cradle i::before {   /* the string */
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: var(--string);
  margin-left: -0.5px;
  background: currentColor;
  opacity: 0.55;
}
.send-loader__cradle i::after {    /* the ball */
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--ball);
  height: var(--ball);
  border-radius: 50%;
  background: currentColor;
}

/* One beat: the left ball swings out and falls back, the click sends the right one out, it
   falls back, and so on. Out decelerates, back accelerates, the way a pendulum does. */
.send-loader.is-running .send-loader__cradle i:first-child { animation: send-loader-left 1.1s infinite; }
.send-loader.is-running .send-loader__cradle i:last-child  { animation: send-loader-right 1.1s infinite; }

@keyframes send-loader-left {
  0%       { transform: rotate(0deg);  animation-timing-function: cubic-bezier(0.33, 0, 0.67, 1); }
  25%      { transform: rotate(32deg); animation-timing-function: cubic-bezier(0.33, 0, 0.67, 1); }
  50%, 100% { transform: rotate(0deg); }
}
@keyframes send-loader-right {
  0%, 50%  { transform: rotate(0deg);   animation-timing-function: cubic-bezier(0.33, 0, 0.67, 1); }
  75%      { transform: rotate(-32deg); animation-timing-function: cubic-bezier(0.33, 0, 0.67, 1); }
  100%     { transform: rotate(0deg); }
}

/* ---- the label: a band of light passing over it ---- */
.send-loader.is-running .send-loader__label {
  -webkit-text-fill-color: transparent;   /* the text shows only through its background: dim, with the bright band (color stays, so currentColor still means the ink) */
  background: linear-gradient(100deg, transparent 35%, currentColor 50%, transparent 65%) 100% 0 / 250% 100% no-repeat,
              color-mix(in srgb, currentColor 55%, transparent);
  -webkit-background-clip: text;
  background-clip: text;
  animation: send-loader-sweep 1.6s linear infinite;
}
@keyframes send-loader-sweep {
  from { background-position: 100% 0; }
  to   { background-position: -150% 0; }
}

/* ---- the time so far ---- */
.send-loader__time {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
  opacity: 0.5;
  min-width: 4ch;
}

@media (prefers-reduced-motion: reduce) {
  .send-loader.is-running .send-loader__cradle i { animation: none; }
  .send-loader.is-running .send-loader__label { animation: none; -webkit-text-fill-color: currentColor; background: none; opacity: 0.75; }
}
