/* ==========================================================================
   Galleries (design.md 7b-2, 7b-3, 7b-5, §5.4, §6 Lightbox): masonry blocks,
   filter pills, floating frames + tilt, "Load more", lens and the lightbox.
   Every batch of photos is its own CSS-columns block, so loading more never
   reshuffles the photos already on screen.
   ========================================================================== */

/* ---- filter pills (sticky under the header on phones) -------------------- */
.filters { display: none; }
.js .filters {
  display: flex;
  gap: 8px;
  margin: 0 calc(var(--gutter) * -1) var(--stack-md);
  padding: 10px var(--gutter);
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  position: sticky;
  top: calc(var(--header-h) * .8 + env(safe-area-inset-top));
  z-index: 20;
  background: var(--c-ivory);
  transition: background-color var(--dur-theme);
}
.filters::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--c-line);
  border-radius: 999px;
  background: transparent;
  color: var(--c-ink);
  font-size: .76rem;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color .3s, color .3s, border-color .3s;
}
.pill:hover { border-color: var(--c-brand); }
.pill[aria-pressed="true"] { background: var(--c-brand); border-color: var(--c-brand); color: var(--c-on-brand); }
.pill-count { font-size: .7rem; letter-spacing: .06em; opacity: .75; font-variant-numeric: tabular-nums; }
@media (min-width: 48em) {
  .js .filters { flex-wrap: wrap; justify-content: center; overflow: visible; position: static; margin-inline: 0; padding-inline: 0; background: none; }
}

/* ---- masonry (CSS columns; 2 / 3 / 4 / 5 columns) ------------------------ */
.gallery-blocks { transition: opacity .25s ease, transform .25s ease; }
.gallery-blocks.is-swapping { opacity: 0; transform: scale(.985); }
.masonry {
  --gap: 6px;
  list-style: none;
  columns: 2;
  column-gap: var(--gap);
}
.masonry + .masonry { margin-top: var(--gap); }
@media (min-width: 48em) { .masonry { --gap: var(--grid-gap); columns: 3; } }
@media (min-width: 80em) { .masonry { columns: 4; } }
@media (min-width: 120em) { .masonry { columns: 5; } }

.g-item { break-inside: avoid; margin-bottom: var(--gap); }
.g-link {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--c-linen);
  transition: background-color var(--dur-theme);
}
.g-link img { width: 100%; height: auto; transition: transform .7s var(--ease-out), opacity .3s; }
@media (hover: hover) and (pointer: fine) {
  .g-link:not(.lens):hover img { transform: scale(1.05); }
}
@media (prefers-reduced-motion: no-preference) {
  .masonry.is-new .g-item { animation: g-in .6s var(--ease-out) backwards; }
  .masonry.is-new .g-item:nth-child(4n+2) { animation-delay: 60ms; }
  .masonry.is-new .g-item:nth-child(4n+3) { animation-delay: 120ms; }
  .masonry.is-new .g-item:nth-child(4n) { animation-delay: 180ms; }
}
@keyframes g-in { from { opacity: 0; transform: translate3d(0, 16px, 0); } }

/* Floating frames (every 7th tile): flat on phones; rotated, overlapping and tilting from lg */
.g-item--frame .g-link { padding: 6px; background: var(--c-frame); box-shadow: 0 10px 30px var(--c-shadow); }
@media (min-width: 64em) {
  [data-frames] .g-item--frame {
    position: relative;
    z-index: 2;
    margin-top: -24px;
    transform: perspective(900px) rotate(var(--rot, 0deg)) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  }
  [data-frames] .g-item--frame .g-link { padding: 10px; }
  [data-frames] .g-item--frame:first-child { margin-top: 0; }
}

.gallery-status { margin-top: var(--stack-md); text-align: center; font-size: var(--fs-small); color: var(--c-ink-soft); letter-spacing: .06em; }
.gallery-status:empty { display: none; }
.gallery-more { margin-top: var(--stack-sm); text-align: center; }
.gallery-more .btn[hidden] { display: none; }

/* curtain over a gallery: the linen panels split from the centre (7b-2); keep gallery sections on ivory */
.gallery-curtain { min-height: 240px; }

/* ---- lens (7b-5) ----------------------------------------------------------- */
.lens-glass { display: none; }
@media (hover: hover) and (pointer: fine) {
  .has-lens .lens { cursor: zoom-in; }
  .has-lens .lens.is-lensing { cursor: none; }
  .lens-glass {
    display: block;
    position: absolute;
    top: 0; left: 0;
    z-index: 3;
    width: 160px; height: 160px;
    border-radius: 50%;
    border: 1px solid rgba(251, 248, 243, .9);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .28), inset 0 0 0 4px rgba(251, 248, 243, .15);
    background-color: var(--c-linen);
    background-repeat: no-repeat;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s ease;
  }
  .lens.is-lensing .lens-glass { opacity: 1; }
}

/* ---- lightbox ---------------------------------------------------------------- */
html.lb-open, html.lb-open body { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: rgba(18, 15, 13, .96);
  color: #F4EEE5;
}
.lightbox[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .lightbox.is-open { animation: fade-in .3s ease both; }
  .lightbox.is-open .lb-stage img { animation: lb-in .4s var(--ease-out) both; }
}
@keyframes lb-in { from { opacity: 0; transform: scale(.97); } }
.lb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px 0 20px; }
.lb-count { font-size: .78rem; letter-spacing: .2em; font-variant-numeric: tabular-nums; color: rgba(244, 238, 229, .8); }
.lb-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  touch-action: pinch-zoom;
}
.lb-stage picture { display: contents; }
.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 2px;
  transition: opacity .3s ease;
  user-select: none;
  -webkit-user-drag: none;
}
.lb-stage.is-loading img { opacity: .35; }
.lb-caption { padding: 8px 20px 12px; text-align: center; font-size: var(--fs-small); color: rgba(244, 238, 229, .82); }
.lb-btn {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px;
  padding: 0;
  border: 1px solid rgba(244, 238, 229, .35);
  border-radius: 50%;
  background: rgba(18, 15, 13, .4);
  color: inherit;
  transition: background-color .3s, border-color .3s;
}
.lb-btn:hover { background: rgba(244, 238, 229, .12); border-color: rgba(244, 238, 229, .7); }
.lb-btn .icon { width: 24px; height: 24px; }
.lb-close { border-color: transparent; }
.lb-prev, .lb-next { display: none; position: absolute; top: 50%; margin-top: -24px; z-index: 2; }
.lb-prev { left: max(16px, env(safe-area-inset-left)); }
.lb-next { right: max(16px, env(safe-area-inset-right)); }
.lightbox :focus-visible { outline-color: #E7C987; }
@media (min-width: 48em) {
  .lb-prev, .lb-next { display: inline-grid; }
  .lb-prev[hidden], .lb-next[hidden] { display: none; }
  .lb-stage { padding: 12px 88px; }
}
.lb-thumbs { display: none; }
@media (min-width: 64em) {
  .lb-thumbs { display: flex; justify-content: center; gap: 8px; padding: 0 20px 16px; }
  .lb-thumb { width: 64px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: 3px; background: none; overflow: hidden; opacity: .55; transition: opacity .3s, border-color .3s; }
  .lb-thumb img { width: 100%; height: 100%; object-fit: cover; }
  .lb-thumb:hover { opacity: .9; }
  .lb-thumb[aria-current="true"] { opacity: 1; border-color: #F4EEE5; }
}

@media print { .filters, .gallery-more, .lightbox { display: none !important; } .g-item:nth-child(n+5) { display: none; } }
