Закрыть модальное окно по клику за его пределами

const backery = document.querySelector(".backdrop3");
const backeryBtnOpen = document.querySelector(".backery-btn-open");
const backeryBtnClose = document.querySelector(".backery-btn-close");

const togglebackery = () => backery.classList.toggle("is-hidden");

backeryBtnOpen.addEventListener("click", togglebackery);
backeryBtnClose.addEventListener("click", togglebackery);

.backdrop3 {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
  background-color: rgb(0, 0, 0, 0.5);
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 3;

  &.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
}

.backery {
  position: relative;
  width: 100%;
  max-width: 880px;
  height: 100%;
  max-height: 880px;
  padding: 75px 20px 20px 20px;
  background-color: var(--color-light);
  border-radius: 32px;
  overflow-y: auto;

  &__btn-close {
    position: absolute;
    top: 40px;
    right: 40px;
    background-color: transparent;
    border: none;
  }

  &__title {
    position: relative;
    text-align: center;
    margin: 0 auto 24px;
  }

  &__list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    margin: 0 21px;
  }

  &__item {
    @media screen and (min-width: $bp-tablet) {
      flex-basis: calc((100% - 30px) / 2);
    }
  }
}

.backery-card {
  display: flex;
  align-items: flex-start;
  width: 377px;
  gap: 16px;

  &__photo {
    width: 200px;
  }

  &__title {
    margin-bottom: 16px;
    font-size: 24px;
    font-weight: 600;

    @media screen and (min-width: $bp-tablet) {
      font-size: 30px;
    }
  }

  &__text {
    font-size: 14px;
    line-height: 0.5;
  }
}

<div class="backdrop3 is-hidden">
<div class="backery">
  <button class="backery__btn-close backery-btn-close" 
  type="button">
  <svg width="32" height="32">
  <use href="/images/icon.svg#icon-cross"></use>
  </svg>    
</button>
<div>
  <h1 class="backery__title">Випічка</h1>
   <ul class="backery__list">
        <li class="backery____item">
          <article class="backery-card">
            <img
              class="backery-card__photo"
              src="./images/menu-backery/sosiska.png"
              alt="Сосиска в тісті"
            />
            <div>
              <h3 class="backery-card__title">Сосиска 
                <br>в тісті</h3>
              <p class="backery-card__text">1шт</p>
              <h3>30 грн</h3>
            </div>
          </article>
        </li> </ul> </div>

Ответы (0 шт):