/* CW Gallery — editorial photo galleries with PhotoSwipe lightbox. */

.cw-gallery {
  --cw-gap: clamp(6px, 0.8vw, 14px);
  display: grid;
  gap: var(--cw-gap);
  margin: clamp(32px, 4vw, 56px) 0;
}

/* ─── GRID MODE ─── */
.cw-gallery--grid.cw-gallery--cols-2 { grid-template-columns: repeat(2, 1fr); }
.cw-gallery--grid.cw-gallery--cols-3 { grid-template-columns: repeat(3, 1fr); }
.cw-gallery--grid.cw-gallery--cols-4 { grid-template-columns: repeat(4, 1fr); }
.cw-gallery--grid.cw-gallery--cols-5 { grid-template-columns: repeat(5, 1fr); }

.cw-gallery--grid .cw-gallery__item {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--hair);
}
.cw-gallery--grid .cw-gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s cubic-bezier(0.2, 0.6, 0.2, 1);
}
.cw-gallery--grid .cw-gallery__item:hover img { transform: scale(1.04); }

/* ─── STRIP MODE (horizontal scroll, matches homepage gallery-section) ─── */
.cw-gallery--strip {
  display: flex;
  grid-template-columns: none;
  gap: var(--cw-gap);
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}
.cw-gallery--strip::-webkit-scrollbar { height: 6px; }
.cw-gallery--strip::-webkit-scrollbar-thumb { background: var(--hair-strong); border-radius: 3px; }
.cw-gallery--strip .cw-gallery__item {
  position: relative;
  flex: 0 0 auto;
  scroll-snap-align: start;
  overflow: hidden;
}
.cw-gallery--strip .cw-gallery__item img {
  height: clamp(280px, 34vw, 520px);
  width: auto;
  display: block;
}

/* ─── MASONRY MODE (CSS columns, graceful degradation) ─── */
.cw-gallery--masonry {
  display: block;
  column-gap: var(--cw-gap);
  column-fill: balance;
}
.cw-gallery--masonry.cw-gallery--cols-2 { column-count: 2; }
.cw-gallery--masonry.cw-gallery--cols-3 { column-count: 3; }
.cw-gallery--masonry.cw-gallery--cols-4 { column-count: 4; }
.cw-gallery--masonry .cw-gallery__item {
  position: relative;
  display: block;
  margin: 0 0 var(--cw-gap);
  break-inside: avoid;
  overflow: hidden;
  background: var(--hair);
  /* CSS multi-column layout doesn't always establish a containing block
   * for absolutely-positioned descendants — so the hover EXIF overlay
   * was failing to render (or rendering in the wrong spot) in masonry.
   * `isolation: isolate` forces a stacking context that fixes both. */
  isolation: isolate;
}
.cw-gallery--masonry .cw-gallery__item img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.7s cubic-bezier(0.2, 0.6, 0.2, 1);
}
.cw-gallery--masonry .cw-gallery__item:hover img { transform: scale(1.03); }

