/* ============================================================
   The gallery page: the catalogue's heading over a grid of
   thumbnails, a list of pages under it, and a viewer for the
   originals over the lightbox's mask. The script adds `open`
   to the viewer to show it and `loading` while the original
   of the picture shown has not arrived.
   ============================================================ */
.gal-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: calc(30 * var(--u));
  margin-top: calc(44 * var(--u));
  /* A change of page brings the grid's top to just under the top bar. */
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
/* A tile keeps its shape through its ratio, so the grid does not jump
   while the thumbnails arrive. A tile the viewer returns to is scrolled
   to clear the top bar. */
.gal-tile {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: max(8px, calc(14 * var(--u)));
  overflow: hidden;
  background: rgb(var(--wash));
  isolation: isolate;
  scroll-margin: calc(var(--topbar-h) + 16px) 0 16px;
}
.gal-tile img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .3s linear;
}
.gal-tile:hover img { transform: scale(1.06); }

/* The list of pages: the arrows at the ends, the current page filled. */
.gal-pager {
  display: flex; align-items: center; justify-content: center;
  gap: max(4px, calc(10 * var(--u)));
  margin-top: calc(56 * var(--u));
  font-variant-numeric: tabular-nums;
}
.gal-num, .gal-arrow {
  flex: 0 1 max(38px, calc(48 * var(--u)));
  min-width: 28px;
  height: max(38px, calc(48 * var(--u)));
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  font-size: max(13px, calc(18 * var(--u)));
  font-weight: 700;
  color: var(--ink-2);
  transition: background .15s ease, color .15s ease;
}
.gal-num:hover, .gal-arrow:hover { background: var(--row-hover); color: var(--ink); }
.gal-num[aria-current="page"] { background: var(--grad-btn); color: #FFFFFF; }
.gal-arrow { font-size: max(15px, calc(20 * var(--u))); }
.gal-arrow[aria-disabled="true"] { opacity: 0.32; pointer-events: none; }
/* The script draws the arrows' icons; without it they show a plain mark. */
.gal-arrow.prev:empty::before { content: "\2039"; }
.gal-arrow.next:empty::before { content: "\203A"; }
.gal-gap { flex: none; min-width: 1em; text-align: center; color: var(--ink-3); }

/* The viewer. The picture sits in a box of one shape whatever its own,
   so the box keeps its size when the original takes the thumbnail's
   place, and a wider picture is shown whole inside it. */
.gal-viewer { --gv-side: 72px; }
/* A closing viewer lets clicks through, as the other overlays do. */
.gal-viewer:not(.open) { pointer-events: none; }
.gal-viewer > .lb-close:focus-visible, .gal-viewer > .lb-arrow:focus-visible { outline-color: #FFFFFF; }
.gv-figure { display: grid; justify-items: center; gap: 12px; }
.gv-figure img {
  grid-area: 1 / 1;
  width: min(100vw - 2 * var(--gv-side), (100vh - 150px) * 16 / 9);
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #0A0B0F;
}
.gv-figure figcaption { grid-area: 2 / 1; }
/* The mark of an original on its way, in the corner of the picture's box. */
.gv-spin {
  grid-area: 1 / 1;
  align-self: end; justify-self: end;
  display: none;
  width: 22px; height: 22px;
  margin: 0 14px 14px 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #FFFFFF;
  animation: gv-turn .8s linear infinite;
}
.gal-viewer.loading .gv-spin { display: block; }
@keyframes gv-turn { to { transform: rotate(360deg); } }

/* The page under the viewer stays still. The space kept for the
   scrollbar shows the page's own background, which the mask does not
   cover, so it takes the mask's colour over the page and fades with it. */
html.viewer-open { overflow: hidden; scrollbar-gutter: stable; }
html { transition: background-color .2s ease; }
html:has(.gal-viewer.open) { background-color: color-mix(in srgb, rgb(4 5 8) 86%, var(--bg)); }

@media (max-width: 1100px) {
  .gal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* From here down the column is a phone's, so the tiles go two to a row. */
@media (max-width: 900px) {
  .gal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: calc(18 * var(--m)); margin-top: calc(30 * var(--m)); }
  .gal-tile { border-radius: max(8px, calc(14 * var(--m))); }
  .gal-pager { gap: 4px; margin-top: calc(44 * var(--m)); }
  .gal-num, .gal-arrow { flex-basis: 38px; height: 38px; font-size: 14px; }
  .gal-arrow { font-size: 16px; }
}
@media (max-width: 760px) {
  .gal-viewer { --gv-side: 12px; }
}

/* With reduced motion the viewer only fades: the picture appears in
   place, the tiles do not zoom and the mark stands still. */
@media (prefers-reduced-motion: reduce) {
  .gal-viewer .lb-figure img, .gal-viewer.open .lb-figure img { transform: none; transition: none; }
  .gal-tile img { transition: none; }
  .gv-spin { animation: none; }
}
