.tournament-gallery {
  scroll-margin-top: 7rem;
  background: var(--mist);
}

.tournament-gallery__heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
}

.tournament-gallery__heading .section-heading {
  max-width: 48rem;
  margin: 0;
}

.tournament-gallery__heading h2 {
  max-width: 22ch;
}

.tournament-gallery__meta {
  flex: 0 0 auto;
  margin: 0;
  padding-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: right;
}

.tournament-gallery__meta strong {
  display: block;
  color: var(--navy);
}

.tournament-gallery__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

.tournament-gallery__photo {
  position: relative;
  display: block;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #dce7e6;
  border-radius: 0.5rem;
  isolation: isolate;
}

.tournament-gallery__photo[hidden] {
  display: none;
}

.tournament-gallery__photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 35%;
  transition: transform 200ms ease;
}

.tournament-gallery__photo::after {
  position: absolute;
  right: 0.65rem;
  bottom: 0.65rem;
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  color: white;
  background: rgba(12, 43, 61, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  content: "+";
  pointer-events: none;
}

.tournament-gallery__photo:hover img {
  transform: scale(1.025);
}

.tournament-gallery__photo:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 4px;
}

.tournament-gallery__footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-top: 2rem;
  text-align: center;
}

.tournament-gallery__footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.tournament-gallery__footer button[hidden] {
  display: none;
}

.photo-viewer {
  width: min(94vw, 82rem);
  max-width: none;
  max-height: 94vh;
  max-height: 94dvh;
  margin: auto;
  padding: 0;
  overflow: auto;
  color: #f8faf9;
  background: #0c202b;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 0.75rem;
  box-shadow: 0 2rem 7rem rgba(0, 0, 0, 0.5);
}

.photo-viewer::backdrop {
  background: rgba(5, 17, 25, 0.92);
}

.photo-viewer__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  padding: 0.45rem 0.8rem 0.45rem 1.25rem;
}

.photo-viewer__toolbar h2 {
  margin: 0;
  color: inherit;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.4;
}

.photo-viewer__button {
  display: grid;
  flex-shrink: 0;
  width: 2.9rem;
  height: 2.9rem;
  padding: 0;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  font-family: inherit;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.photo-viewer__button:hover {
  background: rgba(255, 255, 255, 0.23);
}

.photo-viewer__button:focus-visible,
.photo-viewer__open:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.photo-viewer__stage {
  position: relative;
  display: grid;
  height: min(69vh, 53rem);
  height: min(69dvh, 53rem);
  min-height: 12rem;
  padding: 0 4.5rem;
  place-items: center;
  background: #071720;
}

.photo-viewer__image {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.photo-viewer__previous,
.photo-viewer__next {
  position: absolute;
  top: 50%;
  z-index: 1;
  transform: translateY(-50%);
}

.photo-viewer__previous {
  left: 0.65rem;
}

.photo-viewer__next {
  right: 0.65rem;
}

.photo-viewer__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem 1.05rem;
  font-size: 0.875rem;
}

.photo-viewer__caption {
  margin: 0;
  color: #e1ecef;
}

.photo-viewer__caption strong {
  display: block;
  margin-bottom: 0.2rem;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.photo-viewer__open {
  flex: 0 0 auto;
  color: var(--gold);
  font-weight: 700;
  text-underline-offset: 0.25em;
}

.gallery-open {
  overflow: hidden;
}

@media (max-width: 60rem) {
  .tournament-gallery__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tournament-gallery__heading {
    display: block;
  }

  .tournament-gallery__meta {
    margin-top: 1rem;
    text-align: left;
  }
}

@media (max-width: 46rem) {
  .tournament-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .tournament-gallery__photo::after {
    right: 0.4rem;
    bottom: 0.4rem;
    width: 1.6rem;
    height: 1.6rem;
  }

  .photo-viewer {
    width: 96vw;
    max-height: 96dvh;
  }

  .photo-viewer__stage {
    height: 58vh;
    height: 58dvh;
    padding: 0;
  }

  .photo-viewer__previous,
  .photo-viewer__next {
    background: rgba(7, 23, 32, 0.82);
  }

  .photo-viewer__footer {
    flex-direction: column;
    align-items: start;
    gap: 0.6rem;
  }
}

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