/* Media: landscape photos in the admin's order, in 3:2 frames (a slightly different shape is trimmed from the
   centre). From 700px rows hold two or three: 2, 3, 3, 2, 3, 2 and again, fifteen photos a cycle, set by position so a
   new upload never needs a layout choice. A short last row never leaves one photo alone: it joins the row before,
   a pair and it make three, a three and it make two pairs. Phone: 1, then 2. One gap, the page gutter, both ways.
   The slot classes from shared/data.js are ignored. */
/* No page title on show (the h1 is for screen readers), so the photos start under the header */
.spread-sec { padding-top: calc(var(--header) + var(--s-5)); }
.spread { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gutter); }
.spread > li { grid-column: span 6; }
.shot { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
.shot-img { display: block; aspect-ratio: 3 / 2; overflow: hidden; background: var(--bg-2); }
.shot img { width: 100%; height: 100%; object-fit: cover; }
.shot:focus-visible { outline: 2px solid var(--cue); outline-offset: 3px; }
/* Phone, a cycle of three: 1 alone, 2-3 a pair; a lone last photo pairs with the one before */
@media (max-width: 699px) {
  .spread > li:is(:nth-of-type(3n+2), :nth-of-type(3n+3), :nth-of-type(3n+1):nth-last-of-type(2)) { grid-column: span 3; }
}
@media (min-width: 700px) {
  /* Rows of two or three: 2, 3, 3, 2, 3, 2 and again, fifteen photos a cycle. Pairs by default, then the threes */
  .spread > li { grid-column: span 3; }
  .spread > li:is(:nth-of-type(15n+3), :nth-of-type(15n+4), :nth-of-type(15n+5), :nth-of-type(15n+6), :nth-of-type(15n+7), :nth-of-type(15n+8), :nth-of-type(15n+11), :nth-of-type(15n+12), :nth-of-type(15n+13)) { grid-column: span 2; }
  /* Closing up. Two left in a row of three: a pair */
  .spread > li:is(:nth-of-type(15n+4):last-of-type, :nth-of-type(15n+3):nth-last-of-type(2), :nth-of-type(15n+7):last-of-type, :nth-of-type(15n+6):nth-last-of-type(2), :nth-of-type(15n+12):last-of-type, :nth-of-type(15n+11):nth-last-of-type(2)) { grid-column: span 3; }
  /* One left after a pair: the three make a row of three */
  .spread > li:is(:nth-of-type(15n+16), :nth-of-type(15n+3), :nth-of-type(15n+11)):last-of-type,
  .spread > li:nth-last-of-type(-n+3):has(~ li:is(:nth-of-type(15n+16), :nth-of-type(15n+3), :nth-of-type(15n+11)):last-of-type) { grid-column: span 2; }
  /* One left after a three: the four make two pairs */
  .spread > li:is(:nth-of-type(15n+6), :nth-of-type(15n+9), :nth-of-type(15n+14)):last-of-type,
  .spread > li:nth-last-of-type(-n+4):has(~ li:is(:nth-of-type(15n+6), :nth-of-type(15n+9), :nth-of-type(15n+14)):last-of-type) { grid-column: span 3; }
  /* A single photo on the page sits centred */
  .spread > li:only-of-type { grid-column: 2 / span 4; }
}
/* No photos: the section steps aside */
.spread-sec:not(:has(.shot)) { display: none; }

/* Videos: 16:9 players, one a row on phones, two from 700px, same gap as the photos. Empty: the section steps aside */
.vids-sec { padding-top: 0; }
.spread-sec:not(:has(.shot)) + .vids-sec { padding-top: calc(var(--header) + var(--s-5)); }
.vids-sec:not(:has(.vid)) { display: none; }
.vids-sec .h2 { margin-bottom: var(--s-4); }
.vids { display: grid; gap: var(--gutter); list-style: none; }
@media (min-width: 700px) { .vids { grid-template-columns: repeat(2, minmax(0, 1fr)); } .vids > li:only-child { grid-column: 1 / -1; width: 66.67%; justify-self: center; } }
.vid { aspect-ratio: 16 / 9; background: var(--bg-2); }
.vid iframe { display: block; width: 100%; height: 100%; border: 0; }
.vid-t { margin-top: var(--s-2); font-weight: 700; }
.vid-c { color: var(--muted); font-size: var(--fs-small); }
.vid-c:empty { display: none; }

/* Viewer: the photo in a frame sized from its own shape (--r, set by media.js), so nothing moves while it loads.
   --v-chrome is the height the controls take. Phone: the controls sit in a bar at the bottom, under the thumb */
html:has(.viewer[open]) { overflow: hidden; }
.viewer { --v-chrome: 8rem; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--text); touch-action: pan-y; }
.viewer::backdrop { background: var(--bg); }
.viewer[open] { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.viewer figure { display: grid; align-content: center; justify-items: center; gap: var(--s-2); padding: var(--s-3) var(--gutter) 0; }
.viewer img { width: min(100%, (100svh - var(--v-chrome)) * var(--r, .667)); height: auto; aspect-ratio: var(--r, auto); background: var(--bg-2); }
.v-bar { display: flex; gap: var(--s-1); padding: var(--s-2) var(--gutter) max(var(--s-2), env(safe-area-inset-bottom)); }
.v-btn { width: var(--btn-h); padding: 0; background: var(--bg); font-size: var(--fs-h3); }
.v-close { margin-left: auto; }
/* Wide screens, and short ones (a phone on its side): the controls move to the edges and the photo takes the height */
@media (min-width: 1024px), (max-height: 500px) {
  .viewer { --v-chrome: 8rem; }
  .viewer[open] { grid-template-rows: minmax(0, 1fr); }
  .viewer figure { padding-block: var(--s-5); }
  .v-bar { display: contents; }
  .v-btn { position: absolute; }
  .v-close { top: var(--s-2); right: var(--gutter); }
  .v-prev, .v-next { top: 50%; translate: 0 -50%; }
  .v-prev { left: var(--gutter); } .v-next { right: var(--gutter); }
}
@media (max-height: 500px) { .viewer { --v-chrome: 2rem; } .viewer figure { padding-block: var(--s-2); } }
