.gallery-preview-dialog {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(12px, 2.8vw, 28px);
  border: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: transparent;
  color: #fff8e9;
}

.gallery-preview-dialog:not([open]),
.gallery-preview-dialog [hidden] {
  display: none;
}

.gallery-preview-dialog[open] {
  display: grid;
  place-items: center;
}

.gallery-preview-dialog::backdrop {
  background: rgba(20, 15, 11, 0.9);
}

.gallery-preview-panel {
  width: min(100%, 1100px);
  height: min(100%, 850px);
  min-height: min(390px, 100%);
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
  gap: clamp(7px, 1.2vw, 14px);
}

.gallery-preview-header,
.gallery-preview-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gallery-preview-header h2 {
  min-width: 0;
  margin: 0;
  color: inherit;
  font-size: clamp(1.05rem, 2.7vw, 1.7rem);
  line-height: 1.2;
}

.gallery-preview-dialog button {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid #b89465;
  border-radius: 7px;
  background: #35291e;
  color: #fff8e9;
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
}

.gallery-preview-dialog button:hover:not([aria-disabled="true"]),
.gallery-preview-dialog button[aria-pressed="true"] {
  border-color: #f7d099;
  background: #f7d099;
  color: #25180d;
}

.gallery-preview-dialog button:focus-visible {
  outline: 3px solid #fff3d8;
  outline-offset: 3px;
}

.gallery-preview-dialog button[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
}

.gallery-preview-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.gallery-preview-close span,
.gallery-preview-navigation button span {
  font-size: 1.35em;
  line-height: 1;
}

.gallery-preview-figure {
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
}

.gallery-preview-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #1c1610;
  touch-action: pan-y pinch-zoom;
}

.gallery-preview-photo {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  object-fit: contain;
  user-select: none;
}

.gallery-preview-error {
  margin: 0 16px;
  text-align: center;
}

.gallery-preview-caption {
  display: flex;
  justify-content: center;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 13px;
  margin: 0;
  padding-inline: 10px;
  text-align: center;
}

.gallery-preview-photo-title {
  font-weight: 700;
}

.gallery-preview-position {
  color: #e8c99e;
  font-size: 0.86rem;
}

.gallery-preview-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 14px;
}

.gallery-preview-navigation button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.gallery-preview-thumbnails {
  min-width: 0;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 5px;
  scrollbar-width: thin;
}

.gallery-preview-thumbnails button {
  flex: 0 0 60px;
  padding: 2px;
}

.gallery-preview-thumbnails img {
  width: 100%;
  height: 39px;
  display: block;
  object-fit: cover;
  border-radius: 4px;
}

.gallery-preview-comparison button {
  flex-basis: 80px;
}

@media (max-width: 560px) {
  .gallery-preview-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .gallery-preview-navigation {
    justify-content: center;
  }

  .gallery-preview-thumbnails {
    justify-content: safe center;
  }
}

@media (max-height: 475px) and (orientation: landscape) {
  .gallery-preview-dialog {
    padding: 8px;
  }

  .gallery-preview-controls {
    grid-template-columns: auto minmax(0, 1fr);
  }
}
