.gallery-main {
  width: min(calc(100% - 2 * var(--gutter)), var(--frame));
  min-width: 0;
  margin: var(--space-8) auto var(--space-12);
}
.gallery-opening {
  min-width: 0;
  margin-block-end: var(--space-6);
}
.gallery-masthead .eyebrow {
  margin: 0 0 var(--space-3);
  color: var(--accent);
}
.gallery-masthead h1 {
  margin: 0 0 var(--space-3);
  font: 500 clamp(3.25rem, 7vw, 7rem)/1 var(--serif);
  letter-spacing: -.045em;
}
.gallery-masthead h1 span {
  display: block;
  margin-block-start: .18em;
  font-size: .68em;
  font-weight: 400;
  font-style: italic;
  line-height: .98;
}
.gallery-masthead .page-intro {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1rem, 1.55vw, 1.3rem);
}
.gallery-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  width: min(100%, 25rem);
  margin-block-start: var(--space-4);
  padding-block: var(--space-2);
  border-block: 1px solid var(--line);
}
.gallery-tools input {
  flex: 1 1 11rem;
  width: min(100%, 18rem);
  min-width: 0;
}
.gallery-tools p { margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.gallery-help { max-width: 38ch; margin: var(--space-2) 0 0; }
.gallery-opening .empty-state { margin-block-end: var(--space-2); }

#wall {
  display: grid;
  align-items: start;
  gap: var(--space-6) var(--space-4);
}
.slide { min-width: 0; margin: 0; }
.photo-open {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100px;
  max-width: 100%;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 2px;
  background: var(--soft-surface);
  cursor: zoom-in;
}
.gallery-main .photo-open:hover { background: var(--soft-surface); }
.photo-open img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  transition: opacity var(--motion), transform var(--motion);
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .photo-open:not(.is-loading, .is-error):hover img { transform: scale(1.02); }
}
.photo-open.is-loading img { opacity: 0; }
.photo-open.is-error { min-height: 220px; }
.photo-state {
  position: absolute;
  inset: auto 12px;
  padding: 8px;
  border-radius: var(--radius-control);
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  font-size: .875rem;
}
.slide figcaption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  margin-block-start: var(--space-2);
  padding-block-start: var(--space-2);
  border-top: 1px solid var(--line);
}
.slide h2 { margin: 0; font: 500 clamp(1.375rem, 2vw, 1.75rem)/1.3 var(--serif); }
.slide figcaption p {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: .875rem;
  white-space: pre-wrap;
}
.slide .photo-number {
  color: var(--muted);
  font: .75rem/1.2 var(--sans);
  font-variant-numeric: tabular-nums;
  letter-spacing: .08em;
  white-space: nowrap;
}
@media (min-width: 768px) {
  #wall { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: var(--space-8); }
  #wall > .slide:is(:first-child, :last-child) { grid-column: 1 / -1; }
}

