/* ============================================================================
   GALLERY  (/gallery)
   ----------------------------------------------------------------------------
   Build-photo grid + lightbox. Reads the site design tokens, so it inherits
   both dark mode (style.css) and the storybook re-skin (storybook.css) for
   free - there are no hard-coded palette colours below except the lightbox
   scrim, which is deliberately near-black in every theme so photos read
   against it.

   Layout: CSS grid with a fine row rhythm (--gal-row) and per-tile row spans
   written by gallery.js from each photo's real aspect ratio. That gives true
   masonry while keeping DOM order row-major, so the lightbox's prev/next
   follows the order the eye actually reads - which a CSS-columns masonry
   can't do (it runs column-major). Without JS the .gal-grid falls back to a
   plain aspect-ratio grid, so the page still works.
   ============================================================================ */

/* ── Hero ─────────────────────────────────────────────────────────────── */
.gal-hero {
  padding: calc(var(--nav-h) + 80px) 24px 48px;
  text-align: center;
  background: linear-gradient(180deg, var(--hero-from) 0%, var(--bg) 100%);
}
.gal-hero-inner { max-width: 820px; margin: 0 auto; }
.gal-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
}
.gal-title {
  font-size: 56px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -1.2px;
  color: var(--text-primary);
  margin: 0 0 18px;
}
.gal-title-accent { color: var(--accent); }
.gal-sub {
  font-size: 19px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0 auto;
  max-width: 620px;
}
.gal-count {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--text-tertiary);
}
body.theme-storybook .gal-title { font-family: 'Baloo 2', sans-serif; }
body.theme-storybook .gal-eyebrow { font-family: 'Fredoka', sans-serif; }

/* ── Filter pills ─────────────────────────────────────────────────────── */
.gal-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 0 24px 28px;
  max-width: 1100px;
  margin: 0 auto;
}
.gal-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.gal-pill:hover { color: var(--text-primary); border-color: var(--border-hover); }
.gal-pill.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.gal-pill-n {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  opacity: .65;
}

/* ── Grid ─────────────────────────────────────────────────────────────── */
.gal-grid {
  --gal-row: 8px;             /* row rhythm the JS spans are measured in */
  --gal-gap: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gal-gap);
  /* Natural rows until the masonry pass has measured. The fine row rhythm
     only switches on WITH the spans that are expressed in it - turning it on
     first would clamp every tile to one 8px row and squash the photos. */
  grid-auto-rows: auto;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 80px;
}
.gal-grid.is-measured { grid-auto-rows: var(--gal-row); }
/* Tiles must have a real height BEFORE the masonry pass measures them,
   otherwise measurement reads 0 and every tile collapses to a 1-row span.
   The photo's own aspect ratio supplies that height - never a percentage of
   the tile, which would make the height depend on the span that depends on
   the height. */
.gal-grid:not(.is-measured) .gal-tile { grid-row: auto; }

.gal-tile {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.gal-tile[hidden] { display: none; }

.gal-tile-btn {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.gal-tile-btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
.gal-tile-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
/* --ratio is height/width, so the CSS ratio is 1 / --ratio. Set explicitly
   (rather than relying on the width/height attributes alone) so the space is
   reserved identically for lazy tiles that haven't fetched yet. */
.gal-tile-btn img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / var(--ratio, 0.75);
  object-fit: cover;
}
/* Featured LANDSCAPE shots take two columns where there's room to give them.
   Portrait photos keep one column - see the is-wide note in gallery.html. */
.gal-tile.is-wide { grid-column: span 2; }

.gal-tile-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: scale(.85);
  transition: opacity .18s ease, transform .18s ease;
}
.gal-tile-btn:hover .gal-tile-zoom,
.gal-tile-btn:focus-visible .gal-tile-zoom { opacity: 1; transform: scale(1); }

.gal-cap { display: flex; flex-direction: column; gap: 2px; padding: 0 2px; }
.gal-cap-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
}
.gal-cap-meta { font-size: 12.5px; color: var(--text-tertiary); }

.gal-empty-filter {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 24px 90px;
  margin: 0;
}

