:after перекрывает содержимое страницы

У меня почему-то псевдо класс :after у блока .modal перекрывает всё содержимое на странице

document.getElementById("close").onclick = function() {
  document.getElementById("myModal").style.display = "none";
};

document.getElementById("myBtn").onclick = function() {
  document.getElementById("myModal").style.display = "block";
};
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap");
* {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Roboto", sans-serif;
}

p {
  width: 400px;
  margin-top: 10px;
}

hr {
  margin-top: 20px;
}

#myBtn {
  padding: 5px 10px;
  margin: 10px;
  position: absolute;
  top: 50px;
  left: 50px;
  cursor: pointer;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal {
  display: none;
  width: 400px;
  padding: 20px;
  text-align: center;
  border: 1px solid #000;
  border-radius: 10px;
  background-color: #fff;
}

.modal:after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: -1;
  opacity: 0.5;
}

#close {
  float: right;
  padding: 2px 5px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 20px;
  cursor: pointer;
}
<button id="myBtn">Модальное окно</button>
<div class="page">
  <div class="modal" id="myModal">
    <div class="header">
      <button id="close">&times;</button>
      <h1>Заголовок</h1>
      <hr>
    </div>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Veritatis deleniti, dolores illum iure et optio laboriosam quibusdam veniam reprehenderit mollitia delectus porro vel id voluptate! Omnis amet officia ea veritatis?</p>
  </div>
</div>

Codepen


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

Автор решения: Michael Miller

Если правильно понял, то

#myBtn{z-index:1}
.page {position:relative;z-index:2}
.modal:after {z-index:-1}
→ Ссылка