/* ── Photo gallery ─────────────────────────────────────────────
   For event gallery pages (first: falloween-2026.html, 27 Oct 2026). Only
   those pages load this file.

   Two views of one list of photos:
     .pg__gallery   the grid, generated by scripts/build-gallery.py. Without
                    JavaScript it is the whole gallery.
     .pg__carousel  one large photo with arrows, a caption bar and a
                    thumbnail strip, built by js/photo-gallery.js from the grid.
   The script adds .pg--enhanced and switches between them with [hidden].

   Anything the page scrolls to clears the fixed header AND the sticky
   breadcrumb bar below it, hence --pg-scroll-gap. */

.pg { --pg-scroll-gap: calc(var(--header-total) + 64px); }

.pg-section { padding-block: var(--space-6) var(--space-16); }

/* ── Heading row: back link, title and date left, view switch right ──
   Deliberately one short row, so the carousel starts high on the screen. */
.pg__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  margin-bottom: var(--space-4);
}

/* flex: 1 + min-width: 0 lets the title give up width, so on a phone the
   (icon-only) view switch stays on the title's row instead of wrapping. */
.pg__title {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-4);
}

.pg-back {
  flex-basis: 100%;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-indigo);
  text-decoration: none;
}
.pg-back:hover { color: var(--color-gold-dark); }

.pg__title h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.4rem);
  line-height: 1.2;
}

.pg__date {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-gold-dark);
}

.pg__views[hidden] { display: none; }

.pg__views {
  display: inline-flex;
  padding: 3px;
  border: 2px solid var(--color-indigo);
  border-radius: var(--radius-full);
}

.pg__view {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-indigo);
  font: 600 var(--text-sm) var(--font-body);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.pg__view svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 2;
}
.pg__view[aria-pressed="true"] { background: var(--color-indigo); color: var(--color-white); }
.pg__view:not([aria-pressed="true"]):hover { background: var(--color-cream-dark); }

/* ── Carousel ──────────────────────────────────────────────── */
.pg__carousel { scroll-margin-top: var(--pg-scroll-gap); }
/* Focused by the script when a grid photo opens it, so the next Tab lands
   inside the carousel; it is not a control, so no ring. */
.pg__carousel:focus { outline: none; }
.pg__carousel[hidden] { display: none; }

/* The stage keeps one shape whatever the photo, so the page does not jump as
   portrait and landscape shots alternate; the photo is letterboxed inside it.
   max-height clamps it on short screens, and the box simply gets wider than
   4:3 when that happens -- object-fit: contain keeps the photo whole.
   The clamp leaves room for the breadcrumb and heading row above and the
   caption bar below, so on first arrival a laptop screen shows the photo AND
   its caption, with the top of the thumbnail strip peeking in underneath. */
.pg__stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: max(320px, calc(100vh - var(--header-total) - 290px));
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--color-indigo-dark);
  touch-action: pan-y pinch-zoom;
}

.pg__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity var(--transition-base);
}
.pg__stage.is-loading .pg__img { opacity: 0.45; }

.pg__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(20, 29, 53, 0.6);
  color: var(--color-white);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}
.pg__arrow svg {
  width: 28px; height: 28px;
  fill: none; stroke: currentColor; stroke-width: 2.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.pg__arrow:hover { background: rgba(20, 29, 53, 0.88); border-color: var(--color-white); }
.pg__arrow--prev { left: var(--space-4); }
.pg__arrow--next { right: var(--space-4); }

.pg__arrow:focus-visible,
.pg__btn:focus-visible,
.pg__view:focus-visible,
.pg__thumb:focus-visible,
.pg__item:focus-visible,
.pg-back:focus-visible {
  outline: 3px solid var(--color-gold-light);
  outline-offset: 3px;
}

/* Caption on the left, count and buttons on the right. */
.pg__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  padding: var(--space-4) var(--space-1);
}

.pg__caption { margin: 0; flex: 1 1 320px; }
.pg__caption-chapter {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-gold-dark);
}
.pg__caption-text {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  line-height: 1.4;
  color: var(--color-text);
}

