.media-gallery {
  padding: 2rem 1rem 5rem;
  background: var(--color-surface-subtle);
}

@media (min-width: 900px) {
  .media-gallery {
    padding: 3rem clamp(1rem, 12.15vw, 13.125rem) 7rem;
  }
}

.media-gallery__wrapper {
  max-width: 82rem;
  margin-inline: auto;
}

.media-gallery__header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.media-gallery__heading {
  margin: 0 0 0.5rem;
  color: var(--color-text-default);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.025em;
}

.media-gallery__summary {
  max-width: 40rem;
  margin: 0 0 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.media-gallery__count {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.media-gallery__start {
  flex-shrink: 0;
  padding-block: 0.75rem;
  color: var(--color-interactive);
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
}

.media-gallery__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

@media (min-width: 900px) {
  .media-gallery__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }
}

.media-gallery__item {
  min-width: 0;
  margin: 0;
  scroll-margin-top: 12rem;
}

.media-gallery__item:first-child {
  grid-column: span 2;
}

@media (min-width: 900px) {
  .media-gallery__item:first-child {
    grid-row: span 2;
  }
}

.media-gallery__link {
  position: relative;
  display: block;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 0.5rem;
  background: var(--color-surface-media);
}

@media (min-width: 900px) {
  .media-gallery__item:first-child .media-gallery__link {
    height: 100%;
    aspect-ratio: auto;
  }
}

.media-gallery__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease;
}

.media-gallery__link:hover .media-gallery__image {
  transform: scale(1.025);
}

.media-gallery__number {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  background: rgb(0 0 0 / 60%);
  color: #ffffff;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.media-gallery__dialog {
  width: calc(100% - 1rem);
  max-width: 92rem;
  height: calc(100dvh - 1rem);
  max-height: none;
  padding: 1rem;
  border: 1px solid var(--color-border-default);
  border-radius: 1rem;
  background: var(--color-surface-default);
  color: var(--color-text-default);
}

.media-gallery__dialog::backdrop {
  background: rgb(0 0 0 / 80%);
}

.media-gallery__dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.media-gallery__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

.media-gallery__position {
  margin: 0;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.media-gallery__control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-default);
  border-radius: 0.5rem;
  background: var(--color-surface-raised);
  color: var(--color-text-default);
  font: inherit;
  cursor: pointer;
}

.media-gallery__viewer {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}

.media-gallery__viewer .image-zoom__viewport {
  height: 100%;
}

.media-gallery__previous {
  position: absolute;
  z-index: 1;
  left: 0;
}

.media-gallery__next {
  position: absolute;
  z-index: 1;
  right: 0;
}

.media-gallery__original {
  align-self: center;
  padding: 0.5rem;
  color: var(--color-interactive);
  font-size: 0.875rem;
  text-underline-offset: 0.2em;
}

.media-gallery :focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 3px;
}

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

@media (prefers-reduced-motion: reduce) {
  .media-gallery__link:hover .media-gallery__image {
    transform: none;
  }
}
