* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  background: #111111;
  color: #eee;
  padding: 20px;
  font-size: 1rem;
  overflow-x: hidden;
}

h1 {
  text-align: center;
  font-size: 3rem;
  margin: 0;
  margin-top: 1rem;
  margin-left: 1rem;
  margin-right: 1rem;
  padding: 0;
}

#collection-stats {
  text-align: center;
  font-size: 0.8rem;
  color: #aaa;
}

#search {
  display: block;
  margin: 10px auto 30px auto;
  width: 50%;
  padding: 0.5rem;
  font-size: 1rem;
  color: #eee;
  background-color: transparent;
  border: none;
  border-bottom: 1px solid #496bbeaa;
}

#search::placeholder {
  color: #aaa;
}

#search:focus {
  outline: none;
  border-bottom: 1px solid #496bbe;
}

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.gallery-item {
  position: relative;
  cursor: pointer;
  min-width: 0;
  max-width: 100vw;
}

.gallery-item img {
  border-radius: 0.1rem;
  transition: transform 0.2s;
  max-width: 100%;
  height: auto;
  display: block;
}

.gallery-item img:hover {
  transform: scale(1.05);
}

.nsfw-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;

  border-radius: 0.1rem;
  font-weight: bold;
  font-size: 1rem;
  color: white;
  z-index: 10;

  background: transparent;
}

.nsfw-overlay::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: black;
  filter: blur(5px);
  border-radius: 0.1rem;
  z-index: -1;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 100;
}

.modal-image-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: min(calc(100vw - 40px), 90vw);
  max-height: calc(100vh - 120px);
}

.modal img {
  max-width: min(calc(100vw - 40px), 90vw);
  max-height: calc(100vh - 120px);
  border-radius: 0.1rem;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
  object-fit: contain;
}

@media (max-width: 600px) {
  .modal-image-container {
    max-width: 100vw;
    max-height: calc(100vh - 80px);
  }

  .modal img {
    max-width: 100vw;
    max-height: calc(100vh - 80px);
  }

  #search {
    width: 80%;
  }

  h1 {
    font-size: 2rem;
  }

  #modal-close {
    top: 10px;
    right: 20px;
    font-size: 30px;
  }
}

#modal-meta {
  margin-top: 1rem;
  font-size: 1rem;
  color: #ccc;
}

#modal-close {
  position: absolute;
  top: 20px;
  right: 40px;
  font-size: 40px;
  cursor: pointer;
  color: #fff;
}

#sort-widget {
  position: fixed;
  opacity: 40%;
  bottom: 20px;
  right: 20px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(17, 17, 17, 0.9);
  border: 1px solid #496bbe;
  border-radius: 8px;
  padding: 6px 10px;
}

#sort-widget:hover {
  opacity: 100%;
  transition: all 200ms ease-in-out;
}

.sort-btn {
  background: none;
  border: none;
  color: #aaa;
  font-family: sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition:
    color 0.15s,
    background 0.15s;
}

.sort-btn:hover {
  color: #fff;
  background: rgba(73, 107, 190, 0.2);
}

.sort-btn.active {
  color: #fff;
  background: #496bbe;
}

#sort-reverse {
  font-size: 1.1rem;
  padding: 2px 6px;
  line-height: 1;
}

.sort-sep {
  width: 1px;
  height: 20px;
  background: #496bbe;
  margin: 0 2px;
}