.pg__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pg__count {
  margin-right: var(--space-2);
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pg__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.45rem 1rem;
  border: 2px solid var(--color-indigo);
  border-radius: var(--radius-full);
  background: var(--color-white);
  color: var(--color-indigo);
  font: 600 var(--text-sm) var(--font-body);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.pg__btn[hidden] { display: none; }
.pg__btn:hover { background: var(--color-indigo); color: var(--color-white); }
.pg__btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.pg__icon-play, .pg__icon-pause { fill: currentColor; }
.pg__fs svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.pg__icon-pause { display: none; }
.pg__play.is-playing .pg__icon-play { display: none; }
.pg__play.is-playing .pg__icon-pause { display: block; }

/* Thumbnail strip: scrolls sideways; the script keeps the current one in view. */
.pg__strip {
  position: relative;   /* so a thumbnail's offsetLeft is measured from here */
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1) var(--space-1) var(--space-3);
  scrollbar-width: thin;
}

.pg__thumb {
  flex: 0 0 auto;
  width: 96px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-cream-dark);
  opacity: 0.7;
  cursor: pointer;
  transition: opacity var(--transition-fast), border-color var(--transition-fast);
}
.pg__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pg__thumb:hover { opacity: 1; }
.pg__thumb[aria-current="true"] { opacity: 1; border-color: var(--color-gold); }

/* ── Full screen ───────────────────────────────────────────────
   A class rather than :fullscreen, because Safari only knows
   :-webkit-full-screen and one unknown pseudo-class would void the whole rule. */
.pg__carousel.is-fullscreen {
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-4) 0;
  background: #0b0f1c;
}
/* Only the photo gives way to fit the screen; the caption bar and the strip
   keep their size or the strip gets cut off at the bottom edge. */
.pg__carousel.is-fullscreen .pg__bar,
.pg__carousel.is-fullscreen .pg__strip { flex-shrink: 0; }
.pg__carousel.is-fullscreen .pg__stage {
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
  max-height: none;
  border-radius: 0;
  background: transparent;
}
.pg__carousel.is-fullscreen .pg__caption-chapter { color: var(--color-gold-light); }
.pg__carousel.is-fullscreen .pg__caption-text,
.pg__carousel.is-fullscreen .pg__count { color: var(--color-white); }
.pg__carousel.is-fullscreen .pg__btn {
  border-color: rgba(255, 255, 255, 0.7);
  background: transparent;
  color: var(--color-white);
}
.pg__carousel.is-fullscreen .pg__btn:hover { background: rgba(255, 255, 255, 0.15); }

/* ── Grid ──────────────────────────────────────────────────── */
.pg__gallery[hidden] { display: none; }

.pg__group + .pg__group { margin-top: var(--space-10); }

.pg__chapter {
  margin: var(--space-6) 0 var(--space-4);
  font-size: 1.6rem;
  scroll-margin-top: var(--pg-scroll-gap);
}

.pg__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pg__item {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--color-cream-dark);
}
.pg__item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}
.pg__item:hover img { transform: scale(1.04); }

/* ── Thank-you line, centred between the heading row and the photos ── */
.pg-thanks {
  margin: 0 auto var(--space-4);
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  line-height: 1.5;
  text-align: center;
  color: var(--color-text-muted);
}

/* ── Bottom of the page ────────────────────────────────────── */
.pg-footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin: var(--space-12) 0 0;
}

/* ── Phones ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Square, so portrait and landscape shots both get a fair share of a
     narrow screen. */
  .pg__stage { aspect-ratio: 1; max-height: 70vh; border-radius: var(--radius-md); }
  .pg__arrow { width: 44px; height: 44px; }
  .pg__arrow svg { width: 24px; height: 24px; }
  .pg__arrow--prev { left: var(--space-2); }
  .pg__arrow--next { right: var(--space-2); }
  .pg__caption { flex-basis: 100%; }
  .pg__caption-text { font-size: 1.1rem; }
  .pg__thumb { width: 72px; height: 54px; }
  .pg__grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-2); }
  .pg__chapter { font-size: 1.35rem; }

  /* Icons only, so the switch fits beside the title. The words stay for
     screen readers (same technique as .sr-only). */
  .pg__view { padding: var(--space-2) var(--space-3); }
  .pg__view-label {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pg__img, .pg__item img { transition: none; }
  .pg__item:hover img { transform: none; }
}
