/* ==========================================================================
   BABRI STONE — PORTFOLIO GALLERY, LIGHTBOX, TEAM
   ========================================================================== */

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: var(--space-xl);
}
.filter-btn {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--stone);
  border-radius: 999px;
  background: var(--paper);
  color: var(--taupe);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s var(--ease);
}
.filter-btn:hover { border-color: var(--brass); color: var(--ink); }
.filter-btn[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--ivory);
}

/* On narrow screens, a ragged wrapped pill grid looks untidy —
   use a single clean horizontally-scrollable row instead. */
@media (max-width: 700px) {
  .filter-bar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: calc(-1 * var(--space-md, 1rem));
    margin-right: calc(-1 * var(--space-md, 1rem));
    padding-left: var(--space-md, 1rem);
    padding-right: var(--space-md, 1rem);
    padding-bottom: 0.5rem;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-btn { flex: 0 0 auto; }
}

/* ---- Masonry-ish gallery grid ---- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}
.gallery-item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  background: var(--ivory-deep);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.gallery-item.is-hidden { display: none; }
.gallery-item .thumb-wrap { aspect-ratio: 4/3; overflow: hidden; }
.gallery-item.tall .thumb-wrap { aspect-ratio: 3/4; }
.gallery-item img {
  width: 100%; height: 100%; object-fit: cover;
  /* disables the browser's native double-tap-to-zoom on the thumbnail,
     which otherwise zoomed the page instead of opening the lightbox */
  touch-action: manipulation;
}
.gallery-item .overlay {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(28,26,23,0.82) 100%);
  /* Always visible: opacity used to default to 0 and only reveal on
     :hover/:focus-within, which touch devices only ever satisfy for the
     instant a finger is actually pressed on the tile — so the caption
     effectively never showed on mobile. Captions are part of the content,
     not a hover reveal, so they're shown unconditionally now. */
  opacity: 1;
  display: flex;
  align-items: flex-end;
  padding: var(--space-md);
}
.gallery-item:hover, .gallery-item:focus-within { transform: translateY(-4px); box-shadow: var(--shadow-lifted); }
.gallery-item .overlay-text { color: var(--ivory); }
.gallery-item .overlay-text .cat {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass-light);
  display: block;
  margin-bottom: 0.2rem;
}
.gallery-item .overlay-text .title { font-family: var(--font-display); font-size: 1.15rem; font-style: italic; }
.gallery-item button.expand-btn {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  background: none; border: none; padding: 0; cursor: pointer;
}

@media (max-width: 900px) { .gallery-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .gallery-grid { grid-template-columns: 1fr; } }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  /* Solid, not translucent: at 0.94 alpha the page behind was still
     faintly showing through the backdrop, and on iOS Safari that sliver
     of "through" content sometimes gets stuck as a stale composited
     frame (the previous item's caption lingering above the current
     card, reported as jumbled/misaligned text in an unexpected font).
     A fully opaque backdrop removes the page underneath from the paint
     entirely, so there's nothing left to bleed or go stale. */
  background: var(--ink);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}
.lightbox.is-open { display: flex; }
.lightbox-inner {
  max-width: 1100px;
  width: 100%;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-lg);
  align-items: center;
  max-height: 90vh;
}
.lightbox-media { position: relative; max-height: 85vh; overflow: hidden; border-radius: var(--radius-md); background: rgba(255,255,255,0.03); touch-action: manipulation; transform: translateZ(0); backface-visibility: hidden; }
.lightbox-media img { width: 100%; height: 100%; object-fit: contain; max-height: 85vh; opacity: 0; transition: opacity 0.28s var(--ease), filter 0.25s var(--ease); touch-action: manipulation; }
.lightbox-media img.is-loaded { opacity: 1; }
/* First open shows the on-page thumbnail immediately (see openLightbox()
   in gallery.js) rather than an empty frame, softly blurred with a small
   spinner while the full-resolution photo finishes downloading. */
