:root {
  --gallery-bg: #f5f2ea;
  --gallery-text: #1d2326;
  --gallery-accent: #2f6f73;
  --gallery-focus: rgba(47, 111, 115, 0.45);
  --gallery-shadow: 0 22px 60px rgba(24, 30, 32, 0.18);
}

button,
img {
  display: block;
}

button {
  font: inherit;
}

.demo-page {
  min-height: 100vh;
  padding: 5vh 18px;
}

.photo-gallery {
  width: min(1360px, 100%);
  margin: 0 auto;
}

.gallery-header {
  max-width: 780px;
  margin-bottom: 18px;
}

.gallery-kicker {
  margin: 0 0 8px;
  color: #4DD0E1;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.gallery-header h1,
.gallery-header h4 {
  color: #fff;
  margin: 0;
  font-size: clamp(2rem, 4.2vw, 4.1rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.gallery-grid {
  height: 80vh;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.gallery-grid + .gallery-grid {
  margin-top: 5vh;
}

.gallery-grid.is-hidden {
  display: none;
}

.gallery-grid.is-revealed {
  animation: galleryReveal 420ms ease both;
}

.gallery-item {
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: #d7ddd8;
  cursor: pointer;
  isolation: isolate;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.42) inset;
  transition: box-shadow 220ms ease, transform 220ms ease;
  border: 1px solid #fff;
}

.gallery-item::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.18));
  opacity: 0;
  transition: opacity 180ms ease;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 360ms ease, filter 180ms ease;
}

.gallery-item:hover,
.gallery-item:focus-visible {
  box-shadow: var(--gallery-shadow);
  transform: translateY(-2px);
}

.gallery-item:hover img,
.gallery-item:focus-visible img {
  transform: scale(1.055);
  filter: saturate(1.06) contrast(1.03);
}

.gallery-item:hover::after,
.gallery-item:focus-visible::after {
  opacity: 1;
}

.gallery-item:focus-visible,
.lightbox-close:focus-visible,
.lightbox-arrow:focus-visible {
  outline: 3px solid var(--gallery-focus);
  outline-offset: 3px;
}

.gallery-item:nth-child(1),
.gallery-item:nth-child(4) {
  grid-column: span 4;
}

.gallery-item:nth-child(2),
.gallery-item:nth-child(3) {
  grid-column: span 3;
}

.gallery-grid.has-1 {
  height: min(48vh, 520px);
  grid-template-rows: 1fr;
}

.gallery-grid.has-1 .gallery-item:nth-child(1) {
  grid-column: 1 / -1;
}

.gallery-grid.has-2 {
  height: min(56vh, 600px);
  grid-template-rows: 1fr;
}

.gallery-grid.has-3 {
  height: min(72vh, 720px);
}

.gallery-grid.has-3 .gallery-item:nth-child(3) {
  grid-column: 1 / -1;
}

.gallery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding-top: 18px;
}

.gallery-next,
.gallery-less {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 22px;
  cursor: pointer;
  font-weight: 750;
  transition: background 180ms ease, transform 180ms ease;
}

.gallery-next {
  border: 0;
  background: var(--gallery-text);
  color: #fff;
}

.gallery-less {
  border: 1px solid rgba(29, 35, 38, 0.18);
  background: rgba(255, 255, 255, 0.68);
  color: var(--gallery-text);
}

.gallery-next:hover,
.gallery-next:focus-visible,
.gallery-less:hover,
.gallery-less:focus-visible {
  background: var(--gallery-accent);
  color: #fff;
  transform: translateY(-1px);
}

.gallery-next.is-hidden,
.gallery-less.is-hidden {
  display: none;
}

@keyframes galleryReveal {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 34px 76px;
  background: rgba(9, 12, 14, 0.9);
}

.gallery-lightbox.is-open {
  display: grid;
}

.gallery-lightbox figure {
  width: min(1120px, 100%);
  margin: 0;
}

.gallery-lightbox img {
  width: 100%;
  max-height: 82vh;
  border-radius: 12px;
  object-fit: contain;
  background: #111;
}

.lightbox-close,
.lightbox-arrow {
  position: fixed;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.lightbox-close {
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.55rem;
  line-height: 1;
}

.lightbox-arrow {
  top: 50%;
  width: 48px;
  height: 64px;
  border-radius: 8px;
  font-size: 3rem;
  line-height: 1;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: 18px;
}

.lightbox-next {
  right: 18px;
}

@media (max-width: 760px) {
  .demo-page {
    padding: 5vh 12px;
  }

  .gallery-header {
    margin-bottom: 20px;
  }

  .gallery-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .gallery-item {
    border-radius: 8px;
  }

  .gallery-lightbox {
    padding: 72px 16px 28px;
  }

  .lightbox-arrow {
    top: auto;
    bottom: 18px;
    width: 52px;
    height: 44px;
    font-size: 2rem;
    transform: none;
  }
}

@media (max-width: 520px) {
  .gallery-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(0, 1fr));
    height: 90vh;
  }

  .gallery-item:nth-child(n) {
    grid-column: auto;
  }
  .gallery-grid.has-1,
  .gallery-grid.has-2,
  .gallery-grid.has-3 {
    height: auto;
  }

  .gallery-grid.has-1 {
    grid-template-rows: 260px;
  }

  .gallery-grid.has-2 {
    grid-template-rows: repeat(2, 230px);
  }

  .gallery-grid.has-3 {
    grid-template-rows: repeat(3, 210px);
  }
}
