html.gallery-viewer-open {
  overflow: hidden;
  scrollbar-gutter: stable;
}

.gallery-viewer {
  --viewer-ink: #f8f4fb;
  --viewer-muted: #c1b9cf;
  --viewer-accent: #f4d9eb;
  --viewer-line: #f8f4fb24;
  position: fixed;
  inset: 0;
  width: min(1500px, calc(100% - 36px));
  height: min(1080px, calc(100vh - 36px));
  height: min(1080px, calc(100dvh - 36px));
  max-width: none;
  max-height: none;
  padding: 0;
  margin: auto;
  box-sizing: border-box;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 1px solid var(--viewer-line);
  border-radius: 20px;
  color: var(--viewer-ink);
  background: radial-gradient(ellipse at 50% 90%, #252035, #12101a 70%);
  box-shadow: 0 24px 100px #08060cbb;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color-scheme: dark;
}

.gallery-viewer[open] {
  animation: gallery-viewer-enter 180ms ease-out;
}

.gallery-viewer::backdrop {
  background: #0b0a12d9;
  backdrop-filter: blur(10px);
}

.gallery-viewer-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  box-sizing: border-box;
  height: 100%;
  padding: 15px clamp(15px, 3vw, 35px);
  gap: 12px;
}

.gallery-viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  gap: 12px;
}

.gallery-viewer-count {
  color: var(--viewer-muted);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: .05em;
}

.gallery-viewer-caption {
  color: var(--viewer-ink);
  font-size: .92rem;
  line-height: 1.35;
  text-align: start;
  overflow-wrap: anywhere;
}

.gallery-viewer-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 2vw, 28px);
  align-items: center;
}

.gallery-viewer-frame {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

.gallery-viewer-frame img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.gallery-viewer-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 7px;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  box-sizing: border-box;
  border: 1px solid var(--viewer-line);
  border-radius: 100px;
  color: var(--viewer-ink);
  background: #f8f4fb0d;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.gallery-viewer-button[hidden] {
  display: none;
}

.gallery-viewer-button:focus-visible {
  outline: 2px solid var(--viewer-accent);
  outline-offset: 3px;
}

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

.gallery-viewer-save {
  width: auto;
  padding-inline: 14px;
}

.gallery-viewer-save svg {
  width: 16px;
  height: 16px;
}

.gallery-viewer-save[aria-pressed='true'] {
  color: var(--viewer-accent);
  border-color: #f4d9eb68;
  background: #f4d9eb1c;
}

.gallery-viewer-save[aria-pressed='true'] svg {
  fill: currentColor;
}

@media (hover: hover) {
  .gallery-viewer-button:hover:not(:disabled) {
    color: var(--viewer-accent);
    border-color: #f4d9eb80;
    background: #f4d9eb1f;
  }
}

@media (max-width: 640px) {
  .gallery-viewer {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .gallery-viewer-shell {
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .gallery-viewer-stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 9px;
  }

  .gallery-viewer-frame {
    grid-area: 1 / 1 / 2 / 3;
  }

  .gallery-viewer-prev {
    grid-area: 2 / 1;
    justify-self: end;
  }

  .gallery-viewer-next {
    grid-area: 2 / 2;
    justify-self: start;
  }
}

@keyframes gallery-viewer-enter {
  from { opacity: 0; transform: scale(.985); }
  to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-viewer[open] { animation: none; }
  .gallery-viewer-button { transition: none; }
}