.lightbox-media.is-loading img { filter: blur(6px); }
.lightbox-media.is-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 32px; height: 32px;
  margin: -16px 0 0 -16px;
  border: 2px solid rgba(28,26,23,0.18);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: lightboxSpin 0.75s linear infinite;
  pointer-events: none;
}
@keyframes lightboxSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .lightbox-media img { transition: none; }
  .lightbox-media.is-loading img { filter: none; }
  .lightbox-media.is-loading::after { animation-duration: 1.5s; }
}
.lightbox-info {
  color: var(--ivory);
  background: var(--ink);
  position: relative;
  transform: translateZ(0);
  backface-visibility: hidden;
}
.lightbox-info .cat { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brass-light); }
.lightbox-info h3 { color: var(--ivory); margin: 0.5rem 0 1rem; }
.lightbox-info dl { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; font-size: 0.9rem; }
.lightbox-info dt { color: var(--taupe); }
.lightbox-info dd { margin: 0; color: var(--ivory); }
/* Close/prev/next now live inside .lightbox-media (which is already
   position:relative) instead of the full-screen .lightbox overlay, so
   they're always pinned to the picture itself and can never drift onto
   the caption/spec text below as the modal is scrolled. */
.lightbox-close {
  position: absolute;
  top: var(--space-md); right: var(--space-md);
  z-index: 2;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(247,243,234,0.35);
  background: rgba(28,26,23,0.4);
  color: var(--ivory);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(247,243,234,0.12); }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 2;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid rgba(247,243,234,0.35);
  background: rgba(28,26,23,0.4);
  color: var(--ivory);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.lightbox-prev { left: var(--space-md); }
.lightbox-next { right: var(--space-md); }
@media (max-width: 800px) {
  /* Previously .lightbox-inner had max-height:none with overflow-y:auto,
     which is a no-op (nothing to overflow against), so tall project cards
     had no way to scroll inside the modal — the only way to reach the
     cut-off content was to pinch-zoom the whole page, which is also why
     the page was left zoomed in/panned after closing. The backdrop itself
     now scrolls normally so the modal behaves like any other scrollable
     panel and no zooming is ever needed to see it. */
  .lightbox {
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-md);
  }
  .lightbox-inner { grid-template-columns: 1fr; max-height: none; margin: auto 0; }
  .lightbox-nav, .lightbox-close { width: 40px; height: 40px; }
}

/* ---- Team grid ---- */
.team-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg) var(--space-md);
}
.team-card { text-align: left; }
.team-photo {
  aspect-ratio: 4/5;
  overflow: hidden;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  background: var(--ivory-deep);
}
.team-photo img { width: 100%; height: 100%; object-fit: cover; }
.team-card h3 { font-size: 1.2rem; margin-bottom: 0.15rem; }
.team-card .role {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  display: block;
  margin-bottom: 0.7rem;
}
.team-card p { font-size: 0.92rem; color: var(--taupe); margin-bottom: 0.5rem; }
.team-card .responsibilities { font-size: 0.85rem; color: var(--taupe); }
.team-card .responsibilities strong { color: var(--ink); font-weight: 600; }

@media (max-width: 900px) { .team-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .team-grid { grid-template-columns: 1fr; } }

/* ---- Materials grid ---- */
.material-card {
  border: 1px solid var(--stone-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--paper);
}
.material-card .media { aspect-ratio: 16/10; overflow: hidden; }
.material-card .media img { width: 100%; height: 100%; object-fit: cover; }
.material-card .body { padding: var(--space-lg); }
.material-card .swatch-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  border: 1px solid var(--stone);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  margin-bottom: 0.7rem;
}
/* min-width:0 on the items is required: grid children default to min-width:auto,
   so a long unbreakable value would widen the track past its 1fr share and push
   the whole .split column off-screen on narrow viewports. */
/* material-detail-grid removed — materials.html now uses .material-spec-list (components.css) */


/* Material page anchor tabs
   NOTE: this used to be `position: sticky; top: 90px`, permanently pinned
   below the header for the entire page. On a long page like this, a
   permanently-docked bar sits on top of whichever section happens to be
   scrolling underneath it, visually slicing sentences and headings in half
   as they pass behind it (reported as "jumbled" text/names). It also
   doubled up with the sticky site header as a second stacked sticky
   element, which is a common trigger for iOS Safari failing to restore
   scroll position correctly after a pinch-zoom gesture. Tabs now scroll
   normally with the page instead of staying docked. */
.material-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: var(--space-xl); background: var(--ivory); padding: 0.75rem var(--space-md); }
.material-tabs a {
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.04em;
  padding: 0.5rem 1rem; border: 1px solid var(--stone-soft); border-radius: 999px; color: var(--taupe);
  transition: all 0.25s var(--ease);
}
.material-tabs a:hover { border-color: var(--brass); color: var(--ink); }

.material-full { padding: var(--space-2xl) 0; scroll-margin-top: 150px; }
.material-full:nth-child(even) { background: var(--ivory-deep); }

@media (prefers-reduced-motion: reduce) {
  .gallery-item:hover, .gallery-item:focus-within { transform: none; }
}
