/* ==========================================================================
   PhotoGallery — drop-in styles
   All colour and spacing is driven by custom properties. Override any of
   them on .pg (or a parent) to match your site. Body type is inherited.
   ========================================================================== */

.pg {
  /* --- tokens: override these ------------------------------------------ */
  --pg-ink: #16161a;              /* primary text */
  --pg-muted: #6f6f7a;            /* secondary text, inactive controls */
  --pg-hairline: rgba(22, 22, 26, 0.14);
  --pg-accent: var(--pg-ink);     /* active filter chip fill */
  --pg-accent-ink: #ffffff;       /* text on the accent fill */
  --pg-surface: rgba(22, 22, 26, 0.04); /* chip / select background */
  --pg-focus: #2b6cb0;            /* keyboard focus ring */

  --pg-gap: 8px;                  /* space between tiles */
  --pg-radius: 2px;
  --pg-row-height: 240px;         /* target row height, overridden by JS */

  /* numbers are data, so they get a data face */
  --pg-numerals: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color: var(--pg-ink);
  position: relative;
  width:100%;
}

/* --- filter bar --------------------------------------------------------- */

.pg-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--pg-hairline);
}

.pg-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pg-group-label {
  font-family: var(--pg-numerals);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pg-muted);
  margin-right: 2px;
}

.pg-chip {
  font: inherit;
  font-size: 0.875rem;
  line-height: 1;
  color: var(--pg-ink);
  background: var(--pg-surface);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.pg-chip:hover { border-color: var(--pg-hairline); }

.pg-chip[aria-pressed="true"] {
  background: var(--pg-accent);
  color: var(--pg-accent-ink);
}

.pg-select {
  font: inherit;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--pg-ink);
  background: var(--pg-surface);
  border: 1px solid transparent;
  border-radius: var(--pg-radius);
  padding: 6px 8px;
  cursor: pointer;
}

.pg-range-sep {
  font-family: var(--pg-numerals);
  font-size: 0.75rem;
  color: var(--pg-muted);
}

.pg-count {
  font-family: var(--pg-numerals);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--pg-muted);
  margin-left: auto;
  white-space: nowrap;
}

.pg-clear {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--pg-muted);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--pg-hairline);
  padding: 0 0 1px;
  cursor: pointer;
}

.pg-clear:hover { color: var(--pg-ink); }
.pg-clear[hidden] { display: none; }

/* --- the grid ----------------------------------------------------------- */

.pg-grid {
  position: relative;
  width: 100%;
}

.pg-tile {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  overflow: hidden;
  border-radius: var(--pg-radius);
  background-color: var(--pg-tile-color, var(--pg-surface));
  cursor: zoom-in;
  /* transform is set per tile by JS; contain keeps paint work local */
  contain: strict;
}

.pg-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 260ms ease;
}

.pg-tile img.is-loaded { opacity: 1; }

.pg-empty {
  font-size: 0.9375rem;
  color: var(--pg-muted);
  padding: 48px 0;
  text-align: center;
}

.pg-empty[hidden] { display: none; }

/* --- lightbox ----------------------------------------------------------- */

.pg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pg-scrim, rgba(8, 8, 10, 0.78));
  -webkit-backdrop-filter: blur(var(--pg-scrim-blur, 3px));
  backdrop-filter: blur(var(--pg-scrim-blur, 3px));
  opacity: 0;
  transition: opacity 180ms ease;

  /* The lightbox is attached to <body>, OUTSIDE .pg, so it cannot inherit the
     tokens defined there. Everything it needs is declared here instead.
     Override these on .pg-lightbox, not on .pg. */
  --pg-scrim: rgba(8, 8, 10, 0.78);
  --pg-numerals: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Chrome sits over photographs of unknown brightness, so it carries its own
     contrast rather than relying on the scrim behind it. */
  --pg-lb-ink: rgba(255, 255, 255, 0.95);
  --pg-lb-ink-dim: rgba(255, 255, 255, 0.68);
  --pg-lb-btn-bg: rgba(18, 18, 22, 0.68);
  --pg-lb-btn-bg-hover: rgba(18, 18, 22, 0.88);
  --pg-lb-btn-edge: rgba(255, 255, 255, 0.3);
}

.pg-lightbox[hidden] { display: none; }
.pg-lightbox.is-open { opacity: 1; }

/* --- the photo ---------------------------------------------------------- */

.pg-lightbox-figure {
  margin: 0;
  display: flex;
}

.pg-lightbox-figure img {
  max-width: min(94vw, 1920px);
  /* Leaves room for the top bar and the caption bar. */
  max-height: calc(100vh - 190px);
  max-height: calc(100dvh - 190px);
  width: auto;
  height: auto;
  object-fit: contain;
  background-color: var(--pg-lb-color, #1a1a1a);
}

/* --- top bar: counter and close ---------------------------------------- */

.pg-lb-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  pointer-events: none;   /* clicking the empty bar still closes the viewer */
}

.pg-lb-top > * { pointer-events: auto; }

.pg-lb-counter {
  margin: 0;
  font-family: var(--pg-numerals, ui-monospace, Menlo, monospace);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  color: var(--pg-lb-ink-dim);
}

/* --- buttons ------------------------------------------------------------ */

.pg-lb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--pg-lb-btn-bg);
  border: 1px solid var(--pg-lb-btn-edge);
  color: var(--pg-lb-ink);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: background-color 120ms ease, border-color 120ms ease;
}

.pg-lb-btn:hover {
  background: var(--pg-lb-btn-bg-hover);
  border-color: rgba(255, 255, 255, 0.55);
}

.pg-lb-btn svg {
  display: block;
  width: 20px;
  height: 20px;
}

.pg-lb-prev,
.pg-lb-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.pg-lb-prev { left: 16px; }
.pg-lb-next { right: 16px; }

/* --- caption ------------------------------------------------------------ */

.pg-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 48px 20px 22px;
  text-align: center;
  pointer-events: none;
}

.pg-caption:empty { display: none; }

.pg-caption-title {
  max-width: 68ch;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--pg-lb-ink);
}

.pg-caption-meta {
  font-family: var(--pg-numerals, ui-monospace, Menlo, monospace);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--pg-lb-ink-dim);
}

/* --- accessibility floor ------------------------------------------------ */

.pg :focus-visible {
  outline: 2px solid var(--pg-focus, #2b6cb0);
  outline-offset: 2px;
}

/* Declared separately: the lightbox is outside .pg and cannot read its tokens,
   and an unresolved var() would invalidate the whole outline shorthand. */
.pg-lightbox :focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .pg-tile img,
  .pg-lightbox {
    transition: none;
  }
  .pg-tile img { opacity: 1; }
}

@media (max-width: 640px) {
  .pg-controls { gap: 8px 12px; }
  .pg-count { margin-left: 0; width: 100%; }
  .pg-lb-prev { left: 8px; }
  .pg-lb-next { right: 8px; }
  .pg-lb-top { padding: 10px 10px; }
  .pg-caption { padding: 36px 14px 16px; }
  .pg-caption-title { font-size: 0.9375rem; }
  .pg-caption-meta { font-size: 0.75rem; }
}
