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


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


/**
 * @prop --mds-modal-custom-closed-transform: Public. Sets the transform position of the custom window when it's outside the viewport, to it's default position
 * @prop --mds-modal-custom-window-distance: Public. Set the distance between the slotted modal window and the screen bounds
 * @prop --mds-modal-overlay-color: Set the overlay color of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`.
 * @prop --mds-modal-overlay-opacity: Set the overlay color opacity of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`.
 * @prop --mds-modal-transition-duration: Sets the `transition-duration` of the modal elements
 * @prop --mds-modal-transition-timing-function: Sets the `transition-timing-function` of the modal elements
 * @prop --mds-modal-transition-timing-funciton: Deprecated, misspelled name of `--mds-modal-transition-timing-function`; read only when that one is not set
 * @prop --mds-modal-window-background: Set the background color of the window
 * @prop --mds-modal-window-distance: Public. Set the distance between the modal window and the screen bounds
 * @prop --mds-modal-window-overflow: Public. Set the overflow of the window
 * @prop --mds-modal-window-max-width: Public. If the viewport is greather than mobile, max-width will be considered with this value;
 * @prop --mds-modal-window-min-width: Public. If the viewport is greather than mobile, min-width will be considered with this value;
 * @prop --mds-modal-window-radius: Set the border radius of the window
 * @prop --mds-modal-window-shadow: Set the box shadow of the window
 * @prop --mds-modal-z-index: Public. Set the z-index of the window when the component is opened
 */

/* ❌ Not supported
@property --mds-modal-window-shadow {
  inherits: false;
  initial-value: var(--shadow-2xl);
  syntax: "<box-shadow>";
}

@property --mds-modal-transition-timing-function {
  inherits: false;
  initial-value: var(--ease-in-out-quint);
  syntax: "<box-shadow>";
}
*/

:host {
  --mds-modal-custom-closed-transform: rotateX(10deg) rotateY(0) scale(1.25) translate(0, 10%);
  --mds-modal-custom-window-distance: --spacing(600);
  --mds-modal-overlay-color: var(--magma-overlay-color, var(--magma-backdrop-color, 0 0 0));
  --mds-modal-overlay-opacity: var(--magma-overlay-opacity, 0.5);
  --mds-modal-transition-duration: var(--duration-500, 500ms);
  --mds-modal-transition-timing-function: var(
    --mds-modal-transition-timing-funciton,
    var(--ease-in-out-quint, cubic-bezier(0.86, 0, 0.07, 1))
  );
  --mds-modal-window-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));

  /* overlay: the fields inside take the step below (#1193) */
  --magma-field-fill: var(--magma-surface-default, var(--surface-neutral-default, 242 242 242));

  /* 0px, not 0: the height subtracts it from 100dvh, and calc() cannot take a number from a
   * length; unless globals.css registers it, the window lost its height and max-height (#1143) */
  --mds-modal-window-distance: 0px;
  --mds-modal-window-height: calc(100dvh - calc(var(--mds-modal-window-distance, 0) * 2));
  --mds-modal-window-max-height: calc(100dvh - calc(var(--mds-modal-window-distance, 0) * 2));
  --mds-modal-window-overflow: auto;
  --mds-modal-window-radius: 0;
  --mds-modal-window-shadow: var(--shadow-2xl, 0 25px 50px -12px rgb(0 0 0 / 0.25));
  --mds-modal-window-max-width: 33%;
  --mds-modal-window-min-width: --spacing(10000);
  --mds-modal-z-index: var(--magma-modal-z-index, 3000);

  /* private */
  --private-modal-transition-duration: var(--mds-modal-transition-duration, var(--duration-500, 500ms));
  --private-modal-width: calc(100vw - var(--private-modal-window-close-margin));
  --private-modal-custom-opened-transform: translate(0, 0);
  --private-modal-opened-transform: none;
  --private-modal-transition-window-transform: translate(0);
  --private-modal-window-close-margin: --spacing(2000);

  /* The host is a layout-neutral wrapper; the native <dialog> is the overlay. */
  display: contents;
}

/*
 * The native dialog is the overlay: full-viewport flex container that centers
 * the window. The dim is rendered on its ::backdrop (below). Promoted to the
 * top layer by showModal(). `overlay` and `display` are transitioned with
 * `allow-discrete` so the dialog stays painted in the top layer while the outro
 * animation plays.
 */

