.portfolio {
  padding-top: 150px;
  padding-bottom: 150px;
  background: #09090a;
}

.portfolio .section-heading {
  max-width: 760px;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 260px;
  gap: 10px;
  margin-top: 48px;
}

.portfolio-item {
  position: relative;
  overflow: hidden;
  appearance: none;
  padding: 0;
  border: 0;
  background: #161617;
  cursor: zoom-in;
}

.portfolio-item[hidden] {
  display: none;
}

.portfolio-item:nth-child(7n + 1) {
  grid-column: span 2;
  grid-row: span 2;
}

.portfolio-item:nth-child(9n + 4) {
  grid-row: span 2;
}

.portfolio-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 0 solid var(--red);
  transition: border-width 180ms ease;
  pointer-events: none;
}

.portfolio-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.88) contrast(1.04);
  transition: transform 450ms ease, filter 450ms ease;
}

.portfolio-item:hover img,
.portfolio-item:focus-visible img {
  transform: scale(1.035);
  filter: saturate(1) contrast(1);
}

.portfolio-item:hover::after,
.portfolio-item:focus-visible::after {
  border-width: 3px;
}

.portfolio-item:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.portfolio-actions {
  display: flex;
  justify-content: center;
  margin-top: 42px;
}

.portfolio-toggle {
  border: 1px solid #494949;
  background: transparent;
  color: #fff;
}

.portfolio-toggle:hover,
.portfolio-toggle:focus-visible {
  border-color: var(--red);
  background: var(--red);
}

.portfolio-lightbox {
  width: min(94vw, 1200px);
  height: min(92vh, 900px);
  padding: 0;
  border: 1px solid #333;
  background: #050505;
  color: #fff;
  overflow: hidden;
}

.portfolio-lightbox::backdrop {
  background: rgb(0 0 0 / 92%);
  backdrop-filter: blur(8px);
}

.portfolio-lightbox figure {
  width: 100%;
  height: 100%;
  margin: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 46px;
  place-items: center;
}

.portfolio-lightbox figure img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.portfolio-lightbox figcaption {
  align-self: center;
  font-family: var(--display);
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #aaa;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 70%);
  color: #fff;
  cursor: pointer;
  transition: background 180ms ease;
}

.lightbox-close:hover,
.lightbox-nav:hover {
  background: var(--red);
}

.lightbox-close {
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  font-size: 1.8rem;
}

.lightbox-nav {
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translateY(-50%);
  font-size: 2.2rem;
}

.lightbox-prev {
  left: 12px;
}

.lightbox-next {
  right: 12px;
}

@media (max-width: 1000px) {
  .portfolio {
    padding-top: 110px;
    padding-bottom: 110px;
  }

  .portfolio-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 230px;
  }
}

@media (max-width: 650px) {
  .portfolio {
    padding-top: 84px;
    padding-bottom: 84px;
  }

  .portfolio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 190px;
    gap: 6px;
    margin-top: 32px;
  }

  .portfolio-item:nth-child(7n + 1) {
    grid-column: span 2;
  }

  .lightbox-nav {
    top: auto;
    bottom: 10px;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .portfolio-item img {
    transition: none;
  }
}
