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


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


/**
 * @prop --mds-header-backdrop-background-image: Public. Sets the background-image of the backdrop element visibile when the component attribute `appearance` is set to `inline`, by default is shown when mds-pref-consumtion is set to `medium`
 * @prop --mds-header-backdrop-blur-strength: Sets the blur strength of the backdrop element visibile when the component attribute `appearance` is set to `inline`, by default is shown when mds-pref-consumtion is set to `high`
 * @prop --mds-header-backdrop-height: Sets the height of the backdrop element visibile when the component attribute `appearance` is set to `inline`
 * @prop --mds-header-backdrop-show: Sets if the backdrop element is visible or not, only visible when the component attribute `appearance` is set to `inline`
 * @prop --mds-header-color: Public. Sets the text color of the header and the color of its icons, the hamburger toggler of `mds-header-bar` included
 * @prop --mds-header-hidden-bar-translate-inline: Sets translateY value for the appearance inline `mds-header-bar` element
 * @prop --mds-header-hidden-bar-translate-stripe: Sets translateY value for the appearance stripe `mds-header-bar` element
 * @prop --mds-header-icon-color: Sets the color of the icons of the header, the hamburger toggler of `mds-header-bar` included
 * @prop --mds-header-inline-margin-mobile: Public. Sets inline margin on mobile viewport of `the mds-header-bar` when attribute `appearance` is set to `inline`
 * @prop --mds-header-inline-margin: Public. Sets inline margin of `the mds-header-bar` when attribute `appearance` is set to `inline`
 * @prop --mds-header-z-index: Public. Sets the z-index of the modal
 */

/* ❌ Not supported: transform values cannot be validated by @property
@property --mds-header-hidden-bar-translate-inline {
  inherits: false;
  syntax: "<transform-function>";
  initial-value: translateY(-150%);
}

@property --mds-header-hidden-bar-translate-stripe {
  inherits: false;
  syntax: "<transform-function>";
  initial-value: translateY(-110%);
}
*/

/* ❌ Not supported: gradients are not supported in @property
@property --mds-header-backdrop-background-image {
  inherits: false;
  syntax: "<image>";
  initial-value: linear-gradient(to top, rgb(0 0 0 / 0), rgb(0 0 0 / 0.15));
}
*/

:host {
  --mds-header-hidden-bar-translate-inline: translateY(-150%);
  --mds-header-hidden-bar-translate-stripe: translateY(-110%);
  --mds-header-modal-icon-color: rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-header-backdrop-blur-strength: --spacing(50);
  --mds-header-backdrop-height: --spacing(1600);
  --mds-header-backdrop-show: true;
  --mds-header-z-index: var(--magma-header-z-index, 1000);
  --mds-header-inline-margin-mobile: --spacing(400);
  --mds-header-inline-margin: --spacing(600);
  --mds-header-backdrop-background-image: linear-gradient(
    to top,
    rgb(var(--magma-backdrop-color, 0 0 0) / 0),
    rgb(var(--magma-backdrop-color, 0 0 0) / 0.15)
  );

  /* private custom properties */
  --private-mask-opacity: 1;

  /* --mds-header-color and --mds-header-icon-color have no default on this host: mds-header-bar
     reads them through a fallback for its hamburger, which keeps its own default colour, and a
     value declared here would always win that fallback */
  color: var(--mds-header-color, rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5))));

  /* the header stands in the flow and stays put while the page scrolls (#1189, surfaces/band):
     the page starts under its bar, with no number to keep in step with its height. Sticky holds
     inside the box of the parent, so it is the host, the child of the page, that sticks; its own
     box holds the margins of the floating bar (flow-root) */
  display: flow-root;
  fill: var(--mds-header-icon-color, var(--mds-header-color, rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))));

  /* the box of the header lets the clicks through: around the floating bar and where the hidden
     bar was (auto-hide), only what it draws takes them */
  pointer-events: none;
  position: sticky;
  top: 0;
  z-index: var(--mds-header-z-index);
}

::slotted(*),
.backdrop,
.menu {
  pointer-events: auto;
}

.modal {
  --mds-modal-close-icon-color: var(--mds-header-modal-icon-color, rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255))));

  z-index: var(--mds-header-z-index);
}

:host([appearance='inline']) ::slotted(mds-header-bar) {
  --mds-header-inline-margin-current: var(--mds-header-inline-margin, --spacing(600));

  border-radius: var(--magma-radius-lg, var(--radius-squircle-lg, 28px));
  corner-shape: var(--magma-corner-shape, squircle);

  /* the room of the header is its bar alone, whatever its appearance: the floating bar stands its
     margin lower, over the space under the header, so the page never moves when appearance-set
     changes the appearance on scroll */
  margin-bottom: calc(var(--mds-header-inline-margin-current) * -1);
  margin-top: var(--mds-header-inline-margin-current);

  /* the content of the floating bar stands on the frame of the page, its padding outside it
     (#1189, widths/page): on a wide window it starts where the content of a page-frame does */
  max-width: var(--magma-width-page, 1280px);
  width: calc(100% - calc(var(--mds-header-inline-margin-current) * 2));
}