.dialog {
  align-items: center;
  background-color: transparent;
  border: 0;
  box-sizing: border-box;

  /* The UA sheet gives a dialog `color: CanvasText`, the pure black or white of
   * the colour scheme, which breaks the inheritance from the page: everything
   * slotted in would skip the semantic layer, contrast preference and theme
   * retint included. */
  color: inherit;
  display: none;
  fill: rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  height: auto;
  inset: 0;
  justify-content: center;
  margin: 0;
  max-height: none;
  max-width: none;

  /* Clip the window while it sits off-screen at translate(100%): without this
   * the dialog shows a transient scrollbar during the slide, shifting the
   * layout - the "jump" seen with tall content. `clip`, not `hidden`: hidden
   * still makes the dialog a scroll container, and the focus that showModal()
   * and show() move to the first focusable element of the window scrolled it
   * into view, by exactly the starting transform, so the window began already
   * in its place and never slid in (#1019). clip makes no scroll container:
   * nothing can scroll the dialog. */
  overflow: clip;
  padding: 0;
  perspective: --spacing(15000);
  position: fixed;
  transition-behavior: allow-discrete;
  transition-duration: var(--private-modal-transition-duration);
  transition-property: overlay, display;
  transition-timing-function: var(--mds-modal-transition-timing-function);
  width: auto;
  z-index: var(--mds-modal-z-index, 1000);
}

.dialog[open] {
  display: flex;
}

/*
 * The dim lives on the native ::backdrop (it exists only for modal dialogs, so
 * only when [backdrop] is set / showModal). This is its closed/outro state and
 * the value the entry transition starts from; the open value is in opened.css.
 */

.dialog::backdrop {
  background-color: rgb(var(--mds-modal-overlay-color, var(--magma-overlay-color, var(--magma-backdrop-color, 0 0 0))) / 0);
  transition-behavior: allow-discrete;
  transition-duration: var(--private-modal-transition-duration);
  transition-property: background-color, overlay, display;
  transition-timing-function: var(--mds-modal-transition-timing-function);
}

/* hide-backdrop: keep the page behind interactive (legacy click-through). */

:host([hide-backdrop]) .dialog {
  pointer-events: none;
}

.action-close {
  --mds-button-color: rgb(var(--magma-on-backdrop, 252 252 252));

  opacity: 0;
  pointer-events: none;
  position: absolute;
  transition-duration: var(--private-modal-transition-duration);
  transition-property: background-color, bottom, color, fill, opacity, top, transform;
  transition-timing-function: var(--mds-modal-transition-timing-function);
}

.action-close::part(icon) {
  height: --spacing(900);
  width: --spacing(900);
}

/*
  x - -
  - - -
  - - -
*/

