/* ==========================================================================
   Gallery — masonry, filter & sort, infinite scroll and the lightbox (moey.js).
   ========================================================================== */

/* Masonry: columns from the grid utilities (or automatic), heights packed by moey.js */
.masonry {
  --mo-masonry-min: 14rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--mo-masonry-min)), 1fr));
  gap: 1rem;
  align-items: start;
}
/* the grid-cols-* utilities set --mo-columns (phone first: grid-cols-2 md:grid-cols-4) */
.masonry[class*="grid-cols-"] { grid-template-columns: repeat(var(--mo-columns, 3), minmax(0, 1fr)); }
.masonry.is-ready { grid-auto-rows: 1px; row-gap: 0 !important; }   /* (beats a gap-* utility: the gap is measured first and built into each span) */
.masonry > * { min-width: 0; margin: 0; }
.masonry > .span-2 { grid-column: span 2; }
.masonry > .span-3 { grid-column: span 3; }
.masonry-dense { grid-auto-flow: row dense; }
@supports (grid-template-rows: masonry) {
  .masonry { grid-template-rows: masonry; }
  .masonry.is-ready { grid-auto-rows: auto; row-gap: revert-layer; }
}
/* Picture tiles */
.masonry img,
.gallery-tile img { display: block; width: 100%; height: auto; border-radius: var(--mo-radius-card); }
.gallery-tile { position: relative; display: block; overflow: hidden; color: inherit; text-decoration: none; border-radius: var(--mo-radius-card); }
.gallery-tile:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 2px; }
.gallery-tile > figcaption,
.gallery-tile > .gallery-caption { position: absolute; inset: auto 0 0; padding: 1.5rem .75rem .625rem; font-size: .8125rem; color: #fff; background: linear-gradient(transparent, rgb(0 0 0 / .6)); opacity: 0; transition: opacity var(--mo-duration) var(--mo-ease); }
.gallery-tile:is(:hover, :focus-visible) > :is(figcaption, .gallery-caption) { opacity: 1; }
@media (hover: none) { .gallery-tile > :is(figcaption, .gallery-caption) { opacity: 1; } }

/* Filter & sort */
.filter-empty[hidden] { display: none; }
.filter-empty { grid-column: 1 / -1; padding: 2rem 1rem; color: var(--mo-fg-3); text-align: center; }
[data-moey-filters] [aria-pressed="true"]:is(.btn, .chip) { --mo-btn-bg: var(--mo-default-base); }

/* Infinite scroll */
.infinite-status { display: flex; gap: .625rem; align-items: center; justify-content: center; min-height: 3rem; padding: .75rem 0; font-size: .875rem; color: var(--mo-fg-3); }
.infinite-status:has(.infinite-text:empty):has(.spinner[hidden]):has(.infinite-more[hidden]) { min-height: 0; padding: 0; }
.infinite-sentinel { height: 1px; }

/* Lightbox — phone first: full bleed, controls float on soft gradients, one tap hides them */
.lightbox {
  --lb-bg: 8 9 11;
  --lb-fade: 1;
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
  color: #fff;
  background: rgb(var(--lb-bg) / var(--lb-fade));   /* solid; it fades only while you pull it down */
  border: 0;
  overscroll-behavior: contain;
}
.lightbox::backdrop { background: transparent; }
html.mo-lightbox-open { overflow: hidden; }
.lightbox[open] { display: block; }
.lightbox-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.lightbox-track { position: absolute; inset: 0; }
.lightbox-slide { position: absolute; inset: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; padding: 3.5rem 0 4.5rem; }   /* a fixed-size cell: the media fits inside it */
.lightbox-slide[data-pos="-1"] { translate: -100% 0; }
.lightbox-slide[data-pos="1"] { translate: 100% 0; }
.lightbox-slide:dir(rtl)[data-pos="-1"] { translate: 100% 0; }
.lightbox-slide:dir(rtl)[data-pos="1"] { translate: -100% 0; }
.lightbox-media { max-width: 100%; max-height: 100%; user-select: none; -webkit-user-drag: none; transform-origin: center; }
img.lightbox-media { object-fit: contain; cursor: zoom-in; }
.lightbox.is-zoomed img.lightbox-media { cursor: grab; }
video.lightbox-media { width: 100%; max-height: 100%; background: #000; }
.lightbox-frame { width: min(100%, 64rem); aspect-ratio: 16 / 9; max-height: 100%; }
.lightbox-frame-page { width: min(100%, 60rem); height: 100%; aspect-ratio: auto; }
.lightbox-frame iframe { width: 100%; height: 100%; border: 0; background: #000; }
.lightbox-frame-page iframe { background: #fff; border-radius: .375rem; }
.lightbox-audio { display: grid; gap: 1rem; justify-items: center; width: min(92%, 24rem); margin: 0; }
.lightbox-audio img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 1rem; }
.lightbox-audio-icon { display: grid; place-items: center; width: 10rem; aspect-ratio: 1; font-size: 3rem; background: rgb(255 255 255 / .08); border-radius: 1rem; }
.lightbox-audio audio { width: 100%; }
.lightbox-html { width: min(92%, 40rem); max-height: 100%; padding: 1.5rem; overflow: auto; color: var(--mo-fg-body); background: var(--mo-bg-surface); border-radius: var(--mo-radius-card); }
.lightbox-placeholder img { max-width: 100%; max-height: 100%; opacity: .5; }
/* Controls */
.lightbox-top, .lightbox-bottom { position: absolute; inset-inline: 0; z-index: 2; transition: opacity .2s, translate .2s; }
.lightbox-top { top: 0; display: flex; gap: .25rem; align-items: center; padding: max(.5rem, env(safe-area-inset-top)) .5rem 1.5rem 1rem; background: linear-gradient(rgb(var(--lb-bg) / .7), transparent); }
.lightbox-top > .spacer { flex: 1; }
.lightbox-bottom { bottom: 0; display: grid; gap: .5rem; padding: 1.5rem 1rem max(.75rem, env(safe-area-inset-bottom)); pointer-events: none; background: linear-gradient(transparent, rgb(var(--lb-bg) / .75)); }
.lightbox-bottom > * { pointer-events: auto; }
.lightbox-count { font-size: .875rem; font-variant-numeric: tabular-nums; color: rgb(255 255 255 / .8); }
.lightbox-count[hidden] { display: none; }
.lightbox-caption { max-height: 30dvh; overflow: auto; font-size: .9375rem; line-height: 1.45; text-align: center; }
.lightbox-caption[hidden] { display: none; }
.lightbox-thumbs { display: flex; gap: .375rem; justify-content: safe center; overflow-x: auto; scrollbar-width: none; }
.lightbox-thumbs[hidden] { display: none; }
.lightbox-thumbs button { display: grid; flex: none; place-items: center; width: 3.25rem; height: 3.25rem; padding: 0; overflow: hidden; color: #fff; cursor: pointer; background: rgb(255 255 255 / .1); border: 0; border-radius: .375rem; opacity: .5; }
.lightbox-thumbs button[aria-current="true"] { opacity: 1; box-shadow: 0 0 0 2px #fff; }
.lightbox-thumbs img { width: 100%; height: 100%; object-fit: cover; }
.lightbox-btn { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; font-size: 1.25rem; color: #fff; text-decoration: none; cursor: pointer; background: none; border: 0; border-radius: 999px; }
.lightbox-btn:hover { background: rgb(255 255 255 / .14); }
.lightbox-btn:focus-visible, .lightbox-thumbs button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.lightbox-btn[hidden] { display: none; }
.lightbox-prev, .lightbox-next { position: absolute; top: 50%; z-index: 2; display: none; translate: 0 -50%; background: rgb(var(--lb-bg) / .45); transition: opacity .2s; }
.lightbox-prev { inset-inline-start: .75rem; }
.lightbox-next { inset-inline-end: .75rem; }
/* One tap (touch): only the picture */
.lightbox.is-bare .lightbox-top { opacity: 0; translate: 0 -.5rem; pointer-events: none; }
.lightbox.is-bare .lightbox-bottom { opacity: 0; translate: 0 .5rem; }
.lightbox.is-bare .lightbox-bottom > * { pointer-events: none; }
.lightbox.is-zoomed .lightbox-bottom { opacity: 0; pointer-events: none; }
/* Larger screens with a mouse: arrows, more room */
@media (hover: hover) and (width >= 576px) {
  .lightbox-prev:not([hidden]), .lightbox-next:not([hidden]) { display: grid; }
  .lightbox-slide { padding: 4rem 4.5rem 6rem; }
  .lightbox:has(.lightbox-thumbs:not([hidden])) .lightbox-slide { padding-bottom: 7.5rem; }
}
@media (prefers-reduced-motion: reduce) { .lightbox-top, .lightbox-bottom, .lightbox-prev, .lightbox-next { transition: none; } }

/* Hidden items really go (tiles set their own display) */
:where(.masonry, .filter-items) > [hidden] { display: none !important; }
