/* ==========================================================================
   Image wall: three layouts plus captions
   Put one of these classes on <image-wall>:
     layout-columns  masonry columns, no cropping, reads down each column
     layout-rows     justified rows, no cropping, reads left to right
     layout-grid     featured grid, wide/tall/large cells, crops to fill
   Needs from PHP on each <image-cell>:  style="--ratio: 1.5"  and  size="normal|wide|tall|large"
   ========================================================================== */

/* ---- Settings: change these ------------------------------------------- */
image-wall {
  --wall-gap: 12px;            /* space between photos, all layouts */
  --wall-radius: 12px;         /* corner rounding */
  --row-height: 240px;         /* rows layout: target row height */
  --grid-cell: 220px;          /* grid layout: size of one square */
  --cell-bg: #1A1B1F;          /* shows while an image loads */
  --caption-text: #ECECEE;
  --caption-muted: #D4D4D8;
  --focus: #F2B544;
}
image-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}

/* ---- Shared ------------------------------------------------------------ */
image-wall {
  display: block;
}

image-cell {
  display: block;
  position: relative;
  overflow: hidden;
  margin: 0;
  border-radius: var(--wall-radius);
  background: var(--cell-bg);
}

image-cell img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform .5s ease;
}
/*
image-cell:hover img {
  transform: scale(1.03);
}
*/
image-cell::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .2s ease;
  pointer-events: none;      /* clicks still reach the photo */
}
image-cell:hover::after,
image-cell:focus-visible::after {
  box-shadow: inset 0 0 0 2px var(--focus);
}




image-cell:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- Layout: columns (masonry) ----------------------------------------- */
image-wall.layout-columns {
  column-count: 4;
  column-gap: var(--wall-gap);
}

.layout-columns image-cell {
  margin-bottom: var(--wall-gap);
  break-inside: avoid;
}

@media (max-width: 1100px) { image-wall.layout-columns { column-count: 3; } }
@media (max-width: 760px)  { image-wall.layout-columns { column-count: 2; } }
@media (max-width: 440px)  { image-wall.layout-columns { column-count: 1; } }

/* ---- Layout: justified rows -------------------------------------------- */
image-wall.layout-rows {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wall-gap);
}

image-wall.layout-rows::after {          /* stops the last row stretching */
  content: "";
  flex-grow: 999999;
}

.layout-rows image-cell {
  flex-grow: var(--ratio, 1.5);
  flex-basis: calc(var(--ratio, 1.5) * var(--row-height));
}

@media (max-width: 600px) {
  image-wall.layout-rows { --row-height: 160px; }
}

/* ---- Layout: featured grid --------------------------------------------- */
image-wall.layout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-cell), 1fr));
  grid-auto-rows: var(--grid-cell);
  grid-auto-flow: dense;                 /* fills gaps; changes order slightly */
  gap: var(--wall-gap);
  container: wall / inline-size;         /* lets cells react to the wall's width */
}

.layout-grid image-cell img {
  height: 100%;
  object-fit: cover;                     /* fills the cell, crops edges */
}

/*  size          columns × rows   shape
    normal        1 × 1            square
    wide          2 × 1            panorama
    tall          1 × 2            portrait
    large         2 × 2            big square
    large-wide    3 × 2            big landscape (≈ 3:2)
    large-tall    2 × 3            big portrait  (≈ 2:3)              */
.layout-grid image-cell[size="wide"]       { grid-column: span 2; }
.layout-grid image-cell[size="tall"]       { grid-row: span 2; }
.layout-grid image-cell[size="large"]      { grid-column: span 2; grid-row: span 2; }
.layout-grid image-cell[size="large-wide"] { grid-column: span 3; grid-row: span 2; }
.layout-grid image-cell[size="large-tall"] { grid-column: span 2; grid-row: span 3; }

/* Fewer columns on narrower walls: shrink spans so nothing overflows.
   These widths assume --grid-cell: 220px and --wall-gap: 12px.
   If you change those, recalculate: N columns fit at N × cell + (N − 1) × gap. */
@container wall (max-width: 683px) {     /* 2 columns */
  .layout-grid image-cell[size="large-wide"] { grid-column: span 2; }
}
@container wall (max-width: 451px) {     /* 1 column */
  .layout-grid image-cell[size] { grid-column: auto; grid-row: auto; }
  .layout-grid image-cell[size="large"],
  .layout-grid image-cell[size="large-wide"] { grid-row: span 2; }  /* still a bit bigger */
  .layout-grid image-cell[size="tall"],
  .layout-grid image-cell[size="large-tall"] { grid-row: span 2; }
}

/* ---- Captions ---------------------------------------------------------- */
image-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 40px 14px 12px;
  background: linear-gradient(to top, rgba(8, 8, 10, .85), rgba(8, 8, 10, 0));
  color: var(--caption-text);
  font-family: Inter, system-ui, sans-serif;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;                  /* clicks go through to the photo */
}

image-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

image-user {
  display: block;
  font-size: 13px;
  color: var(--caption-muted);
}

image-cell:hover image-caption,
image-cell:focus-within image-caption,
image-cell:focus-visible image-caption {
  opacity: 1;
}

@media (hover: none) {                   /* touch screens: always show */
  image-caption { opacity: 1; }
}

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  image-cell img,
  image-caption { transition: none; }
  /* image-cell:hover img { transform: none; } */
}


/* view dialog */

/* ==========================================================================
   Image viewer (slideshow) for <dialog id="image-viewer">
   Open it with document.getElementById('image-viewer').showModal()
   ========================================================================== */

