.farm-gallery {
  --gallery-gap: clamp(1rem, 2.15vw, 2.8rem);
  padding: clamp(3.5rem, 7vw, 8rem) max(var(--folio-pad), calc((100% - 100rem) / 2));
  background: var(--folio-paper);
  color: var(--folio-green);
}
.farm-gallery > h2 {
  margin-bottom: clamp(1.4rem, 2.7vw, 2.7rem);
  font-size: var(--type-chapter);
  line-height: .96;
  letter-spacing: -.047em;
  text-wrap: balance;
}
.gallery-selection, .gallery-grid {
  display: grid;
  gap: var(--gallery-gap);
}
.gallery-selection { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.gallery-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: var(--gallery-gap); }
.farm-gallery figure { margin: 0; min-width: 0; }
.gallery-selection figure > a, .gallery-grid figure > a {
  display: block;
  background: #d6dfd5;
  cursor: zoom-in;
}
.gallery-selection img, .gallery-grid img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}
.gallery-selection figcaption, .gallery-grid figcaption {
  margin-top: .55rem;
  color: #405b4f;
  font-size: .96rem;
  line-height: 1.4;
}
@media (min-width: 681px) {
  .gallery-selection > :first-child { grid-row: span 2; display: flex; flex-direction: column; }
  .gallery-selection > :first-child > a { flex: 1; position: relative; }
  .gallery-selection > :first-child img { position: absolute; inset: 0; height: 100%; }
  .gallery-selection > :not(:first-child) img { aspect-ratio: 2.05 / 1; }
}
.gallery-open { overflow: hidden; }
.gallery-view:not([open]) { display: none; }
.gallery-view[open] {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr) auto;
  gap: .75rem clamp(1rem, 2.5vw, 2rem);
  width: min(81rem, calc(100% - 3rem));
  height: min(62rem, calc(100vh - 3rem));
  height: min(62rem, calc(100dvh - 3rem));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: .65rem clamp(1rem, 2vw, 2rem) 1rem;
  border: 0;
  background: #102b28;
  color: #f0f3e7;
  overflow: auto;
  overscroll-behavior: contain;
}
.gallery-view::backdrop { background: rgb(5 18 17 / 87%); }
.gallery-tools {
  grid-area: 1 / 1 / 2 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.gallery-count { color: #c8d8cf; font-size: .96rem; font-variant-numeric: tabular-nums; }
.gallery-view button { min-height: 44px; padding: .5rem .3rem; }
.gallery-view button:hover { text-decoration: underline; text-underline-offset: .25em; }
.gallery-slide { display: contents; }
.gallery-slide img {
  grid-area: 2 / 1 / 3 / -1;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: scale-down;
  touch-action: pan-y pinch-zoom;
}
.gallery-caption {
  grid-area: 3 / 1;
  align-self: center;
  font: 500 clamp(1.25rem, 2.2vw, 2rem)/1.15 var(--serif);
}
.gallery-nav {
  grid-area: 3 / 2;
  display: flex;
  align-items: center;
  justify-content: end;
  gap: clamp(.85rem, 2vw, 2rem);
}
@media (max-width: 900px) {
  .gallery-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .gallery-selection, .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-selection > :first-child { grid-column: 1 / -1; }
  .gallery-selection > :not(:first-child) img, .gallery-grid img { aspect-ratio: 1.35; }
  .gallery-view[open] {
    grid-template: auto minmax(6rem, 1fr) auto auto / minmax(0, 1fr);
    gap: .5rem;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: max(.6rem, env(safe-area-inset-top)) 1rem max(.7rem, env(safe-area-inset-bottom));
  }
  .gallery-caption { padding-top: .35rem; }
  .gallery-nav { grid-area: 4 / 1; justify-content: space-between; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .gallery-view[open] {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    gap: .2rem .75rem;
    grid-template: auto minmax(5rem, 1fr) auto / minmax(0, 1fr) auto;
    padding: 0 max(1rem, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(1rem, env(safe-area-inset-left));
  }
  .gallery-nav { grid-area: 3 / 2; }
}
