.px-gallery {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-self: stretch;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--px-panel-edge);
  border-radius: var(--px-panel-radius);
  background: var(--px-background);
  color: var(--px-text);
  animation: image-in var(--motion-reveal) var(--ease) both;
}

.gallery-stage {
  position: relative;
  display: grid;
  min-height: clamp(286px, 37vw, 555px);
  align-items: stretch;
  padding: 32px clamp(26px, 4vw, 58px);
  isolation: isolate;
  background: radial-gradient(ellipse at 80% 18%, #442822 0, var(--px-surface) 52%, var(--px-background) 92%);
}

.gallery-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle, var(--px-texture-dot) .8px, transparent 1px) 0 0 / 18px 18px;
  pointer-events: none;
}

.gallery-open {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  place-items: center;
  perspective: 850px;
  cursor: zoom-in;
}

.gallery-open img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12px 20px #07080985);
  transform-origin: 50% 50%;
}

.gallery-loupe {
  position: relative;
  z-index: 1;
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid #f3e9dc70;
  border-radius: 50%;
  background: #131416db;
  color: var(--px-text);
  opacity: 0;
  transform: scale(.83);
  transition: opacity var(--motion-feedback), transform var(--motion-feedback) var(--ease);
}

.gallery-loupe::before, .gallery-loupe::after {
  content: '';
  position: absolute;
}
.gallery-loupe::before {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: translate(-2px, -2px);
}
.gallery-loupe::after {
  width: 9px;
  height: 2px;
  background: currentColor;
  transform: translate(8px, 8px) rotate(45deg);
}
.gallery-open:hover .gallery-loupe, .gallery-open:focus-visible .gallery-loupe {
  opacity: 1;
  transform: none;
}

.gallery-arrow, .gallery-playback, .gallery-close {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #e7e1d643;
  border-radius: 50%;
  background: #131416b5;
  color: var(--px-text);
  transition: background var(--motion-feedback), border-color var(--motion-feedback), opacity var(--motion-feedback);
}
.gallery-arrow {
  position: absolute;
  z-index: 2;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  line-height: 1;
  opacity: .63;
}
.gallery-arrow.prev { left: 9px; }
.gallery-arrow.next { right: 9px; }
.gallery-arrow:hover, .gallery-arrow:focus-visible, .gallery-playback:hover, .gallery-close:hover {
  background: var(--px-background);
  border-color: var(--px-coral);
  opacity: 1;
}

.gallery-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 12px;
  border-top: 1px solid var(--px-edge);
  font-size: .84rem;
}
.gallery-controls { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.gallery-count { color: var(--px-muted); font-variant-numeric: tabular-nums; }
.gallery-playback { font-size: .83rem; }

.px-gallery-dialog {
  position: fixed;
  inset: 0;
  width: min(96vw, 1500px);
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--px-panel-edge);
  border-radius: var(--px-panel-radius);
  background: var(--px-background);
  color: var(--px-text);
}
.px-gallery-dialog::backdrop { background: #0a0b0de6; }
.gallery-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--px-edge);
}
.gallery-dialog-header h2 { font-size: 1rem; }
.gallery-close { font-size: 1.2rem; }
.gallery-dialog-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 10px 50px;
}
.gallery-dialog-stage img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(90vh - 70px);
  max-height: calc(90dvh - 70px);
  object-fit: contain;
}
.gallery-open:focus-visible, .gallery-arrow:focus-visible, .gallery-playback:focus-visible, .gallery-close:focus-visible {
  outline: 2px solid var(--px-coral);
  outline-offset: -2px;
}
body:has(.px-gallery-dialog[open]) { overflow: hidden; }

@media (max-width: 760px) {
  .gallery-stage { min-height: clamp(190px, 60vw, 380px); padding: 20px 23px; }
  .access-shell .px-gallery { order: 1; }
  .gallery-arrow.prev { left: 4px; }
  .gallery-arrow.next { right: 4px; }
  .gallery-dialog-stage { padding-inline: 8px; }
}

@media (hover: none) {
  .gallery-loupe { opacity: .86; transform: none; }
}