/* ── Lightbox ─────────────────────────────────────────────────────────── */
.gal-lb {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 28px;
  /* Near-black in every theme on purpose - a cream scrim would wash the
     photos out, and this is the one surface that isn't tokenised. */
  background: rgba(12,10,9,.93);
  backdrop-filter: blur(4px);
  animation: gal-fade .16s ease;
}
.gal-lb[hidden] { display: none; }
@keyframes gal-fade { from { opacity: 0 } to { opacity: 1 } }

.gal-lb-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  max-width: min(1500px, 100%);
  max-height: 100%;
}
#gal-lb-img {
  display: block;
  max-width: 100%;
  /* Leave room for the caption block under the photo. */
  max-height: calc(100vh - 220px);
  margin: 0 auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04);
}
.gal-lb-info {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  color: #fff;
}
.gal-lb-text { max-width: 640px; }
.gal-lb-info h2 {
  margin: 0 0 5px;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
}
.gal-lb-info p { margin: 0; font-size: 14.5px; line-height: 1.55; color: rgba(255,255,255,.78); }
.gal-lb-credit { margin-top: 6px !important; font-size: 12.5px !important; color: rgba(255,255,255,.5) !important; }
.gal-lb-credit:empty { display: none; }

.gal-lb-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.gal-lb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 999px;
  transition: filter .16s ease, background .16s ease;
}
.gal-lb-btn:hover { filter: brightness(1.08); }
.gal-lb-btn-ghost {
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.22);
}
.gal-lb-btn-ghost:hover { background: rgba(255,255,255,.16); }
#gal-lb-mp { font-weight: 400; opacity: .6; font-size: 12px; }

.gal-lb-close,
.gal-lb-nav {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  transition: background .16s ease;
}
.gal-lb-close:hover,
.gal-lb-nav:hover { background: rgba(255,255,255,.2); }
.gal-lb-close:focus-visible,
.gal-lb-nav:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.gal-lb-close { top: 20px; right: 20px; width: 42px; height: 42px; }
.gal-lb-nav { top: 50%; transform: translateY(-50%); width: 48px; height: 48px; }
.gal-lb-prev { left: 20px; }
.gal-lb-next { right: 20px; }
.gal-lb-nav[hidden] { display: none; }

body.gal-lb-open { overflow: hidden; }

/* ── Empty state ──────────────────────────────────────────────────────── */
.gal-empty {
  max-width: 620px;
  margin: 0 auto;
  padding: 24px 24px 110px;
  text-align: center;
  color: var(--text-secondary);
}
.gal-empty-icon { width: 76px; height: 57px; color: var(--text-tertiary); margin-bottom: 22px; }
.gal-empty h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px;
}
.gal-empty p { font-size: 15.5px; line-height: 1.65; margin: 0 0 16px; }
.gal-empty code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-primary);
}
.gal-empty-cmd {
  margin: 0 0 20px;
  padding: 14px 16px;
  text-align: left;
  overflow-x: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.gal-empty-cmd code { background: none; padding: 0; }
.gal-empty-note { font-size: 14px; color: var(--text-tertiary); }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .gal-lb-nav { width: 42px; height: 42px; }
  .gal-lb-prev { left: 10px; }
  .gal-lb-next { right: 10px; }
  #gal-lb-img { max-height: calc(100vh - 260px); }
}
@media (max-width: 720px) {
  .gal-hero { padding: calc(var(--nav-h) + 40px) 20px 32px; }
  .gal-title { font-size: 36px; }
  .gal-sub { font-size: 16px; }
  .gal-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    --gal-gap: 12px;
    padding: 0 16px 60px;
  }
  .gal-lb { padding: 16px; }
  .gal-lb-info { flex-direction: column; align-items: flex-start; }
}
/* One column below ~420 px: two 150 px tiles plus gap stop fitting, and a
   half-width build photo isn't worth looking at. */
@media (max-width: 420px) {
  .gal-grid { grid-template-columns: 1fr; }
  .gal-tile.is-wide { grid-column: span 1; }
}

@media (prefers-reduced-motion: reduce) {
  .gal-tile-btn, .gal-tile-zoom, .gal-lb { transition: none; animation: none; }
  .gal-tile-btn:hover { transform: none; }
}
