.gallery {
  width: min(100% - 3.5rem, 76rem);
  margin-inline: auto;
  padding-block: clamp(4rem, 8vw, 7rem);
  scroll-margin-top: 2rem;
}
.gallery-heading {
  margin-bottom: clamp(2rem, 5vw, 4rem);
}
.gallery-heading h2 {
  font: 400 clamp(3.5rem, 7.4vw, 7rem)/.92 var(--serif);
  letter-spacing: -.05em;
  color: var(--burgundy);
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(.8rem, 2vw, 1.75rem);
  align-items: start;
}
.gallery-photo {
  position: relative;
  display: block;
  overflow: hidden;
  background: #dfd3c6;
  text-decoration: none;
  box-shadow: 0 .5rem 1.5rem #4b001f0b;
}
.gallery-photo:nth-child(1) { grid-column: span 5; }
.gallery-photo:nth-child(2) { grid-column: span 3; margin-top: 5rem; }
.gallery-photo:nth-child(3) { grid-column: span 4; margin-top: 2rem; }
.gallery-photo:nth-child(4) { grid-column: span 7; }
.gallery-photo:nth-child(5) { grid-column: span 5; margin-top: 3rem; }
.gallery-photo:nth-child(n+6) { grid-column: span 4; }
.gallery-photo:nth-child(7) { margin-top: 4rem; }
.gallery-photo:nth-child(8) { margin-top: 1.75rem; }
.gallery-photo img {
  width: 100%;
  height: auto;
  transition: transform .7s cubic-bezier(.2,.65,.3,1), filter .7s;
}
.gallery-photo:hover img,
.gallery-photo:focus-visible img { transform: scale(1.045); filter: saturate(1.06); }
.gallery-photo:focus-visible { outline: 2px solid var(--burgundy); outline-offset: 5px; }
.gallery-photo-open {
  position: absolute;
  inset: auto .65rem .65rem auto;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  background: #f7f3e9ed;
  color: var(--burgundy);
  font: 650 .95rem/1 var(--sans);
}
.gallery-ready .gallery-photo {
  opacity: 0;
  transform: translateY(2rem);
  transition: opacity .8s ease, transform 1s cubic-bezier(.2,.65,.3,1);
}
.gallery-ready .gallery-photo:nth-child(3n+2) { transition-delay: .1s; }
.gallery-ready .gallery-photo:nth-child(3n) { transition-delay: .2s; }
.gallery-ready .gallery-photo.gallery-visible { opacity: 1; transform: translateY(0); }

html:has(.gallery-lightbox[open]) { overflow: hidden; }
.gallery-lightbox {
  width: min(94vw, 78rem);
  max-height: 94dvh;
  margin: auto;
  padding: 1rem clamp(1rem, 3vw, 2.5rem) 1.2rem;
  border: 1px solid #eee0cc4d;
  color: var(--paper);
  background: #27151d;
}
.gallery-lightbox[open] { display: grid; animation: gallery-dialog-enter .25s ease-out; }
.gallery-lightbox::backdrop { background: #17060fe8; backdrop-filter: blur(8px); }
.gallery-close,
.gallery-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  min-height: 2.75rem;
  padding: .4rem .7rem;
  border: 1px solid #eee0cc66;
  background: transparent;
  color: var(--paper);
  font: 600 .67rem/1.3 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
}
.gallery-close { justify-self: end; margin-bottom: .75rem; }
.gallery-close > span { font-size: 1.4rem; font-weight: 400; }
.gallery-controls button:hover,
.gallery-close:hover { background: #eee0cc16; }
.gallery-lightbox-figure { margin: 0; }
.gallery-lightbox-image { width: 100%; height: min(65dvh, 45rem); object-fit: contain; }
.gallery-counter { margin-top: .8rem; font-size: .7rem; text-align: center; letter-spacing: .12em; text-transform: uppercase; }
.gallery-controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .75rem; }
@keyframes gallery-dialog-enter {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 740px) {
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-photo:nth-child(n) { grid-column: span 1; margin-top: 0; }
  .gallery-photo:nth-child(even) { margin-top: 2rem; }
}
@media (max-width: 560px) {
  .gallery { width: calc(100% - 2.5rem); }
  .gallery-heading h2 { font-size: clamp(3rem, 12vw, 4.2rem); }
  .gallery-photo-open { inset: auto .4rem .4rem auto; }
}
@media (prefers-reduced-motion: reduce) {
  .gallery-ready .gallery-photo { opacity: 1; transform: none; transition: none; }
  .gallery-photo img, .gallery-lightbox[open] { transition: none; animation: none; }
}
