/* ============================================================
   CONTENT GALLERY (canonical gallery → pager + softbox)
   ============================================================ */

/* SSR and the pager share the same first-frame geometry. Keeping only the
   first slide visible before enhancement prevents a multi-row grid collapsing
   above the reader when JavaScript installs the pager. */
.content-gallery {
  display: block;
}
.content-gallery[data-gallery-columns="1"] { --gallery-columns: 1; }
.content-gallery[data-gallery-columns="2"] { --gallery-columns: 2; }
.content-gallery[data-gallery-columns="3"] { --gallery-columns: 3; }
.content-gallery[data-gallery-columns="4"] { --gallery-columns: 4; }
.content-gallery[data-gallery-columns="5"] { --gallery-columns: 5; }
.content-gallery[data-gallery-columns="6"] { --gallery-columns: 6; }
.content-gallery[data-gallery-columns="7"] { --gallery-columns: 7; }
.content-gallery[data-gallery-columns="8"] { --gallery-columns: 8; }
.content-gallery[data-gallery-enhance="pager"]:not(.is-pager) > .content-gallery-item:not(:first-child) { display: none; }
.content-gallery[data-gallery-enhance="pager"]:not(.is-pager)::before { content: ""; display: block; height: 60px; }
.content-gallery:not(.is-pager) .content-gallery-link img { aspect-ratio: 16 / 10; object-fit: cover; }
.gallery-hero .content-gallery:not(.is-pager) .content-gallery-link img { aspect-ratio: 16 / 9; }
.article-body .content-gallery .content-gallery-item { margin: 0; }
.content-gallery img { display: block; width: 100%; height: auto; background: var(--paper-2); }
.content-gallery figcaption {
  padding-top: 8px;
}
.content-gallery[data-gallery-layout="grid"] { display: grid; grid-template-columns: repeat(var(--gallery-columns, 2), minmax(0, 1fr)); gap: 14px; }
.content-gallery[data-gallery-layout="masonry"] { columns: var(--gallery-columns, 2); column-gap: 14px; }
.content-gallery[data-gallery-layout="masonry"] > .content-gallery-item { break-inside: avoid; margin-block-end: 14px; }
.content-gallery > .blocks-gallery-caption { grid-column: 1 / -1; column-span: all; }

/* hydrated: scroll-snap pager with per-slide text cards */
.content-gallery.is-pager { display: block; }
.gallery-stage {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.gallery-stage::-webkit-scrollbar { display: none; }
.is-pager .content-gallery-item {
  position: relative;
  flex: 0 0 calc(100% - 52px);
  min-width: 0;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
}
/* caption text moves onto the image; keep the semantic figcaption for no-JS */
.is-pager .content-gallery-item > figcaption { display: none; }
.is-pager .content-gallery-link { position: relative; display: block; background: var(--paper-2); }
/* uniform aspect frame so the overlay always sits on the photo itself;
   the softbox shows the uncropped file */
.is-pager .content-gallery-link img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

/* on-image text: gradient-masked blur + scrim, then label and boxed title */
.gallery-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 64px 16px 15px;
  display: grid;
  gap: 9px;
  justify-items: start;
  pointer-events: none;
}
.gallery-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 12, 12, 0) 0%, rgba(12, 12, 12, 0.34) 58%, rgba(12, 12, 12, 0.5) 100%);
  -webkit-backdrop-filter: blur(18px) saturate(1.12);
  backdrop-filter: blur(18px) saturate(1.12);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.55) 52%, #000 94%);
  mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.55) 52%, #000 94%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .gallery-overlay::before {
    background: linear-gradient(180deg, rgba(12, 12, 12, 0) 0%, rgba(12, 12, 12, 0.55) 55%, rgba(12, 12, 12, 0.78) 100%);
  }
}
.gallery-overlay > * { position: relative; }
.gallery-overlay-label {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.94);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.5);
}
.gallery-overlay-label .num:first-of-type { color: var(--y); }
.gallery-overlay-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.45;
  letter-spacing: -0.01em;
  max-width: 32ch;
}
.gallery-overlay-title span {
  background: var(--y);
  color: var(--on-accent, var(--ink));
  padding: 0.16em 0.45em 0.2em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* prominent softbox trigger */
.gallery-open {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--y);
  color: var(--on-accent, var(--ink));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.gallery-open:hover { background: var(--ink); color: var(--paper); }
.gallery-open:active { transform: scale(0.94); }
.gallery-open:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }
.gallery-open svg { width: 20px; height: 20px; }