/* ---- Settings: change these ------------------------------------------- */
#image-viewer {
  --v-bg: #0B0B0D;
  --v-panel: #15161A;
  --v-surface: #1E2025;
  --v-border: #22242A;
  --v-border-strong: #33353B;
  --v-text: #ECECEE;
  --v-text-2: #D4D4D8;
  --v-muted: #A1A1AA;
  --v-accent: #F2B544;
  --v-on-accent: #17130A;
  --v-details-width: 360px;
  --v-font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---- The dialog: full screen ------------------------------------------- */
#image-viewer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;                 /* accounts for phone browser toolbars */
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--v-bg);
  color: var(--v-text);
  font-family: var(--v-font);
  overflow: hidden;
}

#image-viewer header {
	display: none;
}

#image-viewer[open] {             /* only lay out when open; closed stays hidden */
  display: flex;
  flex-direction: column;
}

#image-viewer::backdrop {
  background: rgba(0, 0, 0, .8);
}

body:has(#image-viewer[open]) {   /* stop the page scrolling behind it */
  overflow: hidden;
}

#image-viewer :focus-visible {
  outline: 2px solid var(--v-accent);
  outline-offset: 2px;
}

:where(#image-viewer) button {    /* :where() keeps this easy to override below */
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---- Top bar ----------------------------------------------------------- */
viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 16px 0 24px;
  border-bottom: 1px solid var(--v-border);
  flex-shrink: 0;
}

viewer-heading {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}

viewer-position {
  flex-shrink: 0;
  font-size: 14px;
  color: var(--v-muted);
  font-variant-numeric: tabular-nums;
}

viewer-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

viewer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.viewer-details-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--v-border-strong);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
}

.viewer-details-btn:hover { background: rgba(255, 255, 255, .08); }

.viewer-details-btn[aria-pressed="true"] {
  background: var(--v-text);
  border-color: var(--v-text);
  color: var(--v-bg);
}

.viewer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: transparent;
  font-size: 20px;
}

.viewer-close:hover { background: rgba(255, 255, 255, .12); }

/* ---- Body: stage + details side by side -------------------------------- */
viewer-body {
  flex: 1;
  display: flex;
  min-height: 0;                  /* lets the image shrink to fit */
  position: relative;
}

viewer-stage {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 88px;
  touch-action: pan-y;            /* leaves horizontal swipes to the script */
}
viewer-image {
  flex: 1;                 /* fill the stage's width */
  align-self: stretch;     /* fill the stage's height */
  display: flex;           /* centre the image inside */
  align-items: center;
  justify-content: center;
  min-width: 0;            /* let it shrink below the image's natural size */
  min-height: 0;
}
viewer-image img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;            /* whole photo visible, any shape */
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  transition: opacity .2s ease;
}

viewer-image img.is-loading { opacity: .35; }   /* the script adds this while loading */

.viewer-prev,
.viewer-next {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  font-size: 28px;
  line-height: 1;
}
.viewer-prev:hover,
.viewer-next:hover { background: rgba(255, 255, 255, .16); }

.viewer-prev { left: 16px; }
.viewer-next { right: 16px; }
.viewer-prev[hidden],
.viewer-next[hidden] { display: none; }

/* ---- Details panel ----------------------------------------------------- */
viewer-details {
  width: var(--v-details-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
  background: var(--v-panel);
  border-left: 1px solid var(--v-border);
  box-sizing: border-box;
}

viewer-details[hidden] { display: none; }

details-user {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

details-user strong { font-size: 15px; }
details-user span { font-size: 13px; color: var(--v-muted); }

.details-description {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--v-text-2);
}

viewer-details section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
viewer-details section[hidden] {
	display: none;
}

viewer-details h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--v-muted);
}

viewer-details dl {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  font-size: 14px;
}

viewer-details dt { color: var(--v-muted); }

viewer-details dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

viewer-details ul {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

viewer-details ul a {
  color: var(--v-accent);
  font-weight: 500;
  text-decoration: none;
}

viewer-details ul a:hover { text-decoration: underline; }

details-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;               /* sits at the bottom of the panel */
}

.details-download,
.details-report {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 14px;
  text-decoration: none;
}

.details-download {
  flex: 1;
  background: var(--v-accent);
  color: var(--v-on-accent);
  font-weight: 600;
}

.details-download:hover { filter: brightness(1.08); }

.details-report {
  border: 1px solid var(--v-border-strong);
  background: transparent;
  font-weight: 500;
}

.details-report:hover { background: rgba(255, 255, 255, .08); }

/* ---- Thumbnail strip --------------------------------------------------- */
viewer-strip {
  display: flex;
  gap: 8px;
  height: 100px;
  padding: 12px 24px;
  overflow-x: auto;
  border-top: 1px solid var(--v-border);
  flex-shrink: 0;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--v-border-strong) transparent;
}

.strip-thumb {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: var(--v-surface);
  opacity: .55;
}

.strip-thumb:hover { opacity: .85; }

.strip-thumb[current] {
  border-color: var(--v-accent);
  opacity: 1;
}

.strip-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- Phones ------------------------------------------------------------ */
@media (max-width: 760px) {
  viewer-bar { padding: 0 8px 0 16px; }
  viewer-stage { padding: 16px 56px; }
  .viewer-prev { left: 4px; }
  .viewer-next { right: 4px; }

  viewer-details {                /* becomes a sheet over the bottom of the photo */
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 62%;
    border-left: none;
    border-top: 1px solid var(--v-border-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
  }
}

@media (max-width: 480px) {
  viewer-title { display: none; } /* keep room for the buttons */
  viewer-strip { height: 72px; padding: 8px 12px; }
  .strip-thumb { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  viewer-image img { transition: none; }
}