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


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


/**
 * @prop --mds-tooltip-arrow-background: Background color of the tooltip arrow.
 * @prop --mds-tooltip-background: Public. Background color of the tooltip body.
 * @prop --mds-tooltip-delay: Public. Delay before showing the tooltip.
 * @prop --mds-tooltip-drop-shadow: Drop shadow applied to the tooltip.
 * @prop --mds-tooltip-duration: Duration of the tooltip animation.
 * @prop --mds-tooltip-ease: Timing function for the tooltip animation.
 * @prop --mds-tooltip-dot-padding: Padding around the tooltip dot (if present).
 * @prop --mds-tooltip-transform-from: Transform applied at the start of the tooltip animation.
 * @prop --mds-tooltip-transform-to: Transform applied at the end of the tooltip animation.
 * @prop --mds-tooltip-z-index: Public. z-index of the tooltip container.
 */

/* ❌ Not supported
@property --mds-tooltip-drop-shadow {
  inherits: false;
  initial-value: drop-shadow(0 10px 8px rgb(0 0 0 / 0.04)) drop-shadow(0 4px 3px rgb(0 0 0 / 0.1)) drop-shadow(0 0 1px rgb(0 0 0 / 0.1));
  syntax: "<drop-shadow>";
}
@property --mds-tooltip-ease {
  inherits: false;
  initial-value: var(--ease-out-expo);
  syntax: "<timing-function>";
}
*/

:host {
  --mds-tooltip-arrow-background: var(--mds-tooltip-background, rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  --mds-tooltip-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));
  --mds-tooltip-delay: var(--duration-1000, 1000ms);
  --mds-tooltip-drop-shadow: drop-shadow(0 --spacing(250) --spacing(200) rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / 0.04))
    drop-shadow(0 --spacing(100) --spacing(75) rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / 0.1)) drop-shadow(0 0 1px rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / 0.1));
  --mds-tooltip-duration: var(--duration-500, 500ms);
  --private-tooltip-duration: var(--mds-tooltip-duration, var(--duration-500, 500ms));
  --mds-tooltip-ease: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  --mds-tooltip-dot-padding: --spacing(100);
  --mds-tooltip-transform-from: scale(0.9) translateY(calc(--spacing(400) * -1));
  --mds-tooltip-transform-to: scale(1) translate(0, 0);
  --mds-tooltip-z-index: var(--magma-tooltip-z-index, 6000);

  background-color: var(--mds-tooltip-background, rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  border-radius: var(--magma-radius-3xs, var(--radius-squircle-3xs, 6px));
  box-sizing: border-box;
  corner-shape: var(--magma-corner-shape, squircle);
  display: grid;
  filter: var(--mds-tooltip-drop-shadow);
  gap: --spacing(400);
  max-width: --spacing(6400);
  opacity: 0;
  padding-block: --spacing(100);
  padding-inline: --spacing(200);
  pointer-events: none;
  position: fixed;
  transform: var(--mds-tooltip-transform-from, scale(0.9) translateY(calc(--spacing(400) * -1)));
  transition-delay: 0s;
  transition-duration: var(--private-tooltip-duration);

  /* transform-origin is the pivot of the opening: in the list it interpolates from
   * the initial 50% 50% and the tooltip grows from a point that moves while it
   * grows. */
  transition-property: opacity, transform;
  transition-timing-function: var(--mds-tooltip-ease);
  width: fit-content;
  z-index: var(--mds-tooltip-z-index, var(--magma-tooltip-z-index, 6000));
}

:host([strategy='absolute']) {
  position: absolute;
}

:host([strategy='fixed']) {
  position: fixed;
}

:host([visible]:not([visible='false'])) {
  opacity: 1;
  pointer-events: auto;
  transform: var(--mds-tooltip-transform-to, scale(1) translate(0, 0));
  transition-delay: var(--mds-tooltip-delay, var(--duration-1000, 1000ms));
}

.text {
  display: inline-flex;
  padding: var(--mds-tooltip-dot-padding, --spacing(100));
}

.arrow {
  @apply ease-in-out;

  display: flex;
  fill: var(--mds-tooltip-arrow-background, rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  pointer-events: none;
  position: fixed;
  top: --spacing(-225);
  transition-duration: var(--duration-300, 300ms);
  transition-property: fill;
  z-index: -1;
}

::slotted(*) {
  position: relative;
  z-index: 10;
}

/* 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-tooltip-duration: 0s;
}

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

/* Theme preference. Background and elevation now come from the semantic surface
 * layer (--magma-surface-*, spec 6.1): it flips per mode at :root and inherits
 * into the shadow DOM, so this component needs no per-mode dark refinement. The
 * former dark override (a --tone-* background re-set and/or a fake outline / glow
 * that faked elevation on the old flat-black canvas) is intentionally gone. */

/* 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.
 * The centred glow (0 0 4px) is an outline, not a projected shadow: it names
 * --magma-text-default, which flips with the mode, not --magma-shadow-ink, which does not. */

:host([pref-contrast='more']) {
  --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.05))
    drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.3))
    drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.3));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.05))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.3))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.3));
  }
}

/* The glow is an outline in the text ink, light on the dark page: see mds-tooltip-pref-contrast.css. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])[pref-contrast='more']),
:host([pref-theme-scheme='dark'][pref-contrast='more']) {
  --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.075))
    drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45))
    drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system'][pref-mode='dark']:not([pref-theme-scheme='light'])),
  :host([pref-contrast='system'][pref-theme-scheme='dark']) {
    --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.075))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-contrast='more'][pref-mode='system']:not([pref-theme-scheme='light'])) {
    --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.075))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45));
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :host([pref-contrast='system'][pref-mode='system']:not([pref-theme-scheme='light'])) {
    --mds-tooltip-drop-shadow: drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.075))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45))
      drop-shadow(0 0 --spacing(100) rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)) / 0.45));
  }
}

