Although I have set the z-indexes correct, so the .container class can be on the back level, on the upper side, it has an empty space that I suspect is caused by the .add-book div. I have linked the button through javascript so it will increase the opacity to 1 when pressed, (by toggling an 'active' class) but now I have set the .add-box opacity to 1 for easier editing.
body {
  margin: 0;
  font-family: Montserrat;
}
nav {
  ...
}
.add {
  font-family: Montserrat;
  margin-right: 2rem;
  height: 3rem;
  border-radius: 20px;
  padding-left: 20px;
  padding-right: 20px;
  font-size: 1rem;
  border: 0;
  cursor: pointer;
  background-color: rgb(248, 248, 248);
  transition: 0.1s;
}
.add:hover {
  background-color: rgb(245, 245, 245);
}
.add:active {
  background-color: rgb(237, 237, 237);
}
.add-book {
  width: 15rem;
  height: 23rem;
  background-color: rgb(237, 237, 237);
  z-index: +20;
  position: relative;
  top: 4.7rem;
  left: calc(100vw - 15rem - 10px);
  border-radius: 17px;
  display: flex;
  opacity: 1;
  flex-direction: column;
  align-items: center;
}
.add-book h2 {
  margin: 0;
  margin-top: 15px;
}
.add-book h3 {
  margin: 0;
}
.input-container {
  margin-top: 20px;
}
.input-container input {
  width: 12rem;
  margin-top: 5px;
}
.checkbox-container {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 12rem;
}
.checkbox-container input {
  transform: scale(1.2);
}
.add-book button {
  margin-top: auto;
  margin-bottom: 25px;
  height: 2.3rem;
  width: 12rem;
  border-radius: 10px;
  border: solid 2px rgb(225, 225, 225);
  background-color: rgb(248, 248, 248);
  cursor: pointer;
  transition: 0.1s;
}
.add-book button:hover {
  background-color: rgb(245, 245, 245);
}
.add-book button:active {
  background-color: rgb(237, 237, 237);
}
.add-book.active {
  opacity: 1;
}
.main-container {
  width: 100%;
  background-color: antiquewhite;
  height: calc(100vh - 4rem);
  z-index: -1;
}<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<nav>
  <div class="title">
    <h1>MyLibrary .</h1>
  </div>
  <button class="add" id="add">Add Book</button>
</nav>
<div class="add-book" id="add-book">
  <h2>Add Book</h2>
  <div class="input-container">
    <h3>Title</h3>
    <input type="text" id="title" />
  </div>
  <div class="input-container">
    <h3>Author</h3>
    <input type="text" id="author" />
  </div>
  <div class="input-container">
    <h3>Pages</h3>
    <input type="number" id="pages" />
  </div>
  <div class="checkbox-container">
    <h3>Read</h3>
    <input type="checkbox" id="checkbox" />
  </div>
  <button>Add!</button>
</div>
<div class="main-container">
  <h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassdasd</h1>
</div> 
    