.gallery-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

/* lead gallery: the gallery IS the story — wider than a lead image would be,
   hierarchy carried by scale and spacing, not rules */
.gallery-lead {
  max-width: 1280px;
  margin: 0 auto;
}
.gallery-hero .gallery-bar { margin-bottom: 14px; }
.gallery-hero .gallery-bar-label {
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--ink);
}
.gallery-hero .content-gallery-link img { aspect-ratio: 16 / 9; }
.gallery-hero .gallery-overlay { padding-top: 110px; gap: 10px; }
.gallery-hero .gallery-overlay-title { font-size: 22px; max-width: 38ch; }
.gallery-hero .gallery-overlay-sub { font-size: 16px; }
.gallery-overlay-sub {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.55);
  max-width: 54ch;
}
.gallery-bar-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--mute);
}
.gallery-bar-label .flag { width: 10px; height: 10px; background: var(--y); }
.gallery-nav { display: flex; gap: 6px; }
.gallery-nav button {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--paper);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.gallery-nav button:hover:not(:disabled) { background: var(--y); color: var(--on-accent, var(--ink)); }
.gallery-nav button:active:not(:disabled) { transform: scale(0.94); }
.gallery-nav button:disabled { background: var(--paper-2); color: #b5b5b1; }
.gallery-nav svg { width: 20px; height: 20px; }

/* softbox: full-viewport bright viewer for the original files */
.gallery-softbox {
  border: 0;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
}
.gallery-softbox[open] { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
body:has(.gallery-softbox[open]) { overflow: hidden; }
.softbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: clamp(64px, 10vh, 88px) clamp(72px, 9vw, 110px) 10px;
}
.softbox-stage img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: var(--paper-2);
  box-shadow: 0 34px 90px rgba(17, 17, 17, 0.28);
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
.softbox-stage img.is-loaded { opacity: 1; }
.softbox-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin: 0 clamp(16px, 6vw, 96px);
  padding: 14px 2px 10px;
}
.softbox-caption {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.softbox-count {
  margin-left: auto;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--mute);
}
.softbox-count .num { font-size: 19px; font-weight: 900; color: var(--ink); }
.softbox-close, .softbox-nav {
  position: absolute;
  z-index: 2;
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--paper);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.softbox-close:hover, .softbox-nav:hover { background: var(--y); color: var(--on-accent, var(--ink)); }
.softbox-close:active, .softbox-nav:active { transform: scale(0.94); }
.softbox-close:focus-visible, .softbox-nav:focus-visible { outline: 3px solid var(--y); outline-offset: 3px; }
.softbox-close { top: 14px; right: 14px; }
.softbox-nav { top: 50%; transform: translateY(-50%); }
.softbox-nav:active { transform: translateY(-50%) scale(0.94); }
.softbox-prev { left: 14px; }
.softbox-next { right: 14px; }
.softbox-close svg, .softbox-nav svg { width: 22px; height: 22px; }
@media (max-width: 620px) {
  .is-pager .content-gallery-item { flex-basis: calc(100% - 36px); }
  .gallery-overlay { padding: 48px 12px 11px; gap: 7px; }
  /* the lead gallery reads taller on portrait screens */
  .gallery-hero .content-gallery-link img { aspect-ratio: 4 / 3; }
  .gallery-open { width: 42px; height: 42px; top: 10px; right: 10px; }
  .content-gallery { grid-template-columns: 1fr; columns: 1; }
  .softbox-stage { padding: 68px 12px 10px; }
  .softbox-stage img { box-shadow: 0 12px 36px rgba(17, 17, 17, 0.18); }
  .softbox-close, .softbox-nav { width: 44px; height: 44px; }
  .softbox-prev { left: 8px; }
  .softbox-next { right: 8px; }
  .softbox-bar { flex-wrap: wrap; margin: 0 14px; }
}

/* an odd trailing opinion card closes the 2-col grid evenly */
@media (min-width: 621px) and (max-width: 860px) {
  .opinion-grid > .opinion-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
