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


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


/**
 * @prop --mds-keyboard-background-default: `private` Set the default background color of the keyboard area.
 * @prop --mds-keyboard-background-fail: Set the background color of the keyboard area when the test fails.
 * @prop --mds-keyboard-background-pass: Set the background color of the keyboard area when the test passes.
 * @prop --mds-keyboard-background: Public. Set the background color of the keyboard area.
 * @prop --mds-keyboard-color: Public. Set the text color of the keyboard area, will impact on `mds-keyboard-key` component.
 * @prop --mds-keyboard-fill-fail: Set the fill color of the combination-checker button when the test fails.
 * @prop --mds-keyboard-fill-pass: Set the fill color of the combination-checker button when the test passes.
 * @prop --mds-keyboard-illumination-dark-opacity: Set the opacity of the dark illumination.
 * @prop --mds-keyboard-illumination-dark-size: Set the size of the dark illumination.
 * @prop --mds-keyboard-illumination-dark: Set the dark illumination.
 * @prop --mds-keyboard-illumination-light-opacity: Set the opacity of the light illumination.
 * @prop --mds-keyboard-illumination-light-size: Set the size of the light illumination.
 * @prop --mds-keyboard-illumination-light: Set the light illumination.
 * @prop --mds-keyboard-illumination-shadow: Set the shadow of the keyboard area.
 * @prop --mds-keyboard-key-background: Set the background color of the keyboard key.
 * @prop --mds-keyboard-key-illumination-dark-opacity: Set the opacity of the dark illumination of the keyboard key.
 * @prop --mds-keyboard-key-illumination-light-opacity: Set the opacity of the light illumination of the keyboard key.
 * @prop --mds-keyboard-key-illumination-shadow: Set the shadow of the keyboard key.
 * @prop --mds-keyboard-padding: Public. Set the padding of the keyboard area.
 * @prop --mds-keyboard-spinner-duration: Set the duration of the spinner animation.
 */

/* ❌ Not supported
@property --mds-keyboard-illumination-dark {
  inherits: false;
  initial-value: 0 calc(var(--mds-keyboard-illumination-dark-size) * -1) 0 0 rgb(0 0 0 / var(--mds-keyboard-illumination-dark-opacity)) inset;
  syntax: "<box-shadow>";
}

@property --mds-keyboard-illumination-light {
  inherits: false;
  initial-value: 0 var(--mds-keyboard-illumination-light-size) 0 0 rgb(255 255 255 / var(--mds-keyboard-illumination-light-opacity)) inset;
  syntax: "<box-shadow>";
}

@property --mds-keyboard-illumination-shadow {
  inherits: false;
  initial-value: 0 0 1px 0 rgb(0 0 0 / 0);
  syntax: "<box-shadow>";
}

@property --mds-keyboard-key-illumination-shadow {
  inherits: false;
  initial-value: var(--shadow-sharp);
  syntax: "<box-shadow>";
}
*/

:host {
  --mds-keyboard-background-default: var(--mds-keyboard-background, rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208))));
  --mds-keyboard-background-fail: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
  --mds-keyboard-background-pass: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
  --mds-keyboard-background: var(--private-keyboard-tray);
  --mds-keyboard-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  --mds-keyboard-fill-fail: rgb(var(--magma-danger-text-default, var(--text-error-default, 89 0 0)));
  --mds-keyboard-fill-pass: rgb(var(--magma-success-text-default, var(--text-success-default, 0 53 0)));
  --mds-keyboard-illumination-dark-opacity: 0.05;
  --mds-keyboard-illumination-dark-size: --spacing(150);
  --mds-keyboard-illumination-dark: 0 calc(var(--mds-keyboard-illumination-dark-size, --spacing(150)) * -1) 0 0
    rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / var(--mds-keyboard-illumination-dark-opacity, 0.05)) inset;
  --mds-keyboard-illumination-light-opacity: 0.075;
  --mds-keyboard-illumination-light-size: --spacing(25);

  /* stylelint-disable magma/token-values -- white light on the edge of the keys, in every theme and mode: a highlight, not a role */
  --mds-keyboard-illumination-light: 0 var(--mds-keyboard-illumination-light-size, --spacing(25)) 0 0
    rgb(255 255 255 / var(--mds-keyboard-illumination-light-opacity, 0.075)) inset;

  /* stylelint-enable magma/token-values */
  --mds-keyboard-illumination-shadow: 0 0 1px 0 rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / 0);
  --mds-keyboard-key-background: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
  --mds-keyboard-key-illumination-dark-opacity: 0.075;
  --mds-keyboard-key-illumination-light-opacity: 0.5;
  --mds-keyboard-key-illumination-shadow: var(--shadow-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-keyboard-padding: --spacing(200);
  --mds-keyboard-spinner-duration: var(--duration-1000, 1000ms);

  /* the tray and the keys are washes of the active theme, which a named theme retints: they were
     porcelain steps, the family of the cool theme, under every theme (#828) */
  --private-keyboard-tray: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));

  align-items: center;
  align-self: flex-start;
  background-color: var(--mds-keyboard-background-default, rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208))));
  border-radius: var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px));
  box-shadow:
    var(--mds-keyboard-illumination-light), var(--mds-keyboard-illumination-dark),
    var(--mds-keyboard-illumination-shadow);
  color: var(--mds-keyboard-color, rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99))));
  corner-shape: var(--magma-corner-shape, squircle);
  display: inline-flex;
  gap: --spacing(200);
  justify-self: flex-start;
  padding: calc(var(--mds-keyboard-illumination-light-size, --spacing(25)) + var(--mds-keyboard-padding, --spacing(200)))
    var(--mds-keyboard-padding, --spacing(200))
    calc(var(--mds-keyboard-illumination-dark-size, --spacing(150)) + var(--mds-keyboard-padding, --spacing(200)))
    var(--mds-keyboard-padding, --spacing(200));
  transition-duration: var(--duration-200, 200ms);
  transition-property: background-color;
  transition-timing-function: var(--ease-out-quad, cubic-bezier(0.25, 0.46, 0.45, 0.94));
  -webkit-user-select: none;
          user-select: none;
}

