@layer components {
  :root {
    --modal-min-width: 320px;
    --modal-margin: 2rem;
    --modal-padding: 2rem;
    --modal-mobile-padding: 1rem;
    --modal-mobile-margin: 0rem;
    --modal-hero-width: 18rem;
    --modal-scale: 0.95;
    --modal-mobile-hero-height: 150px;
    --modal-mobile-max-height: 90vh;
    --modal-backdrop-blur: 4px;
    --modal-backdrop-color: rgba(0, 0, 0, 0.3);

    --modal-animation-duration: var(--duration-speed-slow);

    --modal-radius: var(--radius-site);
    --modal-box-shadow: var(--shadow-site);
    --modal-mobile-shadow: var(--shadow-site);
  }

  dialog.modal-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    background-color: transparent;
    padding: 0;
    border: none;
    margin: 0;
    overflow: hidden;
    will-change: opacity;
    transition: opacity var(--modal-animation-duration) ease;
  }

  dialog.modal-dialog::backdrop {
    background-color: var(--modal-backdrop-color);
    -webkit-backdrop-filter: blur(var(--modal-backdrop-blur));
    backdrop-filter: blur(var(--modal-backdrop-blur));
    opacity: 0;
    transition: opacity var(--modal-animation-duration) ease;
  }

  dialog.modal-dialog[open] {
    opacity: 1;
    visibility: visible;
  }

  dialog.modal-dialog[open]::backdrop {
    opacity: 1;
  }

  dialog.modal-dialog[open] .modal-container {
    transform: scale(1);
  }

  dialog .modal-container {
    width: min(fit-content, calc(100vw - (var(--modal-margin) * 2)));
    min-width: var(--modal-min-width);
    border-radius: var(--modal-radius);
    box-shadow: var(--modal-box-shadow);
    max-height: calc(100vh - 1rem var(--modal-margin));
    overflow: visible;
    position: relative;
    transform: scale(var(--modal-scale));
    transition: all var(--modal-animation-duration) ease;
    z-index: 2;
    display: flex;
    flex-direction: column;
    margin: 0;
    max-height: 100%;
    will-change: transform;
  }

  .modal-control-bar {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 1rem;
    margin-top: -0.5rem;
  }

  .modal-backdrop {
    position: fixed;
    inset: 0;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .modal-backdrop button {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    appearance: none;
    border: none;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: pointer;
  }

  .modal-body:last-child {
    padding-bottom: 0;
  }

  dialog .modal-container.modal-container--with-hero {
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow: visible;
  }

  dialog .modal-container--with-hero .modal-hero-image {
    width: var(--modal-hero-width);
    height: 100%;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    object-fit: cover;
    border-top-left-radius: var(--modal-radius);
    border-bottom-left-radius: var(--modal-radius);
  }

  dialog .modal-container > div:last-child {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: var(--modal-padding);
  }

  dialog .modal-container:has(.modal-close) > div:last-child {
    padding-top: calc(var(--modal-padding) + 1rem);
  }

  dialog.modal-dialog.modal-disable-backdrop::backdrop {
    background-color: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  dialog.modal-dialog.modal-fullscreen {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    transform: translate(-50%, -50%);
    padding: 0;
    margin: 0;
  }

  dialog.modal-fullscreen .modal-container {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    min-width: 100vw;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  dialog.modal-fullscreen .modal-container--with-hero {
    height: 100vh;
    max-height: 100vh;
  }

  dialog.modal-dialog.modal-disable-entrance .modal-container {
    transform: none;
  }

  dialog.modal-dialog.modal-disable-entrance[open] .modal-container {
    transform: none;
  }

  .modal-header {
    position: absolute;
    top: var(--modal-mobile-padding);
    right: var(--modal-mobile-padding);
    z-index: 3;
    margin: 0;
    padding: 0;
  }

  .modal-close {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: color var(--modal-animation-duration) ease;
    position: absolute;
    top: calc(1rem - var(--modal-mobile-padding));
    right: 0;
  }

  @media screen and (max-width: 640px) {
    dialog.modal-dialog {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      top: auto;
      transform: none;
      align-items: flex-end;
      padding: 0;
      width: 100%;
      max-width: 100%;
      margin: 0;
    }

    dialog
      .modal-container:has(.modal-close):not(:has(.modal-hero-image))
      > div:last-child {
      padding: 0;
    }

    dialog
      .modal-container:has(.modal-close):has(.modal-hero-image)
      > div:last-child {
      padding: var(--modal-mobile-padding);
    }

    .modal-close {
      top: calc(-0.125 * (var(--modal-mobile-padding) + 1rem));
    }

    dialog .modal-container {
      width: 100%;
      margin: 0 var(--modal-mobile-margin);
      max-height: var(--modal-mobile-max-height);
      border-radius: var(--modal-radius) var(--modal-radius) 0 0;
      transform: translateY(100%);
      box-shadow: var(--modal-mobile-shadow);
      padding: calc(var(--modal-mobile-padding) + 2rem)
        var(--modal-mobile-padding) var(--modal-mobile-padding)
        var(--modal-mobile-padding);
    }

    dialog.modal-dialog[open] .modal-container {
      transform: translateY(0);
    }

    dialog .modal-container.modal-container--with-hero {
      flex-direction: column;
      max-height: var(--modal-mobile-max-height);
      padding: 0;
    }

    dialog .modal-container--with-hero .modal-hero {
      padding-top: calc(2 * var(--modal-mobile-padding) + 1rem);
    }

    dialog .modal-container--with-hero .modal-control-bar {
      position: sticky;
      top: 0;
      right: auto;
      width: 100%;
      padding: var(--modal-mobile-padding);
    }

    dialog .modal-container--with-hero > div:first-child {
      width: 100%;
    }

    dialog .modal-hero-image {
      width: 100%;
      height: var(--modal-mobile-hero-height);
      object-fit: cover;
      border-radius: 0px;
    }

    dialog .modal-container--with-hero .modal-hero-image {
      width: 100%;
      height: var(--modal-mobile-hero-height);
      object-fit: cover;
      border-radius: 0;
    }

    dialog .modal-container--with-hero > div:last-child {
      padding: var(--modal-mobile-padding);
    }

    dialog.modal-dialog.modal-fullscreen-mobile {
      position: fixed;
      top: 50%;
      left: 50%;
      right: 0;
      bottom: 0;
      width: 100vw;
      height: 100vh;
      max-width: 100vw;
      max-height: 100vh;
      transform: translate(-50%, -50%);
    }

    dialog.modal-fullscreen-mobile .modal-container {
      width: 100vw;
      height: 100vh;
      max-height: 100vh;
      min-width: 100vw;
      margin: 0;
      border-radius: 0;
      box-shadow: none;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      padding: var(--modal-mobile-padding);
    }

    dialog.modal-fullscreen-mobile .modal-container--with-hero {
      height: 100vh;
      max-height: 100vh;
    }

    dialog.modal-disable-entrance .modal-container {
      transform: none;
    }

    dialog.modal-disable-entrance[open] .modal-container {
      transform: none;
    }

    dialog .modal-header {
      position: absolute;
      top: var(--modal-mobile-padding);
      right: var(--modal-mobile-padding);
    }

    dialog .modal-container--with-hero .modal-header {
      position: absolute;
      top: var(--modal-mobile-padding);
      right: var(--modal-mobile-padding);
      width: auto;
      background: transparent;
      z-index: 4;
    }
  }
}
