/* Hindsight Farms: Gallery page (2026-10-01, step 3).
   One open grid of all 27 photographs, category filters, and a full-screen
   viewer in a native <dialog>. Loaded only by gallery.html, right after
   main.css. It uses the shared controls at the end of main.css (.ctl-row,
   .ctl-arrow, .ctl-counter, .media-caption) and scopes its few variants to
   this page. The old viewer, thumbnail rail and browse grid rules in
   main.css section 32 (.gallery-focus, .gallery-stage, .gallery-thumb,
   .gallery-browse, .gallery-tile) no longer match anything here; the intro,
   film and closing band keep their main.css rules. */

/* INTRO: one button now ("Open photo grid" was retired), so on phones it
   takes the whole row instead of half of main.css's two-column grid. */
@media (max-width: 640px) {
  .page--gallery .gallery-intro__actions { grid-template-columns: 1fr; }
}

/* FILTER BAR: buttons on the left, photo count on the right; on phones the
   buttons wrap to two rows and the count drops beneath them. */
.page--gallery .gallery-photos__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.page--gallery .gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.page--gallery .gallery-filters[hidden] { display: none; }
.page--gallery .gallery-filter {
  appearance: none;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--tan);
  border-radius: var(--radius);
  background: transparent;
  color: var(--bark);
  font-family: var(--font-body);
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1;
  letter-spacing: .04em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}
.page--gallery .gallery-filter:hover { background: var(--cream); border-color: var(--bark); }
.page--gallery .gallery-filter[aria-pressed="true"] {
  background: var(--bark);
  border-color: var(--bark);
  color: var(--paper);
}
.page--gallery .gallery-filter:focus-visible { outline: 2px solid var(--bark); outline-offset: 2px; }
.page--gallery .gallery-photos__count {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: .04em;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--stone);
}

/* GRID: 2 columns on phones, 3 at tablet widths, 4 on desktop. Plain photos
   in a 3:2 frame; each caption sits below its photo on one line. The img
   sizes attribute in gallery.html mirrors these column widths. */
.page--gallery .gallery-photos__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 12px;
}
.page--gallery .gallery-photo { min-width: 0; }
.page--gallery .gallery-photo[hidden] { display: none; }
.page--gallery .gallery-photo__link {
  display: block;
  color: inherit;
}
.page--gallery .gallery-photos.is-enhanced .gallery-photo__link { cursor: zoom-in; }
.page--gallery .gallery-photo__link:focus-visible { outline: 2px solid var(--bark); outline-offset: 4px; }
.page--gallery .gallery-photo__frame {
  position: relative;
  display: block;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--cream);
}
.page--gallery .gallery-photo__frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.page--gallery .gallery-photo__caption {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color var(--ease);
}
@media (hover: hover) {
  .page--gallery .gallery-photo__link:hover .gallery-photo__caption { color: var(--bark); }
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .page--gallery .gallery-photo__frame img { transition: transform 240ms ease-out; }
  .page--gallery .gallery-photo__link:hover .gallery-photo__frame img { transform: scale(1.025); }
}

@media (max-width: 640px) {
  .page--gallery .gallery-photos__bar { gap: 12px; margin-bottom: 20px; }
  .page--gallery .gallery-filters { gap: 6px; }
  .page--gallery .gallery-filter { padding: 0 12px; font-size: 13px; }
}
@media (min-width: 641px) {
  .page--gallery .gallery-photos__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
}
@media (min-width: 1024px) {
  .page--gallery .gallery-photos__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* VIEWER: a full-screen native <dialog> on a dark ground. Three rows: the
   Close button, the photo (as large as the screen allows, never past its
   1600px file), and the caption with previous / counter / next. */
.page--gallery .gallery-viewer {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--ink);
  color: var(--cream);
  overflow: hidden;
  overscroll-behavior: contain;
}
.page--gallery .gallery-viewer[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.page--gallery .gallery-viewer::backdrop { background: transparent; }

.page--gallery .gallery-viewer__top {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px;
}
.page--gallery .gallery-viewer__close.ctl-arrow {
  width: auto;
  gap: 8px;
  padding: 0 12px 0 16px;
  font-family: var(--font-body);
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1;
  letter-spacing: .04em;
}
.page--gallery .gallery-viewer__close svg { width: 18px; height: 18px; }

.page--gallery .gallery-viewer__stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;   /* horizontal swipes reach gallery.js */
  -webkit-user-select: none;
  user-select: none;
}
/* Two layers in the same box: the grid's 800px file shows at once, the
   1600px file covers it when it arrives. Same aspect ratio, same rect. */
.page--gallery .gallery-viewer__placeholder,
.page--gallery .gallery-viewer__image {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 100%;
  height: 100%;
  max-width: 1600px;
  max-height: 1200px;
  object-fit: contain;
  -webkit-user-drag: none;
}
.page--gallery .gallery-viewer__image { opacity: 0; }
.page--gallery .gallery-viewer__image.is-loaded { opacity: 1; }

.page--gallery .gallery-viewer__bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 16px;
  text-align: center;
}
.page--gallery .gallery-viewer__caption { margin: 0; max-width: 100%; }

@media (min-width: 768px) {
  .page--gallery .gallery-viewer__top { padding: 16px 24px; }
  .page--gallery .gallery-viewer__stage { margin-inline: 24px; }
  .page--gallery .gallery-viewer__bar {
    flex-direction: row;
    justify-content: space-between;
    gap: 24px;
    padding: 16px 24px 20px;
    text-align: left;
  }
}
/* Short screens (phones held sideways): slimmer bars, more photo. */
@media (max-height: 520px) {
  .page--gallery .gallery-viewer__top { padding-block: 6px; }
  .page--gallery .gallery-viewer__bar { padding-block: 6px 8px; }
}

/* Page scroll is locked while the viewer is open (gallery.js toggles the
   class). The stable gutter stops the page shifting when the scrollbar goes. */
html.gallery-viewer-open { overflow: hidden; scrollbar-gutter: stable; }
html.gallery-viewer-open body { overflow: hidden; }

/* Motion: a short fade as the viewer opens and as the sharp photo lands.
   Nothing moves under reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .page--gallery .gallery-viewer[open] { animation: gallery-viewer-in 180ms ease-out; }
  .page--gallery .gallery-viewer__image.is-loaded { transition: opacity 200ms ease-out; }
}
@keyframes gallery-viewer-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .page--gallery .gallery-viewer[open] { animation: none; }
  .page--gallery .gallery-viewer__image,
  .page--gallery .gallery-photo__frame img,
  .page--gallery .gallery-photo__caption,
  .page--gallery .gallery-filter { transition: none; }
}