.errors {
  display: grid;
  gap: --spacing(100);
}

.shortcuts {
  align-items: center;
  display: inline-flex;
  gap: --spacing(100);
  outline: 0;
}

/* the tray one shade toward the ink, darker in light and lighter in dark */

:host(:focus-within) {
  --mds-keyboard-background: color-mix(
    in oklab,
    var(--private-keyboard-tray) 88%,
    rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)))
  );
}

mds-tooltip {
  --mds-tooltip-delay: 0;
}

.combination-checker {
  --mds-button-await-duration: var(--mds-keyboard-spinner-duration, var(--duration-1000, 1000ms));

  border-radius: var(--magma-radius-full, var(--radius-full, 1000px));
}

::slotted(mds-keyboard-key) {
  align-self: flex-end;
}

:host([test='pass']) {
  --mds-keyboard-background-default: var(--mds-keyboard-background-pass, rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205))));
}

:host([test='fail']) {
  --mds-keyboard-background-default: var(--mds-keyboard-background-fail, rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211))));
}

:host([test='pass']) .combination-checker {
  background-color: var(--mds-keyboard-background-pass, rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205))));
  fill: var(--mds-keyboard-fill-pass, rgb(var(--magma-success-text-default, var(--text-success-default, 0 53 0))));
}

:host([test='fail']) .combination-checker {
  background-color: var(--mds-keyboard-background-fail, rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211))));
  fill: var(--mds-keyboard-fill-fail, rgb(var(--magma-danger-text-default, var(--text-error-default, 89 0 0))));
}

/* 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.
 * In dark the two washes swap, so the keys stay lighter than the tray. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  --private-keyboard-tray: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
  --mds-keyboard-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  --mds-keyboard-illumination-dark-opacity: 0.5;
  --mds-keyboard-illumination-light-opacity: 0.15;

  /* stylelint-disable magma/token-values -- the white glow around the keyboard and its keys in dark: light, not a role */
  --mds-keyboard-illumination-shadow: 0 0 --spacing(75) 0 rgb(255 255 255 / 0.5);
  --mds-keyboard-key-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  --mds-keyboard-key-illumination-dark-opacity: 0.5;
  --mds-keyboard-key-illumination-light-opacity: 0.15;
  --mds-keyboard-key-illumination-shadow: 0 0 1px 0 rgb(255 255 255 / 0.5);

  /* stylelint-enable magma/token-values */
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --private-keyboard-tray: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
    --mds-keyboard-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
    --mds-keyboard-illumination-dark-opacity: 0.5;
    --mds-keyboard-illumination-light-opacity: 0.15;

    /* stylelint-disable magma/token-values -- the white glow around the keyboard and its keys in dark: light, not a role */
    --mds-keyboard-illumination-shadow: 0 0 --spacing(75) 0 rgb(255 255 255 / 0.5);
    --mds-keyboard-key-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
    --mds-keyboard-key-illumination-dark-opacity: 0.5;
    --mds-keyboard-key-illumination-light-opacity: 0.15;
    --mds-keyboard-key-illumination-shadow: 0 0 1px 0 rgb(255 255 255 / 0.5);

    /* stylelint-enable magma/token-values */
  }
}