/* The opening photo stays a real gallery item, including its preview and deep link. */
@media (min-width: 1024px) {
  .gallery-main:has(#wall > .slide:first-child:not([hidden])) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: var(--space-8) var(--space-6);
  }
  .gallery-main:has(#wall > .slide:first-child:not([hidden])) #wall { display: contents; }
  .gallery-main:has(#wall > .slide:first-child:not([hidden])) .gallery-opening {
    align-self: center;
    margin: 0;
    padding-inline-start: clamp(0px, 2vw, 32px);
  }
  .gallery-main:has(#wall > .slide:first-child:not([hidden])) #wall > .slide:first-child { grid-column: 2; }
  .gallery-main:has(#wall > .slide:first-child:not([hidden])) #wall > .slide:last-child { grid-column: 1 / -1; }
}

/* The full-screen viewer keeps a dark surround in both site themes. */
.lightbox {
  --viewer-base: #181b18;
  --viewer-ink: #f4f4ef;
  --viewer-muted: #c1c8bd;
  --viewer-focus: #e4eccf;
  --viewer-control-hover: rgba(255, 255, 255, .14);
  --viewer-control-border: rgba(255, 255, 255, .26);
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--viewer-base);
  color: var(--viewer-ink);
  color-scheme: dark;
  overscroll-behavior: contain;
}
:root[data-theme="night"] .lightbox {
  --viewer-base: #0b1019;
  --viewer-ink: #f5f8ff;
  --viewer-muted: #adc1d9;
  --viewer-focus: #a7c3e5;
}
.lightbox::backdrop { background: rgba(0, 0, 0, .9); }
.lightbox-shell {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 100%;
  height: 100%;
  padding: var(--space-3) max(var(--space-3), var(--gutter));
}
.lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  gap: 16px;
  padding-block-end: var(--space-2);
  border-bottom: 1px solid var(--viewer-control-border);
}
.lightbox-toolbar h2 { margin: 0; font: 500 clamp(1.375rem, 3vw, 2rem)/1.2 var(--serif); }
.lightbox-toolbar p {
  margin: 0 0 6px;
  color: var(--viewer-muted);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: .1em;
}
.lightbox :is(button, .btn) {
  border-color: var(--viewer-control-border);
  background: transparent;
  color: var(--viewer-ink);
}
.lightbox :is(button, .btn):hover { background: var(--viewer-control-hover); }
.lightbox :focus-visible { outline-color: var(--viewer-focus); }
.lightbox-stage {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-width: 0;
  min-height: 100px;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}
.lightbox-stage img {
  position: absolute;
  inset: 0;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  margin: auto;
  object-fit: contain;
}
.lightbox-stage #lightbox-status {
  position: absolute;
  bottom: 10px;
  left: 50%;
  max-width: 95%;
  margin: 0;
  padding: 8px 16px;
  transform: translateX(-50%);
  border-radius: var(--radius-control);
  background: var(--viewer-base);
  text-align: center;
  font-size: .875rem;
}
.lightbox-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  flex: none;
  gap: 8px 20px;
  padding-block-start: var(--space-2);
  border-top: 1px solid var(--viewer-control-border);
}
.lightbox-controls, .lightbox-links { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lightbox-links { justify-content: end; font-size: .875rem; }
.lightbox-links a { min-height: 44px; padding: 10px; }
.lightbox-footer p { margin: 0; color: var(--viewer-muted); font-size: .8125rem; }
.lightbox-footer #lightbox-description { grid-column: 1/-1; font-size: .875rem; white-space: pre-wrap; }
.lightbox-footer #lightbox-help { grid-column: 1/-1; }
.lightbox-footer #share-status { grid-column: 1/-1; user-select: all; }
.lightbox #lightbox-close { font-size: .875rem; }
.lightbox-close-mark {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 12px;
}
.lightbox-close-mark::before, .lightbox-close-mark::after {
  position: absolute;
  inset: 50% 0 auto;
  border-top: 1px solid currentColor;
  content: '';
  transform: rotate(45deg);
}
.lightbox-close-mark::after { transform: rotate(-45deg); }
.lightbox-footer p:empty { display: none; }

@media (max-width: 767px) {
  .gallery-main { margin-block: var(--space-6) var(--space-8); }
  .gallery-masthead .eyebrow { margin-bottom: var(--space-2); }
  .gallery-masthead h1 { margin-bottom: var(--space-2); font-size: clamp(2.75rem, 11vw, 4.25rem); }
  .gallery-tools { margin-block-start: var(--space-3); }
  .gallery-opening { margin-block-end: var(--space-4); }
  .lightbox-shell { gap: 10px; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .lightbox-footer { grid-template-columns: 1fr; gap: 10px; }
  .lightbox-links { justify-content: start; }
  .lightbox-toolbar h2 { font-size: 22px; }
  .lightbox-footer button, .lightbox-links a { padding: 8px 12px; font-size: .8125rem; }
  .lightbox-controls { justify-content: space-between; }
  .lightbox-footer #lightbox-help { font-size: .75rem; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .lightbox-shell { gap: 5px; padding: 8px 12px; }
  .lightbox-toolbar, .lightbox-footer { padding-block: 4px; }
  .lightbox-toolbar h2 { font-size: 18px; }
  .lightbox-toolbar p, .lightbox-footer #lightbox-help { display: none; }
  .lightbox-footer { grid-template-columns: 1fr 1fr; gap: 4px; }
  .lightbox-links { justify-content: end; }
}