:host([position='top-left'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(22deg) rotateY(22deg) scale(0.5)
    translate(-80%, 80%);
}

/*
  - x -
  - - -
  - - -
*/

:host([position='top'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(-22deg) rotateY(0) scale(0.5)
    translate(0, -80%);
}

/*
  - - x
  - - -
  - - -
*/

:host([position='top-right'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(-22deg) rotateY(-22deg) scale(0.5)
    translate(80%, 80%);
}

/*
  - - -
  x - -
  - - -
*/

:host([position='left'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(0) rotateY(22deg) rotateZ(0) scale(0.5)
    translate(-100%, 0%);
}

/*
  - - -
  - x -
  - - -
*/

:host([position='center'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(0) rotateY(22deg) scale(0.5)
    translate(0, 40%);
}

/*
  - - -
  - - x
  - - -
*/

:host([position='right'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(0) rotateY(-22deg) rotateZ(0) scale(0.5)
    translate(100%, 0%);
}

/*
  - - -
  - - -
  x - -
*/

:host([position='bottom-left'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(22deg) rotateY(22deg) scale(0.5)
    translate(-80%, 80%);
}

/*
  - - -
  - - -
  - x -
*/

:host([position='bottom'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(22deg) rotateY(0) scale(0.5)
    translate(0, 80%);
}

/*
  - - -
  - - -
  - - x
*/

:host([position='bottom-right'][animation='3d']) {
  --private-modal-transition-window-transform: rotateX(-22deg) rotateY(-22deg) scale(0.5)
    translate(80%, 80%);
}

:host([animation='custom']) {
  --private-modal-opened-transform: var(--private-modal-custom-opened-transform);
  --private-modal-transition-window-transform: var(--mds-modal-custom-closed-transform, rotateX(10deg) rotateY(0) scale(1.25) translate(0, 10%));
}

/*
  x - -
  - - -
  - - -
*/

:host([position='top-left'][animation='slide']) {
  --private-modal-transition-window-transform: translate(-50%, -100%);
}

/*
  - x -
  - - -
  - - -
*/

:host([position='top'][animation='slide']) {
  --private-modal-transition-window-transform: translate(0, -100%);
}

/*
  - - x
  - - -
  - - -
*/

:host([position='top-right'][animation='slide']) {
  --private-modal-transition-window-transform: translate(50%, -100%);
}

/*
  - - -
  x - -
  - - -
*/

:host([position='left'][animation='slide']) {
  --private-modal-transition-window-transform: translate(-100%, 0%);
}

/*
  - - -
  - x -
  - - -
*/

:host([position='center'][animation='slide']) {
  --private-modal-transition-window-transform: translate(0, 25%);
}

/*
  - - -
  - - x
  - - -
*/

:host([position='right'][animation='slide']) {
  --private-modal-transition-window-transform: translate(100%, 0%);
}

/*
  - - -
  - - -
  x - -
*/

:host([position='bottom-left'][animation='slide']) {
  --private-modal-transition-window-transform: translate(-50%, 100%);
}

/*
  - - -
  - - -
  - x -
*/

:host([position='bottom'][animation='slide']) {
  --private-modal-transition-window-transform: translateY(50%);
}

/*
  - - -
  - - -
  - - x
*/

:host([position='bottom-right'][animation='slide']) {
  --private-modal-transition-window-transform: translate(50%, 100%);
}

/* Open state of the native backdrop dim. ::backdrop only renders for modal
 * dialogs (showModal), i.e. when [backdrop] is set, so no extra guard needed. */

.dialog[open]::backdrop {
  background-color: rgb(var(--mds-modal-overlay-color, var(--magma-overlay-color, var(--magma-backdrop-color, 0 0 0))) / var(--mds-modal-overlay-opacity, var(--magma-overlay-opacity, 0.5)));
}

/* Fade the dim in when the dialog enters the top layer. */

@starting-style {
  .dialog[open]::backdrop {
    background-color: rgb(var(--mds-modal-overlay-color, var(--magma-overlay-color, var(--magma-backdrop-color, 0 0 0))) / 0);
  }
}

/* widths/dialog (#1189): the window of a dialog is at most the column of a form plus its inset, so
   its body is the column of the page and a form keeps its shape in it; a narrower screen shrinks
   it. A bespoke window writes its own width with a class: from the light DOM it wins over this
   default */

:host ::slotted([slot='window']) {
  margin: var(--mds-modal-custom-window-distance, --spacing(600));
  max-width: var(--magma-width-dialog, calc(var(--magma-width-form, var(--magma-width-reading, 56ch)) + 2 * var(--magma-rhythm-inset, 24px)));
  width: 100%;
}

.window {
  background-color: var(--mds-modal-window-background, rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  border-radius: var(--mds-modal-window-radius, 0);
  box-shadow: var(--mds-modal-window-shadow);
  box-sizing: border-box;
  display: grid;
  gap: 0;
  grid-template-columns: repeat(1, minmax(0, 100%));
  margin: var(--mds-modal-window-distance, 0);
  overflow: var(--mds-modal-window-overflow, auto);
  position: relative;
}

.window-content--empty {
  display: none;
}

/* `overflow` here is the closed/initial state. While the window's transform is
 * animating, the component freezes this to `hidden` inline and restores it on
 * the transform's `transitionend` (a live overflow:auto with overflowing
 * content janks the transform). See setContentOverflow in the component.
 *
 * The max height is the window's own: a window as tall as its content sizes
 * this box before its max height applies, and a box taller than the window
 * made the window scroll too, with the end of the content under its bottom
 * edge (#1160, top and bottom on a narrow screen). */

.window-content-wrapper {
  max-height: var(--mds-modal-window-max-height);
  overflow: hidden;
}

.window-header,
.window-footer {
  box-sizing: border-box;
  position: absolute;
}

.window-header {
  inset: 0 0 auto;
}

.window-footer {
  inset: auto 0 0;
}

/* .window--top {
  grid-template-rows: auto 1fr;
}

.window--bottom {
  grid-template-rows: 1fr auto;
}

.window--top-bottom {
  grid-template-rows: auto 1fr auto;
} */

/*
 * Closed / outro state (also the value the entry transition starts from).
 * Keyed on the native `.dialog[open]` (synchronous) rather than the reflected
 * `:host([opened])` (one tick late), so `@starting-style` matches the frame the
 * window first renders and the slide actually plays instead of popping.
 */

.dialog .window,
.dialog ::slotted([slot='window']) {
  opacity: 0;
  transform: var(--private-modal-transition-window-transform);
  transition-duration: var(--private-modal-transition-duration);
  transition-property: transform, opacity;
  transition-timing-function: var(--mds-modal-transition-timing-function);
}

/* Open / resting state. Resting transform comes from a variable (`none` by
 * default, a caller-defined transform for the custom animation) so the custom
 * override can stay a `:host()`-only rule and avoid a `:host(...) .descendant`
 * selector list, which the CSS compiler mangles. */

.dialog[open] .window,
.dialog[open] ::slotted([slot='window']) {
  opacity: 1;
  pointer-events: auto;
  transform: var(--private-modal-opened-transform);
}

/* Entry: start from the closed transform when the dialog enters the top layer. */

@starting-style {
  .dialog[open] .window,
  .dialog[open] ::slotted([slot='window']) {
    opacity: 0;
    transform: var(--private-modal-transition-window-transform);
  }

  .window-content-wrapper {
    overflow: hidden;
  }
}

.window {
  height: var(--mds-modal-window-height);
  max-height: var(--mds-modal-window-max-height);
  max-width: var(--private-modal-width);
  min-width: var(--mds-modal-window-min-width, --spacing(10000));
  width: 100%;
}

/*
 * Flex alignment of the window inside the overlay. The host is `display: contents`,
 * so the alignment lives on the native dialog (the flex container). The existing
 * `:host([position=...])` align rules below become inert on a display:contents host.
 */

:host([position='top-left']) .dialog,
:host([position='top']) .dialog,
:host([position='top-right']) .dialog {
  align-items: flex-start;
}

:host([position='left']) .dialog,
:host([position='center']) .dialog,
:host([position='right']) .dialog {
  align-items: center;
}

:host([position='bottom-left']) .dialog,
:host([position='bottom']) .dialog,
:host([position='bottom-right']) .dialog {
  align-items: flex-end;
}

:host([position='top-left']) .dialog,
:host([position='left']) .dialog,
:host([position='bottom-left']) .dialog {
  justify-content: flex-start;
}

:host([position='top']) .dialog,
:host([position='center']) .dialog,
:host([position='bottom']) .dialog {
  justify-content: center;
}

:host([position='top-right']) .dialog,
:host([position='right']) .dialog,
:host([position='bottom-right']) .dialog {
  justify-content: flex-end;
}

/*
  x - -
  - - -
  - - -
*/

:host([position='top-left']) {
  align-items: flex-start;
  justify-content: flex-start;
}

/*
  - x -
  - - -
  - - -
*/

:host([position='top']) {
  align-items: flex-start;
  justify-content: center;
}

:host([position='top']) .window {
  --mds-modal-window-max-width: 100vw;
  --mds-modal-window-height: auto;
}

/*
  - - x
  - - -
  - - -
*/

:host([position='top-right']) {
  align-items: flex-start;
  justify-content: flex-end;
}

/*
  - - -
  x - -
  - - -
*/

:host([position='left']) {
  align-items: center;
  justify-content: flex-start;
}

:host([position='left']) .action-close {
  right: --spacing(300);
  top: --spacing(300);
}

:host([position='left'][opened]) .action-close {
  opacity: 1;
  pointer-events: auto;
}

:host([position='left']:not([opened])) .action-close {
  transform: translateX(-120%) rotate(-45deg);
}

:host([position='left']),
:host([position='right']) {
  --mds-modal-window-height: 100%;
}

/*
  - - -
  - x -
  - - -
*/

:host([position='center']) {
  align-items: center;
  justify-content: center;
}

/*
  - - -
  - - x
  - - -
*/

:host([position='right']) {
  align-items: center;
  justify-content: flex-end;
}

:host([position='right']) .action-close {
  left: --spacing(300);
  top: --spacing(300);
}

:host([position='right']:not([opened])) .action-close {
  transform: translateX(120%) rotate(45deg);
}

:host([position='right'][opened]) .action-close {
  opacity: 1;
  pointer-events: auto;
}

@media (width <= 480px) {
  :host {
    --mds-modal-window-min-width: 0px;
  }

  :host([position='bottom']),
  :host([position='bottom-left']),
  :host([position='bottom-right']),
  :host([position='center']),
  :host([position='top']),
  :host([position='top-left']),
  :host([position='top-right']) {
    --private-modal-width: 100vw;
  }

  :host([position='left']),
  :host([position='right']) {
    --private-modal-width: calc(100% - var(--private-modal-window-close-margin));
  }

  /* The windows that fill the screen here leave a strip of backdrop at the top, as the side
   * positions leave one at their side: the built-in close button sits in it, and a tap on it
   * closes a relaxed modal. Without it a phone could close them only from their content or
   * with Esc (#1143). top and bottom are as tall as their content, the backdrop around them. */

  :host([position='bottom-left']),
  :host([position='bottom-right']),
  :host([position='center']),
  :host([position='top-left']),
  :host([position='top-right']) {
    --mds-modal-window-height: calc(
      100dvh - var(--private-modal-window-close-margin) - var(--mds-modal-window-distance, 0) * 2
    );
    --mds-modal-window-max-height: var(--mds-modal-window-height);
  }

  :host([position='bottom-left']) .dialog,
  :host([position='bottom-right']) .dialog,
  :host([position='center']) .dialog,
  :host([position='top-left']) .dialog,
  :host([position='top-right']) .dialog {
    align-items: flex-end;
  }

  /* top and bottom stay as tall as their content, but never taller than the screen less the
   * strip, which stays on their free side: a tall content covered the whole screen, with the close
   * button hidden (#1160). The button sits in the strip at the edge of the screen, for bottom at
   * the top right as for the windows above, for top at the bottom right. */

  :host([position='bottom']),
  :host([position='top']) {
    --mds-modal-window-max-height: calc(
      100dvh - var(--private-modal-window-close-margin) - var(--mds-modal-window-distance, 0) * 2
    );
  }

  :host([position='bottom']) .action-close,
  :host([position='bottom-left']) .action-close,
  :host([position='bottom-right']) .action-close,
  :host([position='center']) .action-close,
  :host([position='top-left']) .action-close,
  :host([position='top-right']) .action-close {
    right: --spacing(300);
    top: --spacing(300);
  }

  :host([position='top']) .action-close {
    bottom: --spacing(300);
    right: --spacing(300);
  }

  :host([position='bottom'][opened]) .action-close,
  :host([position='bottom-left'][opened]) .action-close,
  :host([position='bottom-right'][opened]) .action-close,
  :host([position='center'][opened]) .action-close,
  :host([position='top'][opened]) .action-close,
  :host([position='top-left'][opened]) .action-close,
  :host([position='top-right'][opened]) .action-close {
    opacity: 1;
    pointer-events: auto;
  }

  :host([position='bottom']:not([opened])) .action-close,
  :host([position='bottom-left']:not([opened])) .action-close,
  :host([position='bottom-right']:not([opened])) .action-close,
  :host([position='center']:not([opened])) .action-close,
  :host([position='top-left']:not([opened])) .action-close,
  :host([position='top-right']:not([opened])) .action-close {
    transform: translateY(-120%) rotate(45deg);
  }

  :host([position='top']:not([opened])) .action-close {
    transform: translateY(120%) rotate(-45deg);
  }
}

@media (width > 480px) {
  :host([position='bottom']),
  :host([position='bottom-left']),
  :host([position='bottom-right']),
  :host([position='center']),
  :host([position='top']),
  :host([position='top-left']),
  :host([position='top-right']) {
    --mds-modal-window-height: auto;
  }

  :host([position='left']),
  :host([position='right']) {
    --private-modal-width: var(--mds-modal-window-max-width, 33%);
  }

  /* Every window leaves a strip of backdrop at its side, as left and right do, with the close
   * button at the top of it: it was hidden, and a strict modal had nothing else to be closed by
   * (#1160). The corners already leave the strip on the side away from their own; center, top and
   * bottom leave one on each side, where the 40px they left were too few for the button. */

  :host([position='bottom']),
  :host([position='center']),
  :host([position='top']) {
    --private-modal-width: calc(100vw - var(--private-modal-window-close-margin) * 2);
  }

  :host([position='bottom']) .action-close,
  :host([position='bottom-left']) .action-close,
  :host([position='center']) .action-close,
  :host([position='top']) .action-close,
  :host([position='top-left']) .action-close {
    right: --spacing(300);
    top: --spacing(300);
  }

  :host([position='bottom-right']) .action-close,
  :host([position='top-right']) .action-close {
    left: --spacing(300);
    top: --spacing(300);
  }

  :host([position='bottom'][opened]) .action-close,
  :host([position='bottom-left'][opened]) .action-close,
  :host([position='bottom-right'][opened]) .action-close,
  :host([position='center'][opened]) .action-close,
  :host([position='top'][opened]) .action-close,
  :host([position='top-left'][opened]) .action-close,
  :host([position='top-right'][opened]) .action-close {
    opacity: 1;
    pointer-events: auto;
  }

  :host([position='bottom']:not([opened])) .action-close,
  :host([position='bottom-left']:not([opened])) .action-close,
  :host([position='center']:not([opened])) .action-close,
  :host([position='top']:not([opened])) .action-close,
  :host([position='top-left']:not([opened])) .action-close {
    transform: translateY(-120%) rotate(45deg);
  }

  :host([position='bottom-right']:not([opened])) .action-close,
  :host([position='top-right']:not([opened])) .action-close {
    transform: translateY(-120%) rotate(-45deg);
  }
}

/*
  x - -
  - - -
  - - -
*/

:host([position='top-left']) {
  align-items: flex-start;
  justify-content: flex-start;
}

/*
  - x -
  - - -
  - - -
*/

:host([position='top']) {
  --mds-modal-window-height: auto;

  align-items: flex-start;
  justify-content: center;
}

/*
  - - x
  - - -
  - - -
*/

:host([position='top-right']) {
  align-items: flex-start;
  justify-content: flex-end;
}

:host([position='right']),
:host([position='left']) {
  --mds-modal-window-height: 100%;
  --mds-modal-window-max-height: calc(100dvh - calc(var(--mds-modal-window-distance, 0) * 2));
}

/*
  - - -
  x - -
  - - -
*/

:host([position='left']) {
  align-items: center;
  justify-content: flex-start;
}

:host([position='left']) .action-close {
  right: --spacing(300);
  top: --spacing(300);
}

:host([position='left'][opened]) .action-close {
  opacity: 1;
  pointer-events: auto;
}

:host([position='left']:not([opened])) .action-close {
  transform: translateX(-120%) rotate(-45deg);
}

/*
  - - -
  - x -
  - - -
*/

:host([position='center']) {
  align-items: center;
  justify-content: center;
}

/*
  - - -
  - - x
  - - -
*/

:host([position='right']) {
  align-items: center;
  justify-content: flex-end;
}

:host([position='right']) .action-close {
  left: --spacing(300);
  top: --spacing(300);
}

:host([position='right']:not([opened])) .action-close {
  transform: translateX(120%) rotate(45deg);
}

:host([position='right'][opened]) .action-close {
  opacity: 1;
  pointer-events: auto;
}

/*
  - - -
  - - -
  x - -
*/

:host([position='bottom-left']) {
  align-items: flex-end;
  justify-content: flex-start;
}

/*
  - - -
  - - -
  - x -
*/

:host([position='bottom']) {
  --mds-modal-window-height: auto;

  align-items: flex-end;
  justify-content: center;
}

/*
  - - -
  - - -
  - - x
*/

:host([position='bottom-right']) {
  align-items: flex-end;
  justify-content: flex-end;
}

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

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

/* 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-modal-window-shadow: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6)), var(--shadow-2xl, 0 25px 50px -12px rgb(0 0 0 / 0.25));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-modal-window-shadow: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6)), var(--shadow-2xl, 0 25px 50px -12px rgb(0 0 0 / 0.25));
  }
}

/* Theme preference. Surface and elevation now come from the semantic layer
 * (--magma-surface-overlay + the base --shadow-2xl, spec 6.1), which flips per
 * mode at :root, so the former dark background re-set and fake outline are gone.
 * The close icon still needs a dark-mode value: it sits over the dark scrim, not
 * over the modal surface, so it does not follow the surface flip. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  .action-close {
    --mds-button-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    .action-close {
      --mds-button-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
    }
  }
}