/* ─── SHOWCASE MODE (main + thumbs + caption) ─── */
.cw-gallery--showcase {
  display: block;
  /* Matches the post prose width (--narrow) so the stage image never
   * exceeds the surrounding column. */
  --cw-stage-max: 840px;
}
.cw-showcase__viewer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: clamp(16px, 1.6vw, 24px);
}
.cw-showcase__stage {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--hair);
  cursor: zoom-in;
  overflow: hidden;
  appearance: none;
}
.cw-showcase__stage:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.cw-showcase__image {
  display: block;
  width: 100%;
  max-height: var(--cw-stage-max);
  object-fit: contain;
  background: var(--hair);
  transition: opacity 0.18s ease;
}
.cw-showcase__image.is-loading { opacity: 0.4; }
.cw-showcase__fs-icon {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(15, 15, 14, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s;
}
.cw-showcase__stage:hover .cw-showcase__fs-icon,
.cw-showcase__stage:focus-visible .cw-showcase__fs-icon { opacity: 1; }

/* Caption + EXIF as a hover overlay in the bottom-left corner of the stage. */
.cw-showcase__overlay {
  position: absolute;
  left: 14px;
  bottom: 14px;
  right: 14px;
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  background: rgba(15, 15, 14, 0.6);
  backdrop-filter: blur(6px);
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  transform: translateY(4px);
  max-width: max-content;
}
.cw-showcase__stage:hover .cw-showcase__overlay,
.cw-showcase__stage:focus-visible .cw-showcase__overlay {
  opacity: 1;
  transform: translateY(0);
}
.cw-showcase__overlay.is-empty { display: none; }
.cw-showcase__overlay-title {
  font-family: var(--serif);
  font-weight: 360;
  font-size: clamp(13px, 1.2vw, 15px);
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: #fff;
}
.cw-showcase__overlay-title:empty { display: none; }
.cw-showcase__overlay-meta {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.3;
}
.cw-showcase__overlay-meta:empty { display: none; }
.cw-showcase__overlay-shop {
  color: #d9bf86;
  text-decoration: none;
  border-bottom: 1px solid rgba(217, 191, 134, 0.45);
  padding-bottom: 1px;
  pointer-events: auto;
  transition: color 0.2s, border-color 0.2s;
}
.cw-showcase__overlay-shop:hover {
  color: #fff;
  border-bottom-color: #fff;
}

.cw-showcase__thumbs-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cw-showcase__nav {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
  padding: 0;
}
.cw-showcase__nav:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.cw-showcase__nav:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  background: var(--paper);
  color: var(--ink);
  border-color: var(--hair-strong);
}
.cw-showcase__thumbs-wrap.is-overflow-none .cw-showcase__nav { display: none; }
.cw-showcase__thumbs {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(6px, 0.7vw, 10px);
  flex: 1 1 auto;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  padding: 4px 0;
}
.cw-showcase__thumbs::-webkit-scrollbar { height: 4px; }
.cw-showcase__thumbs::-webkit-scrollbar-track { background: transparent; }
.cw-showcase__thumbs::-webkit-scrollbar-thumb { background: var(--hair-strong); border-radius: 2px; }
.cw-showcase__thumbs-wrap.is-overflow-none .cw-showcase__thumbs {
  flex-wrap: wrap;
  justify-content: center;
  overflow-x: visible;
}
.cw-showcase__thumb {
  position: relative;
  /* Grow to fill the available row width. With 3 thumbs in an 840px post
   * each takes ~270px; with 8+ thumbs each shrinks toward min-width and
   * the horizontal scroll kicks in (existing nav-arrow logic). */
  flex: 1 1 0;
  min-width: 120px;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  border: 1px solid transparent;
  background: var(--hair);
  cursor: pointer;
  overflow: hidden;
  appearance: none;
  transition: border-color 0.2s, opacity 0.2s;
  opacity: 0.62;
}
.cw-showcase__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cw-showcase__thumb:hover { opacity: 0.92; }
.cw-showcase__thumb.is-active {
  opacity: 1;
  border-color: var(--ink);
}
.cw-showcase__thumb:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  .cw-showcase__thumb { min-width: 80px; max-width: none; }
  .cw-gallery--showcase { --cw-stage-max: 480px; }
}

/* ─── EXIF OVERLAY (thumbnail) ─── */
.cw-gallery__exif {
  position: absolute;
  left: 10px;
  bottom: 10px;
  right: 10px;  /* allow wrapping when gear strings are long */
  font-family: var(--sans);
  color: #fff;
  background: rgba(15, 15, 14, 0.55);
  padding: 8px 10px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: max-content;
  z-index: 2;  /* defensive: keep above the img regardless of stacking context */
}
.cw-gallery__exif-caption {
  font-family: var(--serif);
  font-weight: 380;
  font-size: 13px;
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: #fff;
}
.cw-gallery__exif-gear {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.96);
  line-height: 1.3;
}
.cw-gallery__exif-exposure {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.3;
}
.cw-gallery--exif-always .cw-gallery__exif { opacity: 1; }
.cw-gallery--exif-hover .cw-gallery__item:hover .cw-gallery__exif,
.cw-gallery--exif-hover .cw-gallery__item:focus-visible .cw-gallery__exif { opacity: 1; }

@media (max-width: 720px) {
  .cw-gallery--grid.cw-gallery--cols-3,
  .cw-gallery--grid.cw-gallery--cols-4,
  .cw-gallery--grid.cw-gallery--cols-5 { grid-template-columns: repeat(2, 1fr); }
  .cw-gallery--masonry.cw-gallery--cols-3,
  .cw-gallery--masonry.cw-gallery--cols-4 { column-count: 2; }
  .cw-gallery__exif { display: none; }
}

