/* Media page: one grid of pictures (media.js), Are.na-style: square tiles, each picture whole inside its square, on
   white. The Books page's type and colours (base.css). */

body.media-page {
  background: #fff;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  scrollbar-gutter: stable;
}

.media-page main {
  max-width: 1280px;
  padding-bottom: 96px;
}

/* ← Room on the left, the shuffle and − + on the right, on one hairline. It stays at the top of the screen as the
   grid scrolls under it, so they're always there, zoomed in or out. */
.media-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 16px;
  margin-top: 20px;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--rule);
  background: #fff;
}

/* For screen readers: the page's title, which the pictures stand in for on screen. */
.media-head h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* As on Books. */
.back-to-room {
  margin-right: auto;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}

.back-to-room:hover {
  color: var(--ink);
}

.back-to-room:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 3px;
}

/* Shuffle: two crossing arrows, drawn in the same grey as − and +. */
.shuffle {
  align-self: center;
  display: grid;
  place-items: center;
  padding: 4px 6px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.shuffle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shuffle:hover {
  color: var(--ink);
}

.shuffle:focus {
  outline: none;
}

.shuffle:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

.zoom {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 13px;
  color: var(--faint);
}

.zoom button {
  min-width: 28px;
  padding: 2px 6px;
  border: none;
  background: none;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.zoom button:hover {
  color: var(--ink);
}

.zoom button:disabled {
  color: var(--rule);
  cursor: default;
}

.zoom button:focus {
  outline: none;
}

.zoom button:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

/* Announced to screen readers ("5 to a row"); on screen, − and + speak for themselves. */
.zoom-count {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* ------------------------------------------------------------- the grid */

.gallery {
  display: grid;
  grid-template-columns: repeat(var(--per-row, 5), minmax(0, 1fr));
  gap: var(--gap, 22px);
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  scroll-margin: 64px 24px 24px; /* clear of the − + bar at the top */
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
}

/* A video: its still, with a play mark in the middle (where the still always is, whatever its shape). */
.tile.is-video::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -35% -50%;
  border-style: solid;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent #fff;
  filter: drop-shadow(0 0 4px rgb(0 0 0 / 0.6));
}

.tile:focus {
  outline: none;
}

.tile:focus-visible,
.tile.is-arrived {
  outline: 1.5px solid var(--ink);
  outline-offset: 4px;
}

/* Arrived at from the room: marked, then the mark fades. */
.tile.is-arrived {
  animation: arrived 2.4s ease-in 0.6s forwards;
}

@keyframes arrived {
  to {
    outline-color: transparent;
  }
}

/* ------------------------------------------------------------- one picture at a time */

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: rgb(255 255 255 / 0.97);
  color: var(--text);
}

/* It holds the focus when it opens (media.js), not its first button: no ring round it. */
.lightbox:focus {
  outline: none;
}

.lightbox::backdrop {
  background: transparent;
}

.lightbox[open] {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.lightbox-figure {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  min-height: 0;
  margin: 0;
  padding: 40px 24px 0;
  pointer-events: none; /* clicks round the picture reach the dialog, which closes */
}

/* The picture takes what the screen has left over the caption and the controls (about 180px). */
.lightbox-picture {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
}

.lightbox-picture img,
.lightbox-picture video {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 180px);
  object-fit: contain;
  pointer-events: auto;
}

/* The same caption as under the room on the Books page. */
.lightbox-caption {
  min-height: 2.9em;
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.caption-title {
  display: block;
  font-size: 15px;
  color: var(--ink);
}

.caption-by {
  display: block;
}

.lightbox-controls {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0 calc(20px + env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--faint);
}

.lightbox-controls button {
  padding: 12px 8px;
  border: none;
  background: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.lightbox-controls button:hover {
  color: var(--ink);
}

.lightbox-controls button:focus {
  outline: none;
}

.lightbox-controls button:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

.lightbox-count {
  min-width: 5em;
  text-align: center;
}

.lightbox-close {
  margin-left: 24px;
}

/* No fade: the mark simply goes after a while. */
@media (prefers-reduced-motion: reduce) {
  .tile.is-arrived {
    animation: arrived 0s 3s forwards;
  }
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 760px) {
  .media-head {
    margin-top: 24px;
  }

  .gallery {
    margin-top: 16px;
  }
}
