/*
 * gallery.css - /gallery grid, filter chips and the PhotoSwipe lightbox skin.
 * Uses the theme tokens from base.css (--bg, --fg, --muted, --accent, --card, --border ...).
 */

.gallery.container {
  max-width: 80rem;
  padding-block: var(--space-5) var(--space-7);
}

.gallery-head h1 {
  margin-bottom: var(--space-1);
}

.gallery-sub {
  color: var(--muted);
  margin-bottom: var(--space-4);
}

/* ---------- Filter chips: one horizontally scrolling row each on phones ---------- */
.gallery-filters {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  min-width: 0;
}

.chip-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* bleed to the screen edge but keep the 16px gutter for the first/last chip */
  margin-inline: -1rem;
  padding: 2px 1rem;
  scroll-padding-inline: 1rem;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 1rem, #000 calc(100% - 1rem), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 1rem, #000 calc(100% - 1rem), transparent 100%);
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip-row .chip {
  flex: none;
}

.chip-count {
  font-size: 0.75rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 40rem) {
  .chip-row {
    flex-wrap: wrap;
    overflow: visible;
    margin-inline: 0;
    padding-inline: 0;
    -webkit-mask-image: none;
    mask-image: none;
  }
}

/* ---------- Grid ---------- */
.gallery-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: 3px;
}

@media (min-width: 40rem) {
  .gallery-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
}

@media (min-width: 64rem) {
  .gallery-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
}

.g-tile {
  min-width: 0;
}

.g-tile.is-featured {
  grid-column: span 2;
  grid-row: span 2;
}

.g-link {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background-color: var(--border);
  background-size: cover;
  background-position: center;
  -webkit-tap-highlight-color: transparent;
}

@media (min-width: 40rem) {
  .g-link { border-radius: calc(var(--radius) * 0.6); }
}

.g-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;  /* square crops: keep faces (upper third) in frame */
  opacity: 0;
  transition: opacity 280ms ease, transform 400ms ease;
}

.g-link img.is-loaded {
  opacity: 1;
}

.g-link img.is-broken {
  visibility: hidden;
}

@media (hover: hover) {
  .g-link:hover img.is-loaded { transform: scale(1.03); }
}

.g-link:focus-visible {
  outline-offset: 2px;
}

.g-play {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

.g-play::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 7px solid currentColor;
  border-top: 4.5px solid transparent;
  border-bottom: 4.5px solid transparent;
}

.gallery-status {
  margin: var(--space-5) 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9375rem;
}

.gallery-status:empty {
  display: none;
}

.g-retry {
  margin-left: var(--space-2);
  min-height: 2.25rem;
  padding-block: var(--space-1);
}

.gallery-sentinel {
  height: 1px;
}

/* ---------- Lightbox ---------- */
.g-pswp {
  --pswp-bg: #0d0b09;
  --pswp-icon-color: #fff;
  --pswp-icon-color-secondary: rgb(0 0 0 / 0.45);
  --pswp-icon-stroke-color: transparent;
  --pswp-placeholder-bg: #1d1915;
}

.g-pswp .pswp__top-bar {
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(to bottom, rgb(0 0 0 / 0.5), transparent);
}

.g-pswp a.pswp__button {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pswp-icon-color);
}

.g-pswp .pswp__button--download .pswp__icn,
.g-pswp .pswp__button--share .pswp__icn,
.g-pswp .pswp__button--info-toggle .pswp__icn {
  position: static;
  width: 26px;
  height: 26px;
  color: var(--pswp-icon-color);
  fill: none;
  filter: drop-shadow(0 0 2px rgb(0 0 0 / 0.5));
}

.g-pswp .pswp__counter {
  font-variant-numeric: tabular-nums;
}

/* Video slides */
.g-video {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 56px 0 96px;
}

.g-video video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #000;
}

@media (min-width: 40rem) {
  .g-video { padding-bottom: 120px; }
}

/* Info panel: a bottom sheet. Collapsed shows "Shared by" + caption; expanded adds the rest. */
.g-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  max-height: 60%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-3) 1rem calc(var(--space-3) + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgb(0 0 0 / 0.82) 60%, rgb(0 0 0 / 0));
  color: #f3ece2;
  font-size: 0.9375rem;
  line-height: 1.5;
  transition: opacity 250ms ease;
}

.pswp--ui-visible .g-info { opacity: 1; }
.pswp:not(.pswp--ui-visible) .g-info { opacity: 0; pointer-events: none; }

.g-info__bar {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.g-info__summary {
  flex: 1;
  min-width: 0;
}

.g-info p {
  margin: 0;
}

.g-info__by {
  font-weight: 600;
}

.g-info__caption {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.35;
}

.g-info:not(.is-open) .g-info__caption {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.g-info__meta {
  color: #c9bba9;
}

.g-info__toggle {
  flex: none;
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  border: 1px solid rgb(255 255 255 / 0.35);
  border-radius: var(--radius-pill);
  background: rgb(255 255 255 / 0.08);
  color: #fff;
  font-size: 0.875rem;
}

.g-info__body {
  display: none;
  margin-top: var(--space-2);
}

.g-info.is-open .g-info__body {
  display: grid;
  gap: var(--space-2);
}

.g-info__story {
  white-space: pre-line;
}

.g-info__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px var(--space-3);
  margin: 0;
}

.g-info__facts dt {
  color: #c9bba9;
}

.g-info__facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (min-width: 64rem) {
  .g-info {
    left: auto;
    right: var(--space-4);
    bottom: var(--space-4);
    width: 24rem;
    max-height: calc(100% - 7rem);
    border-radius: var(--radius);
    background: rgb(20 17 14 / 0.86);
    backdrop-filter: blur(8px);
    padding: var(--space-4);
  }
}

.g-toast {
  position: absolute;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  z-index: 20;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: rgb(255 255 255 / 0.92);
  color: #1d1915;
  font-size: 0.875rem;
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.g-toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}