@media (width <= 767px) {
  :host([appearance='inline']) ::slotted(mds-header-bar) {
    --mds-header-inline-margin-current: var(--mds-header-inline-margin-mobile, --spacing(400));
  }
}

:host([menu='desktop']) .menu {
  @apply max-tablet:hidden;
}

:host([menu='mobile']) .menu {
  @apply desktop:hidden;
}

:host([menu='none']) .menu {
  display: none;
}

:host([visibility='hidden'][appearance='stripe']) ::slotted(mds-header-bar) {
  transform: var(--mds-header-hidden-bar-translate-stripe);
}

:host([visibility='hidden'][appearance='inline']) ::slotted(mds-header-bar) {
  transform: var(--mds-header-hidden-bar-translate-inline);
}

.backdrop {
  align-items: center;
  -webkit-backdrop-filter: blur(var(--mds-header-backdrop-blur-strength, --spacing(250)));
          backdrop-filter: blur(var(--mds-header-backdrop-blur-strength, --spacing(250)));
  background-image: var(--mds-header-backdrop-background-image);
  content: '';
  display: flex;
  height: var(--mds-header-backdrop-height, --spacing(1600));
  inset: 0;
  opacity: 1;
  position: fixed;
  transform: translate(0, 0);
  transition-duration: var(--duration-200, 200ms);
  transition-property: opacity, transform;
  width: 100%;
}

.backdrop-blur-item {

  /* https://caniuse.com/?search=sibling-count actually 75% (not good) */
  --private-gradient-position: calc(100% - calc(calc(sibling-count() - sibling-index()) * 5%));

  display: none;

  &:nth-child(1) {
    --private-gradient-position: 100%;
  }

  &:nth-child(2) {
    --private-gradient-position: 95%;
  }

  &:nth-child(3) {
    --private-gradient-position: 90%;
  }

  &:nth-child(4) {
    --private-gradient-position: 85%;
  }

  &:nth-child(5) {
    --private-gradient-position: 80%;
  }

  &:nth-child(6) {
    --private-gradient-position: 75%;
  }

  &:nth-child(7) {
    --private-gradient-position: 70%;
  }

  &:nth-child(8) {
    --private-gradient-position: 65%;
  }

  &:nth-child(9) {
    --private-gradient-position: 60%;
  }

  &:nth-child(10) {
    --private-gradient-position: 55%;
  }

  &:nth-child(11) {
    --private-gradient-position: 50%;
  }
}

@supports ((-webkit-mask-image: linear-gradient(rgb(0 0 0 / 1), transparent)) or (mask-image: linear-gradient(rgb(0 0 0 / 1), transparent))) {

  /* https://caniuse.com/?search=mask-image */

  .backdrop {
    -webkit-backdrop-filter: none;
            backdrop-filter: none;
    background-image: none;
  }

  .backdrop-blur-item {
    -webkit-backdrop-filter: blur(var(--mds-header-backdrop-blur-strength, 1px));
            backdrop-filter: blur(var(--mds-header-backdrop-blur-strength, 1px));
    display: flex;
    inset: 0;
    -webkit-mask-image: linear-gradient(
      to bottom,
      rgb(0 0 0 / var(--private-mask-opacity, 1)) 40%,
      rgb(0 0 0 / 0) var(--private-gradient-position, 100%)
    );
            mask-image: linear-gradient(
      to bottom,
      rgb(0 0 0 / var(--private-mask-opacity, 1)) 40%,
      rgb(0 0 0 / 0) var(--private-gradient-position, 100%)
    );
    pointer-events: none;
    position: absolute;
  }
}

:host([appearance='inline']) .backdrop {
  transform: translate(0, 0);
}

:host([visibility='hidden']) .backdrop,
:host([appearance='stripe']) .backdrop {
  --mds-header-backdrop-blur-strength: 0px;

  transform: translate(0, -100%);
}

@container style(--mds-header-backdrop-show: false) {
  .backdrop {
    display: none;
  }
}

/* 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-header-modal-icon-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'])) {
    --mds-header-modal-icon-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

/* Consumption preference. The component mirrors the resolved level from <html>
 * onto its host as pref-consumption (see subscribePreference in @common/preference);
 * these plain shadow selectors then trim the backdrop cost. Cross-browser, no
 * :host-context. */

:host([pref-consumption='high']) .backdrop {
  --mds-header-backdrop-background-image: none;
}

:host([pref-consumption='medium']) .backdrop {
  --mds-header-backdrop-blur-strength: 1px;
}

:host([pref-consumption='low']) .backdrop {
  --mds-header-backdrop-blur-strength: 0px;

  display: none;
}

