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


/**
 * @prop --mds-progress-background: Public. Background color of the progress bar.
 * @prop --mds-progress-color: Public. Foreground color of the progress indicator.
 * @prop --mds-progress-duration: Public. Duration of the progress animation.
 * @prop --mds-progress-radius: Public. Border-radius of the progress bar.
 * @prop --mds-progress-thickness: Public. Thickness (height) of the progress bar.
 */

:host {
  --mds-progress-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));

  /* stylelint-disable-next-line magma/token-values -- 750ms no --duration-* step says it */
  --mds-progress-duration: 750ms;
  --private-progress-duration: var(--mds-progress-duration, 750ms);
  --mds-progress-transition-duration: var(--duration-300, 300ms);
  --private-progress-transition-duration: var(--mds-progress-transition-duration);
  --mds-progress-thickness: --spacing(200);
  --mds-progress-radius: var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px));

  @apply ease-in-out;

  background-color: var(--mds-progress-background, rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208))));
  border-radius: var(--mds-progress-radius, var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px)));
  corner-shape: var(--magma-corner-shape, squircle);
  display: flex;
  height: var(--mds-progress-thickness, --spacing(200));
  min-height: var(--mds-progress-thickness, --spacing(200));
  min-width: var(--mds-progress-thickness, --spacing(200));
  overflow: hidden;
  position: relative;
  transition-duration: var(--private-progress-transition-duration);
  transition-property: background-color;
  width: 100%;
}

:host([direction='vertical']) {
  flex-direction: column;
  height: unset;
  min-height: var(--mds-progress-thickness, --spacing(200));
  width: var(--mds-progress-thickness, --spacing(200));
}

:host([direction='radial']) {
  aspect-ratio: 1;
  background-color: transparent;
  height: auto;
}

:host([direction='radial']) mds-radial-progress {
  width: inherit;
}

.progress {
  @apply ease-out-expo;

  background-color: var(--mds-progress-color, rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211))));
  border-radius: inherit;
  corner-shape: inherit;
  transition-duration: var(--private-progress-duration);
  transition-property: background-color, flex-grow;
}

:host([variant='dark']) {
  --mds-progress-color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
  --mds-progress-background: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
}

:host([variant='light']) {
  --mds-progress-color: rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-progress-background: rgb(var(--magma-surface-inverse-muted, var(--tone-neutral-03, 73 73 73)));
}

:host([variant='error']) {
  --mds-progress-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-progress-background: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
}

:host([variant='warning']) {
  --mds-progress-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-progress-background: rgb(var(--magma-warning-wash-base, var(--status-warning-09, 255 220 117)));
}

:host([variant='success']) {
  --mds-progress-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-progress-background: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
}

:host([variant='info']) {
  --mds-progress-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-progress-background: rgb(var(--magma-info-wash-base, var(--status-info-09, 193 230 246)));
}

:host([variant='primary']) {
  --mds-progress-color: rgb(var(--magma-accent-emphasis-hover, var(--variant-primary-03, 0 73 211)));
  --mds-progress-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
}

:host([variant='ai']) {
  --mds-progress-color: rgb(var(--magma-accent-ai-fg, var(--variant-ai-03, 105 49 204)));
  --mds-progress-background: rgb(var(--magma-accent-ai-surface, var(--variant-ai-09, 225 219 255)));
}

:host([size='sm']) {
  --mds-progress-thickness: --spacing(200);
}

:host([size='md']) {
  --mds-progress-thickness: --spacing(300);
}

:host([size='lg']) {
  --mds-progress-thickness: --spacing(400);
}

:host([size='xl']) {
  --mds-progress-thickness: --spacing(600);
}

/* 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);
 * these plain shadow selectors then zero the private duration(s) the base CSS
 * reads. `reduce` always stops; `system` and no controller follow the OS via
 * @media; `no-preference` keeps the base value. Customization composes (the base
 * sets --private from the public token, this only overrides it when reduced). */

:host([pref-animation='reduce']) {
  --private-progress-duration: 0s;
  --private-progress-transition-duration: 0s;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-progress-duration: 0s;
    --private-progress-transition-duration: 0s;
  }
}

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

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));

  &:host([variant='primary']) {
    --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  }

  &:host([variant='error']) {
    --mds-progress-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
    --mds-progress-background: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
  }

  &:host([variant='warning']) {
    --mds-progress-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
    --mds-progress-background: rgb(var(--magma-warning-wash-base, var(--status-warning-09, 255 220 117)));
  }

  &:host([variant='success']) {
    --mds-progress-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
    --mds-progress-background: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
  }

  &:host([variant='info']) {
    --mds-progress-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
    --mds-progress-background: rgb(var(--magma-info-wash-base, var(--status-info-09, 193 230 246)));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));

    &:host([variant='primary']) {
      --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
    }

    &:host([variant='error']) {
      --mds-progress-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
      --mds-progress-background: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
    }

    &:host([variant='warning']) {
      --mds-progress-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
      --mds-progress-background: rgb(var(--magma-warning-wash-base, var(--status-warning-09, 255 220 117)));
    }

    &:host([variant='success']) {
      --mds-progress-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
      --mds-progress-background: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
    }

    &:host([variant='info']) {
      --mds-progress-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
      --mds-progress-background: rgb(var(--magma-info-wash-base, var(--status-info-09, 193 230 246)));
    }
  }
}

/* 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']) {
  --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));

  &:host([variant='primary']) {
    --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  }
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));

    &:host([variant='primary']) {
      --mds-progress-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
    }
  }
}

