.gallery-intro {
  padding: clamp(28px, 5vw, 64px) var(--page-padding);
  border-bottom: 1px solid var(--border);
}
.gallery-page .section-line {
  flex-wrap: wrap;
}
.gallery-intro h1 {
  margin: 0 0 16px;
  font: 500 clamp(40px, 7vw, 88px)/1.05 var(--display);
  letter-spacing: -0.045em;
}
.gallery-intro p {
  max-width: 64ch;
  margin: 0;
  color: var(--soft);
  font-size: 18px;
}
.gallery-controls {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 0.35fr) auto;
  border-bottom: 1px solid var(--border);
}
.gallery-controls label {
  display: grid;
  gap: 7px;
  padding: 18px var(--page-padding);
  border-right: 1px solid var(--border);
  font: 500 12px/1.5 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.gallery-controls input,
.gallery-controls select {
  min-width: 0;
  width: 100%;
  padding: 8px 0;
  background: transparent;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font: 400 16px/1.5 var(--font);
}
.gallery-controls option {
  background: var(--bg);
}
.gallery-controls button {
  border: 0;
  background: transparent;
  padding: 24px;
  cursor: pointer;
}
.gallery-controls button:hover {
  background: var(--surface);
}
.gallery-status {
  margin: 0;
  padding: 16px var(--page-padding);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.gallery-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.gallery-card:nth-child(3n) {
  border-right-color: transparent;
}
.gallery-preview {
  --image-inset: clamp(16px, 2vw, 32px);
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 11;
  padding: var(--image-inset);
  background: var(--surface);
  border: 0;
  cursor: zoom-in;
}
.gallery-preview:hover {
  background: var(--surface-2);
}
.gallery-image {
  position: absolute;
  inset: var(--image-inset);
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-preview img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  object-fit: contain;
  filter: drop-shadow(0 5px 10px #0002);
}
.gallery-preview.image-unavailable::after {
  content: "Preview unavailable";
  color: var(--muted);
}
.gallery-preview.image-unavailable img {
  display: none;
}
.gallery-card-details {
  padding: 22px clamp(20px, 2vw, 32px) 28px;
}
.gallery-card h2 {
  margin: 0;
  font: 500 18px/1.4 var(--mono);
  overflow-wrap: anywhere;
}
.gallery-card-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 8px;
  min-width: 0;
}
.gallery-optional {
  display: inline-block;
  flex: none;
  color: var(--muted);
  font: 400 12px/1.5 var(--mono);
}
.gallery-optional[hidden] {
  display: none;
}
.gallery-viewer .gallery-card-heading {
  margin-bottom: 0;
}
.gallery-card h2 a:hover,
.gallery-viewer h2 a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 4px;
}
.gallery-card p {
  margin: 0;
  color: var(--soft);
  line-height: 1.6;
}
.gallery-more-wrap {
  padding: 28px var(--page-padding);
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.gallery-more-wrap:has(button[hidden]) {
  display: none;
}
.gallery-viewer {
  max-width: min(96vw, 1800px);
  width: 96vw;
  max-height: 94svh;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.gallery-viewer::backdrop {
  background: #000b;
}
.gallery-viewer header,
.gallery-viewer footer {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}
.gallery-viewer header {
  border-bottom: 1px solid var(--border);
}
.gallery-viewer h2 {
  margin: 0;
  font: 500 18px/1.4 var(--mono);
  overflow-wrap: anywhere;
}
.gallery-viewer-image {
  display: flex;
  align-items: center;
  justify-content: center;
  height: min(65svh, 1050px);
  padding: 20px;
  background: var(--surface);
}
.gallery-viewer img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  object-fit: contain;
}
.gallery-viewer p {
  margin: 0;
  padding: 14px 24px;
}
.gallery-viewer footer {
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.gallery-viewer button {
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
}
.gallery-viewer button:hover:not(:disabled) {
  background: var(--surface);
}
.gallery-viewer button:disabled {
  opacity: 0.4;
  cursor: default;
}
.gallery-viewer nav {
  display: flex;
  align-items: center;
  gap: 12px;
}
.gallery-source {
  text-decoration: underline;
  text-underline-offset: 4px;
}
@media (max-width: 1050px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .gallery-card:nth-child(3n) {
    border-right-color: var(--border);
  }
  .gallery-card:nth-child(2n) {
    border-right-color: transparent;
  }
}
@media (max-width: 640px) {
  .gallery-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .gallery-card {
    border-right: 0 !important;
  }
  .gallery-controls {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .gallery-controls label:first-child {
    grid-column: 1 / -1;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .gallery-controls label {
    padding: 14px 20px;
  }
  .gallery-viewer-image {
    height: 50svh;
    padding: 10px;
  }
  .gallery-viewer header,
  .gallery-viewer footer,
  .gallery-viewer p {
    padding: 12px;
  }
}
