/* Let the available container width determine the number of photos per row. */
section.gallery .im_wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  height: auto;
  margin: 0;
}

section.gallery .im_wrapper > div {
  min-width: 0;
}

section.gallery .im_wrapper button {
  display: block;
  width: 100%;
  padding: 5px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  box-shadow: 1px 1px 3px #000;
}

section.gallery .im_wrapper img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  margin: 0;
}

.gallery-viewer {
  position: fixed;
  inset: 0;
  width: calc(100% - 24px);
  max-width: 1100px;
  max-height: calc(100% - 24px);
  margin: auto;
  padding: 12px;
  border: 0;
  border-radius: 6px;
  background: #161616;
  color: #fff;
}

.gallery-viewer::backdrop {
  background: rgba(0, 0, 0, 0.85);
}

.gallery-viewer__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gallery-viewer button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #777;
  border-radius: 4px;
  background: #252525;
  color: #fff;
  cursor: pointer;
}

.gallery-viewer button:disabled {
  opacity: 0.35;
  cursor: default;
}

.gallery-viewer__stage {
  position: relative;
  display: flow-root;
  overflow: hidden;
}

.gallery-viewer__tiles,
.gallery-viewer__tile {
  position: absolute;
  pointer-events: none;
}

.gallery-viewer__tile {
  background-repeat: no-repeat;
}

.gallery-viewer__image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 160px);
  max-height: calc(100dvh - 160px);
  margin: 10px auto;
  object-fit: contain;
}

.gallery-viewer button:focus-visible,
section.gallery .im_wrapper button:focus-visible {
  outline: 3px solid #e4bd74;
  outline-offset: 3px;
}

@media (max-width: 359px) {
  section.gallery .im_wrapper {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
}