/* ─── EDITOR PREVIEW (Gutenberg block — all modes render as a uniform grid) ─── */
.cw-gallery-editor-preview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);  /* default for non-column modes */
  gap: 8px;
  margin: 16px 0;
}
.cw-gallery-editor-preview--cols-2 { grid-template-columns: repeat(2, 1fr); }
.cw-gallery-editor-preview--cols-3 { grid-template-columns: repeat(3, 1fr); }
.cw-gallery-editor-preview--cols-4 { grid-template-columns: repeat(4, 1fr); }
.cw-gallery-editor-preview--cols-5 { grid-template-columns: repeat(5, 1fr); }
.cw-gallery-editor-preview--cols-6 { grid-template-columns: repeat(6, 1fr); }
.cw-gallery-editor-preview .cw-gallery__item {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #e5e3dd;
  pointer-events: none;
}
.cw-gallery-editor-preview .cw-gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
@media (max-width: 960px) {
  .cw-gallery-editor-preview { grid-template-columns: repeat(3, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════
   PHOTOSWIPE — EXIF PANEL (added by cw-gallery.js via uiRegister)
   We intentionally use our own variables here so PhotoSwipe theming
   follows the editorial aesthetic of the rest of the site.
   ══════════════════════════════════════════════════════════════════ */
.pswp {
  --pswp-bg: #0f0f0e;
  --pswp-placeholder-bg: #1a1a18;
  --pswp-icon-color: #f0efea;
  --pswp-icon-color-secondary: #0f0f0e;
  --pswp-icon-stroke-color: transparent;
  --pswp-icon-stroke-width: 0;
  --pswp-root-z-index: 10000;
}

/* Custom bottom meta panel. */
.cw-pswp-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: clamp(16px, 2vw, 24px) clamp(20px, 3vw, 40px);
  color: #f0efea;
  background: linear-gradient(to top, rgba(15, 15, 14, 0.92) 30%, rgba(15, 15, 14, 0));
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 1002;
}
.cw-pswp-meta:empty { display: none; }
.cw-pswp-meta__title {
  font-family: var(--serif);
  font-weight: 360;
  font-size: clamp(17px, 1.6vw, 22px);
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0;
  color: #fff;
}
.cw-pswp-meta__caption {
  font-size: 14px;
  line-height: 1.5;
  color: rgba(240, 239, 234, 0.82);
  max-width: 60ch;
  margin: 0;
}
.cw-pswp-meta__rule {
  display: block;
  width: 28px;
  height: 1px;
  background: rgba(240, 239, 234, 0.35);
  margin: 4px 0 2px;
}
.cw-pswp-meta__gear,
.cw-pswp-meta__exposure,
.cw-pswp-meta__context {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(240, 239, 234, 0.72);
  line-height: 1.5;
}
.cw-pswp-meta__gear { color: rgba(240, 239, 234, 0.9); }
.cw-pswp-meta__shop {
  color: #d9bf86;
  text-decoration: none;
  border-bottom: 1px solid rgba(217, 191, 134, 0.45);
  padding-bottom: 1px;
  pointer-events: auto;  /* re-enable clicks; meta panel itself is pointer-events: none */
  transition: color 0.2s, border-color 0.2s;
}
.cw-pswp-meta__shop:hover {
  color: #f0efea;
  border-bottom-color: #f0efea;
}
.cw-pswp-meta__notes {
  font-size: 13px;
  line-height: 1.55;
  color: rgba(240, 239, 234, 0.7);
  font-style: italic;
  max-width: 60ch;
  margin-top: 4px;
}

/* Compact mode for narrow screens */
@media (max-width: 720px) {
  .cw-pswp-meta { gap: 4px; padding: 16px 20px; }
  .cw-pswp-meta__title { font-size: 16px; }
  .cw-pswp-meta__caption { font-size: 13px; }
}

/* Hide meta when PhotoSwipe UI is hidden (single-tap toggle). */
.pswp--ui-visible .cw-pswp-meta { opacity: 1; }
.pswp:not(.pswp--ui-visible) .cw-pswp-meta { opacity: 0; }

/* Counter & close: minor tweaks so they feel editorial rather than app-like. */
.pswp__top-bar {
  background: linear-gradient(to bottom, rgba(15, 15, 14, 0.6), rgba(15, 15, 14, 0));
  padding: 10px 20px;
}
.pswp__counter {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(240, 239, 234, 0.7);
}
