html:has(.photo-viewer[open]) { overflow: hidden; }
.photo-viewer:not([open]) { display: none; }
.gallery-main[aria-haspopup="dialog"] { cursor: zoom-in; }
.photo-viewer[open] {
  position: fixed;
  inset: 0;
  margin: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  color: white;
  background: #161616;
}
.photo-viewer::backdrop { background: #161616; }
.photo-viewer-tools {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: max(.5rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right)) .5rem .5rem;
}
.photo-viewer-tools form { margin: 0; }
.photo-viewer-tools button {
  min-height: 44px;
  min-width: 44px;
  padding: .25rem .8rem;
  border: 1px solid #777;
  border-radius: .5rem;
  color: white;
  background: #252525;
  font: inherit;
  cursor: pointer;
}
.photo-viewer-tools form button { font-size: 1.5rem; line-height: 1; }
.photo-viewer-tools button:focus-visible { outline: 2px solid white; outline-offset: 2px; }
.photo-viewer-stage {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  cursor: zoom-out;
}
.photo-viewer-stage img {
  display: block;
  flex: none;
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
.photo-viewer-stage.original-size img { max-width: none; max-height: none; }
