/* Gallery section — bento grid of studio photographs with a filter row and a
   lightbox. Tokens only (css/design-tokens.css); no raw hex, no second palette.
   Mobile-first: one column, fluid widths only — no fixed pixel layout widths,
   no 100vw, no horizontal scroll at 320px.
   >=36em: two columns. >=64em: three columns with wide feature cells. */

.gallery {
  padding-block: var(--space-section);
  background-color: var(--color-bg-soft);
}

.gallery__container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-padding);
  display: grid;
  gap: var(--space-8);
}

/* ---------- Header ---------- */

.gallery__header {
  display: grid;
  gap: var(--space-4);
  max-width: var(--measure);
}

.gallery__eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: var(--letter-wide);
  text-transform: uppercase;
  color: var(--color-accent-600);
}

.gallery__heading {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--letter-tight);
  line-height: var(--leading-tight);
  color: var(--color-text);
}

.gallery__subheading {
  font-size: var(--text-lg);
  line-height: var(--leading-normal);
  color: var(--color-text-body);
}

/* ---------- Filters ---------- */

.gallery__filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
}

.gallery__filters[hidden] { display: none; }

.gallery__filter {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background-color: var(--color-bg);
  color: var(--color-text-body);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default),
              border-color var(--duration-fast) var(--ease-default);
}

.gallery__filter:hover {
  border-color: var(--color-primary-600);
  color: var(--color-primary-700);
}

.gallery__filter[aria-pressed='true'] {
  background-color: var(--color-primary-600);
  border-color: var(--color-primary-600);
  color: var(--color-text-on-primary);
}

/* ---------- Bento grid ---------- */

.gallery__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--grid-gap);
  list-style: none;
}

.gallery__cell { display: flex; }

.gallery__tile {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: var(--color-bg);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  text-align: left;
  transition: transform var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default);
}

.gallery__tile:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.gallery__figure {
  display: grid;
  gap: 0;
  height: 100%;
}

/* Fixed 4:3 frame so a photograph never shifts the layout while it loads. */
.gallery__image {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center;
  background-color: var(--color-bg-strong);
}

.gallery__caption {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5) var(--space-5);
}

.gallery__title {
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.gallery__note {
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  color: var(--color-text-muted);
}

/* ---------- CTAs ---------- */

.gallery__ctas {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* ---------- Scroll reveal (moderate motion) ---------- */

.gallery__header,
.gallery__filters,
.gallery__ctas,
.gallery__cell {
  opacity: 1;
  transition: opacity var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
}

/* The hidden start state is opt-in: only JS that can reveal it adds
   `is-animated`, so with JS off nothing is stuck invisible. */
.gallery.is-animated .gallery__header,
.gallery.is-animated .gallery__filters,
.gallery.is-animated .gallery__ctas,
.gallery.is-animated .gallery__cell {
  opacity: 0;
  transform: translateY(var(--reveal-distance));
}

.gallery.is-animated.is-ready .gallery__header,
.gallery.is-animated.is-ready .gallery__filters,
.gallery.is-animated.is-ready .gallery__ctas,
.gallery.is-animated.is-ready .gallery__cell {
  opacity: 1;
  transform: none;
}

.gallery.is-animated.is-ready .gallery__cell {
  transition-delay: var(--cell-delay, 0ms);
}

/* ---------- Lightbox ---------- */

.gallery__lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  /* Token-derived scrim: the dark brand green at 88%. */
  background: var(--color-primary-900);
  background: color-mix(in srgb, var(--color-primary-900) 88%, transparent);
}

.gallery__lightbox[hidden] { display: none; }

.gallery__lightbox-panel {
  position: relative;
  width: 100%;
  max-width: 56rem;
  max-height: 90vh;
  overflow: auto;
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  background-color: var(--color-bg);
  box-shadow: var(--shadow-xl);
}

.gallery__lightbox-image {
  display: block;
  width: 100%;
  max-height: 65vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  background-color: var(--color-bg-strong);
}

.gallery__lightbox-meta {
  display: grid;
  gap: var(--space-1);
}

.gallery__lightbox-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.gallery__lightbox-note {
  font-size: var(--text-sm);
  color: var(--color-text-body);
}

.gallery__lightbox-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.gallery__lightbox-counter {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.gallery__lightbox-button {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background-color: var(--color-bg);
  color: var(--color-text-body);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}

.gallery__lightbox-button:hover {
  background-color: var(--color-bg-soft);
  color: var(--color-primary-700);
}

.gallery__lightbox-close {
  justify-self: end;
  background-color: var(--color-primary-600);
  border-color: var(--color-primary-600);
  color: var(--color-text-on-primary);
}

.gallery__lightbox-close:hover {
  background-color: var(--color-primary-700);
  color: var(--color-text-on-primary);
}

/* Tablet: two columns. */
@media (min-width: 36em) {
  .gallery__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery__heading { font-size: var(--text-4xl); }
}

/* Desktop: three columns, feature cells span two for the bento rhythm. */
@media (min-width: 64em) {
  .gallery__container { gap: var(--space-10); }
  .gallery__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gallery__cell--wide { grid-column: span 2; }
  .gallery__cell--wide .gallery__image { aspect-ratio: 16 / 9; }
  .gallery__lightbox-panel { padding: var(--space-6); }
}
