.photo-gallery {
  container-type: inline-size;
}

.photo-gallery .photo-gallery__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .875rem;
  align-items: center;
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
}

@container (min-width: 38rem) {
  .photo-gallery .photo-gallery__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.photo-gallery .photo-gallery__grid[data-justified] {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

.photo-gallery .photo-gallery__grid li {
  margin: 0;
}

.photo-gallery .galleryImg,
.photo-gallery .galleryImg picture,
.photo-gallery .galleryImg img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  box-shadow: none;
}

.photo-gallery [data-photo]:focus-visible,
.photo-viewer :focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

.photo-gallery .galleryImg img {
  aspect-ratio: var(--photo-ratio);
  background-color: var(--photo-color);
}

.photo-gallery__details {
  font-size: .875rem;
}

.photo-gallery[data-enhanced] .photo-gallery__details {
  display: none;
}

.photo-gallery .photo-gallery__camera {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.25rem;
  margin: .25rem 0;
  font-size: .875rem;
}

.photo-gallery__camera div {
  display: flex;
  gap: .35em;
  max-width: 100%;
}

.photo-gallery .photo-gallery__camera dt,
.photo-gallery .photo-gallery__camera dd {
  width: auto;
}

.photo-gallery .photo-gallery__camera dd {
  margin: 0;
  padding: 0;
}

.photo-gallery .photo-gallery__camera dt {
  flex: none;
  font-weight: 600;
}

:root:has(.photo-viewer[open]) {
  overflow: hidden;
}

.photo-viewer[open] {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color-scheme: dark;
  color: white;
  background: black;
  overflow: hidden;
}

.photo-viewer::backdrop {
  background: #111;
}

.photo-viewer__frame {
  position: relative;
  height: 100%;
  --edge-x: max(.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
  --edge-top: max(.75rem, env(safe-area-inset-top));
  --edge-bottom: max(.75rem, env(safe-area-inset-bottom));
  --glass: rgb(20 20 20 / 85%);
}

.viewer-chrome {
  position: absolute;
  z-index: 2;
  transition: opacity .18s ease;
}

[data-quiet] .viewer-chrome {
  opacity: 0;
  pointer-events: none;
}

.photo-viewer button, .photo-viewer a[download] {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  min-width: 44px;
  height: 44px;
  padding: 0 .6rem;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 50%;
  box-shadow: none;
  background: var(--glass);
  color: white;
  font: 600 .7rem/1 ui-monospace, monospace;
  cursor: pointer;
}

.photo-viewer [hidden], .photo-viewer a[hidden] { display: none; }
.photo-viewer button:disabled { visibility: hidden; }
.photo-viewer button:hover, .photo-viewer a:hover,
.photo-viewer button[aria-expanded="true"] { background: #444; }
.photo-viewer svg { width: 20px; height: 20px; }
.photo-viewer :focus-visible { outline: 2px solid white; outline-offset: -3px; }

.viewer-counter {
  top: var(--edge-top);
  left: var(--edge-x);
  border-radius: 2rem;
  background: var(--glass);
  padding: .45rem .8rem;
  font: 500 .75rem/1.3 ui-monospace, monospace;
}

.viewer-close { top: var(--edge-top); right: var(--edge-x); }
.viewer-prev, .viewer-next { top: 50%; transform: translateY(-50%); }
.viewer-prev { left: var(--edge-x); }
.viewer-next { right: var(--edge-x); }
.viewer-tools {
  bottom: var(--edge-bottom);
  right: var(--edge-x);
  display: flex;
  gap: .35rem;
}

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

.photo-viewer__slides {
  height: 100%;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  direction: ltr;
}

.photo-viewer__slides::-webkit-scrollbar {
  display: none;
}

.photo-viewer__slides:focus-visible {
  outline: none;
}

.photo-viewer__slides > div {
  flex: 0 0 100%;
  min-width: 0;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.photo-viewer__slides picture {
  display: grid;
  place-items: center;
  height: 100%;
}

.photo-gallery .photo-viewer__slides img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  border-radius: 0;
  object-fit: contain;
}

.viewer-panels {
  position: absolute;
  z-index: 1;
  bottom: calc(var(--edge-bottom) + 52px);
  right: var(--edge-x);
  max-width: min(30rem, calc(100% - 2 * var(--edge-x)));
  max-height: 46%;
  overflow: auto;
  border-radius: .75rem;
  background: var(--glass);
}

.photo-gallery .viewer-panels p { margin: 0; padding: .75rem 1rem; }
.photo-gallery .viewer-panels dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: .65rem 1rem;
  margin: 0;
  padding: .85rem 1rem;
  font: .85rem/1.45 ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.photo-gallery .viewer-panels dl div { display: block; }
.photo-gallery .viewer-panels dt {
  color: #c2c2c2;
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
