/**
 * @prop --mds-spinner-duration: Public. Duration of the spinner animation.
 */

:host {

  /* stylelint-disable-next-line magma/token-values -- 725ms, one turn of the spinner, no --duration-* step says it */
  --mds-spinner-duration: 0.725s;
  --private-spinner-duration: var(--mds-spinner-duration, 0.725s);

  @apply ease-in-out-quart;

  align-items: center;
  color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  display: inline-flex;
  height: --spacing(1200);
  justify-content: center;
  opacity: 0;
  overflow: hidden;
  transform: scale(0);
  transition-duration: var(--duration-300, 300ms);
  transition-property: opacity, transform;
  width: --spacing(1200);
}

:host([running]) {
  @apply ease-in-out-expo;

  opacity: 1;
  transform: scale(1);
  transition-duration: var(--duration-700, 700ms);
}

.await-icon {
  @apply animate-spin
    ease-out;

  animation-duration: var(--private-spinner-duration);
  animation-play-state: paused;
  aspect-ratio: var(--aspect-square, 1/1);
  display: flex;
  flex-shrink: 0;
  stroke: currentcolor;
  transition-duration: var(--duration-300, 300ms);
  transition-property: stroke;
  width: 100%;
}

.await-icon svg {
  width: 100%;
}

:host([running]) .await-icon {
  animation-play-state: running;
}

/* Motion, held back.
 *
 * Every component zeroes the private durations its own base CSS reads, which composes
 * with the public knobs - but that only reaches the declarations that read them. An audit
 * of the 52 sheets found 21 transitions in 15 components that did not: the host's own
 * transition in mds-button and mds-table, the focus ring of the input family, the tab
 * slider, the close button of mds-note. This reset reaches the whole shadow tree, which is
 * what the preference promises, and keeps reaching it when a declaration is added.
 *
 * Transitions only, on purpose. A keyframe animation is usually a loader, and a loader has
 * to keep saying "working": mds-spinner slows to 8s under reduced motion instead of
 * freezing, and a duration of nearly zero on an infinite animation would spin it out of
 * control instead of stopping it.
 *
 * 0.01ms rather than 0s, so a component that waits for its own transitionend still gets
 * one: mds-modal, mds-push-notification and mds-tree-item all listen for it, and a
 * transition of zero never fires it. */

/* stylelint-disable time-min-milliseconds -- the floor is there to keep a transition
   perceivable; the point of these two is that it is not. */

:host([pref-animation='reduce']),
:host([pref-animation='reduce']) *,
:host([pref-animation='reduce']) *::before,
:host([pref-animation='reduce']) *::after {
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host([pref-animation='system']) *,
  :host([pref-animation='system']) *::before,
  :host([pref-animation='system']) *::after,
  :host(:not([pref-animation])),
  :host(:not([pref-animation])) *,
  :host(:not([pref-animation])) *::before,
  :host(:not([pref-animation])) *::after {
    transition-duration: 0.01ms !important;
  }
}

/* stylelint-enable time-min-milliseconds */


/* Animation preference. The component mirrors the resolved mode from <html> onto its host as
 * pref-animation (see subscribePreference in @common/preference). The spinner must keep turning
 * to signal progress, so reduced motion slows it (8s) rather than freezing it (a 0 duration
 * would). `reduce` always slows it; `system` and no controller follow the OS via @media;
 * `no-preference` keeps the base value. The slowdown sets the private duration, so a
 * --mds-spinner-duration set from outside (mds-button sets one) no longer cancels it. */

:host([pref-animation='reduce']) {

  /* stylelint-disable-next-line magma/token-values -- 8s, the slowed turn above: no --duration-* step says it */
  --private-spinner-duration: 8s;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {

    /* stylelint-disable-next-line magma/token-values -- 8s, the slowed turn above: no --duration-* step says it */
    --private-spinner-duration: 8s;
  }
}

/* Contrast preference. The component reflects the resolved mode from <html> onto
 * its host as pref-contrast (see subscribePreference in @common/preference); these
 * plain shadow selectors refine for high contrast. `more` is the explicit choice;
 * `system` and no controller follow the OS via @media. Cross-browser, no :host-context. */

:host([pref-contrast='more']) {
  color: rgb(var(--magma-accent-emphasis-active, var(--variant-primary-02, 0 57 163)));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    color: rgb(var(--magma-accent-emphasis-active, var(--variant-primary-02, 0 57 163)));
  }
}

:host(:not(:is([hydrated], .hydrated))) {
  @apply not-hydrated;
}

