/* Dialog shell – a native <dialog> that fills the screen, dims the page and animates its panel in and out.
   .dlg          the <dialog>; scrolls when the panel is taller than the screen
   .dlg__panel   the panel; its width comes from --dlg-w, the content component styles the inside
   .dlg__close   round close button in the panel's top right corner
   dialog.js adds .is-open after showModal() and removes it before close(), so both directions animate.
   On phones the panel fills the screen and slides up. */

html:has(.dlg[open]) {
  overflow: hidden;
}

.dlg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: var(--gutter);
  border: 0;
  display: grid;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgb(10 12 15 / 0);
  transition:
    background-color var(--dur-base) var(--ease-exit),
    -webkit-backdrop-filter var(--dur-base) var(--ease-exit),
    backdrop-filter var(--dur-base) var(--ease-exit);
}

.dlg:not([open]) {
  display: none;
}

.dlg::backdrop {
  background: transparent;
}

.dlg.is-open {
  background: rgb(10 12 15 / 0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition-timing-function: var(--ease-out);
}

.dlg__panel {
  position: relative;
  width: min(100%, var(--dlg-w, 880px));
  margin: auto;
  /* Never stretched to the screen height: a taller panel must grow and let the dialog scroll */
  align-self: start;
  border-radius: 3px;
  overflow: clip; /* clips like hidden, but sticky parts inside still stick to the scrolling dialog */
  box-shadow: 0 0 0 1px rgb(10 12 15 / 0.06), 0 60px 110px -50px rgb(10 12 15 / 0.65);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition:
    opacity var(--dur-base) var(--ease-exit),
    transform var(--dur-base) var(--ease-exit);
}

.dlg.is-open .dlg__panel {
  opacity: 1;
  transform: none;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-slow) var(--ease-emphasis);
}

.dlg__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.dlg__close:hover {
  background: var(--bg-raised);
  color: var(--fg);
}

.dlg__close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--accent), 0 0 16px 3px var(--accent-glow);
}

.dlg__close svg {
  width: 20px;
  height: 20px;
}

@media (max-width: 560px) {
  .dlg {
    padding: 0;
  }

  .dlg__panel {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(40px);
  }

  .dlg__close {
    top: calc(12px + env(safe-area-inset-top, 0px));
  }
}
