/* Load after styles.css. Keep labels, button dimensions and the existing focus outline. */
.button {
  position: relative;
  isolation: isolate;
  --cta-active: 0;
  --cta-fill-scale: 0.2;
  transition: color 360ms var(--ease);
}

.button:hover {
  transform: none;
  box-shadow: none;
}

.button-green,
.button-green:hover {
  background: var(--green);
  --cta-fill: #80ee86;
  --cta-disc: var(--navy);
  --cta-arrow: var(--green);
}

.button-navy,
.button-navy:hover {
  background: var(--navy);
  --cta-fill: var(--navy-soft);
  --cta-disc: var(--lavender);
  --cta-arrow: var(--navy);
}

.button::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--cta-fill);
  opacity: var(--cta-active);
  transform: scaleX(var(--cta-fill-scale));
  transform-origin: right center;
  transition:
    transform 520ms var(--ease),
    opacity 300ms var(--ease);
  pointer-events: none;
}

/* The backing is out of flow; a 25px slot preserves the original arrow's line height. */
.button > span[aria-hidden='true'] {
  position: relative;
  isolation: isolate;
  display: inline-grid;
  place-items: center;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  font-size: 20px;
  line-height: 1;
  color: var(--cta-arrow);
  transform: translate(calc(var(--cta-active) * 2px), calc(var(--cta-active) * -2px));
  transition: transform 420ms var(--ease);
}

.button-small > span[aria-hidden='true'] {
  font-size: 18px;
}

/* A pending submit replaces its arrow with plain text; reserve the same height. */
.submit-button {
  min-height: 55px;
}

.button > span[aria-hidden='true']::before {
  content: '';
  position: absolute;
  inset: -3px;
  z-index: -1;
  border-radius: 50%;
  background: var(--cta-disc);
  transform: translate(calc(var(--cta-active) * -2px), calc(var(--cta-active) * 2px))
    scale(calc(1 + var(--cta-active) * 0.06));
  transition: transform 420ms var(--ease);
  pointer-events: none;
}

.button:focus-visible:not(:disabled) {
  --cta-active: 1;
  --cta-fill-scale: 1;
}

@media (hover: hover) and (pointer: fine) {
  .button:hover:not(:disabled) {
    --cta-active: 1;
    --cta-fill-scale: 1;
  }
}

/* The arrow glyph is wrapped so it can loop out and back inside its disc. */
.cta-glyph {
  display: block;
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .button {
    translate: var(--mag-x, 0px) var(--mag-y, 0px);
    transition:
      color 360ms var(--ease),
      translate 750ms var(--motion-spring);
  }
  .button.is-magnetic {
    transition:
      color 360ms var(--ease),
      translate 200ms var(--motion-out);
  }
  .button > span[aria-hidden='true'] {
    translate: calc(var(--mag-x, 0px) * 0.6) calc(var(--mag-y, 0px) * 0.6);
    transition:
      transform 420ms var(--ease),
      translate 750ms var(--motion-spring);
  }
  .button.is-magnetic > span[aria-hidden='true'] {
    transition:
      transform 420ms var(--ease),
      translate 200ms var(--motion-out);
  }
  .button:hover:not(:disabled) .cta-glyph {
    animation: cta-arrow-loop 640ms var(--motion-out);
  }
}

@keyframes cta-arrow-loop {
  0% {
    transform: none;
    opacity: 1;
  }
  38% {
    transform: translate(9px, -9px);
    opacity: 0;
  }
  39% {
    transform: translate(-9px, 9px);
    opacity: 0;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

.faq-list summary > span[aria-hidden='true'] {
  transition: transform 360ms var(--ease);
}

.faq-list details[data-faq-closing] > summary > span[aria-hidden='true'] {
  transform: rotate(0);
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .button::before,
  .button > span[aria-hidden='true'],
  .button > span[aria-hidden='true']::before,
  .faq-list summary > span[aria-hidden='true'] {
    transition: none;
  }

  .button > span[aria-hidden='true'],
  .button > span[aria-hidden='true']::before {
    transform: none;
  }
}
