:root {
  --bg: #050505;
  --fg: #f5f5f3;
  --dim: #7a7a76;
  --line: #1c1c1a;
  --gap: 8px;
  --content-w: 1280px;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  scrollbar-color: #333 #000;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Montserrat", "Helvetica Neue", Arial, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; }

/* ---------- Brand logo ----------
   Its own block, in normal flow, above the gallery — not overlaid on any
   photo. Not fixed/sticky, so it scrolls away with the rest of the page. */
.brand {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(48px, 11vh, 108px) 24px clamp(36px, 8vh, 72px);
}
.brand img {
  width: min(38vw, 300px);
  height: auto;
  transition: opacity .25s ease;
  opacity: .96;
}
.brand:hover img { opacity: 1; }

/* ---------- Gallery ---------- */
main#gallery {
  position: relative;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: var(--gap) var(--gap) 40px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.block {
  content-visibility: auto;
  contain-intrinsic-size: 900px 1200px;
}

.row {
  display: grid;
  gap: var(--gap);
  width: 100%;
}

.frame {
  position: relative;
  overflow: hidden;
  background: #0a0a0a;
  cursor: pointer;
  opacity: 0;
  transform: translateY(22px) scale(.985);
  transition: opacity .8s cubic-bezier(.16,.8,.3,1), transform .8s cubic-bezier(.16,.8,.3,1);
}
/* Reveal is driven by the SAME "loaded" class the image's own onload handler
   sets (reliable, event-based) rather than a separate scroll observer — a
   missed/late visibility callback can therefore never leave a frame stuck
   invisible. :has() falls back gracefully: unsupported browsers just show
   frames immediately via the plain .frame rule below. */
.frame:has(img.loaded) {
  opacity: 1;
  transform: translateY(0) scale(1);
}
@supports not selector(:has(a)) {
  .frame { opacity: 1; transform: none; }
}

.frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.35), rgba(0,0,0,0) 40%);
  opacity: 0;
  transition: opacity .4s ease;
}
.frame:hover::after { opacity: 1; }

.frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.06);
  filter: blur(14px);
  transition: opacity .6s ease, filter .8s ease, transform .7s ease;
}
.frame img.thumb-src { filter: blur(8px); transform: scale(1.02); }
.frame img.loaded {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}
.frame:hover img.loaded { transform: scale(1.02); }

.frame .idx {
  position: absolute;
  left: 14px;
  bottom: 12px;
  font-size: 10px;
  letter-spacing: .2em;
  color: rgba(255,255,255,.75);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .4s ease, transform .4s ease;
  z-index: 2;
}
.frame:hover .idx { opacity: 1; transform: translateY(0); }

/* --- layout templates ---
   Every template below is built so no template can ever leave visible empty
   space: rows either (a) use CSS Grid with align-items:stretch, where every
   cell's height is forced to match the row (aspect-ratio only steers the
   crop, it can never create a gap), or (b) use a flex column that stretches
   to match its sibling's height, or (c) use a true CSS multi-column masonry
   where each item keeps its own natural aspect ratio so nothing needs to
   line up. */

.tpl-full .row { grid-template-columns: 1fr; }
/* No max-height here: combining aspect-ratio with a max-height on a stretched
   grid item makes Chrome shrink the width to match too (not just crop the
   height), leaving a big empty gap beside the image. Width always fills the
   row; a portrait shot just runs tall as a full-bleed moment. */
.tpl-full .frame { aspect-ratio: var(--ar, 1.5/1); }

.tpl-duo .row { grid-template-columns: 1fr 1fr; align-items: stretch; }
.tpl-duo .frame { aspect-ratio: var(--ar, 2/3); }

.tpl-trip .row { grid-template-columns: 1fr 1fr 1fr; align-items: stretch; }
.tpl-trip .frame { aspect-ratio: var(--ar, 3/4); }

/* big image + a stacked pair that stretches to exactly match its height */
.tpl-mosaic .row { grid-template-columns: 1.4fr 1fr; align-items: stretch; }
.tpl-mosaic .frame.big { aspect-ratio: var(--ar, 3/4); }
.tpl-mosaic .col-small {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.tpl-mosaic .frame.small { flex: 1 1 0; min-height: 0; }

/* true masonry: two explicit columns, items pre-sorted by JS (shortest-column-
   first, using each photo's real aspect ratio) so the two stacks land within
   a few px of each other — CSS `column-count` was tried first but its content
   balancing is only a heuristic and regularly left a visible gap under the
   shorter column. */
.tpl-masonry .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
}
.tpl-masonry .col {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.tpl-masonry .frame {
  width: 100%;
  aspect-ratio: var(--ar, 3/4);
}

.tpl-wide-pair .row { grid-template-columns: 2fr 1fr; align-items: stretch; }
.tpl-wide-pair .frame:first-child { aspect-ratio: 16/10; }
.tpl-wide-pair .frame:last-child { aspect-ratio: 3/4; }

@media (max-width: 720px) {
  .tpl-trip .row { grid-template-columns: 1fr 1fr; }
  .tpl-mosaic .row { grid-template-columns: 1fr; }
  .tpl-mosaic .frame.big { aspect-ratio: 4/3; }
  .tpl-mosaic .col-small { flex-direction: row; }
  .tpl-wide-pair .row { grid-template-columns: 1fr; }
}

/* ---------- Loader / sentinel ---------- */
.sentinel {
  height: 1px;
}

.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 0;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .3em;
  text-transform: uppercase;
}
.loader .dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--dim);
  animation: pulse 1.2s ease-in-out infinite;
}
.loader .dot:nth-child(2) { animation-delay: .15s; }
.loader .dot:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.loader.done { display: none; }

/* ---------- Footer ---------- */
footer {
  padding: 90px 24px 60px;
  text-align: center;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .25em;
  text-transform: uppercase;
}
footer img { height: 14px; margin: 0 auto 18px; opacity: .6; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.96);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease;
}
.lightbox.open { opacity: 1; visibility: visible; }
.lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  width: auto;
  height: auto;
  object-fit: contain;
  transform: scale(.97);
  transition: transform .35s ease;
}
.lightbox.open img { transform: scale(1); }
.lightbox .lb-close {
  position: absolute;
  top: 22px; right: 26px;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 13px;
  letter-spacing: .2em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 10px;
}
.lightbox .lb-nav {
  position: absolute;
  top: 0; bottom: 0;
  width: 20%;
  background: none;
  border: none;
  cursor: pointer;
  color: transparent;
}
.lightbox .lb-prev { left: 0; }
.lightbox .lb-next { right: 0; }
.lightbox .lb-idx {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: .25em;
  color: var(--dim);
}

/* progress bar */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  background: linear-gradient(90deg, #fff, #b7b7b3);
  box-shadow: 0 0 10px rgba(255,255,255,.5);
  width: 0%;
  z-index: 200;
  transition: width .12s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .frame, .frame img { transition: none !important; animation: none !important; }
}
