/* lightbox.css (platform) — a picture opened whole, at the size of the screen (ui/_lightbox.html,
   shared/lightbox.js). Loaded by `lightbox()` on the pages that have pictures to open, never by a
   layout: no other page pays for it.

   The picture stands on a dark ground the size of the window, as large as the window lets it
   without being enlarged; above it the count and the close button, beside it the buttons to leaf,
   under it the caption with its credit — the credit in a quieter tone, as under a picture in the
   issue. Colours are the preset's (var(--mn-…)), sizes are named once on `.lightbox` below. */

.lightbox {
  --lightbox-bar: 56px;                 /* the bar with the count and the close button */
  --lightbox-btn: 44px;                 /* a button: a target for a finger */
  --lightbox-gutter: 16px;              /* between the picture and the window's edges */
  --lightbox-measure: 720px;            /* the longest line of the caption */
  --lightbox-words: 30vh;               /* the most of the window the caption takes; more scrolls */
  --lightbox-text-size: 14px;           /* caption and credit, as under the picture on the page */
  --lightbox-text-line: 20px;
  --lightbox-spinner: 32px;             /* the ring while the picture loads */

  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, var(--mn-gray-900) 96%, transparent);
  color: var(--mn-white);
  overscroll-behavior: contain;
}
.lightbox[open] {
  display: grid;
  grid-template-rows: var(--lightbox-bar) minmax(0, 1fr) auto;
}
.lightbox::backdrop { background: transparent; }

/* The page behind it does not scroll along (set by the script while it is open). */
html.lightbox-open { overflow: hidden; }

.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 6px 0 var(--lightbox-gutter);
}
.lightbox__count {
  font-size: var(--lightbox-text-size);
  line-height: var(--lightbox-text-line);
  font-variant-numeric: tabular-nums;
  color: var(--mn-gray-300);
}

.lightbox__btn {
  display: inline-grid;
  place-items: center;
  width: var(--lightbox-btn);
  height: var(--lightbox-btn);
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--mn-white);
  cursor: pointer;
}
.lightbox__btn:hover { background: color-mix(in srgb, var(--mn-white) 14%, transparent); }
.lightbox__btn:focus-visible { outline: 2px solid var(--mn-white); outline-offset: 2px; }
.lightbox__btn[hidden] { display: none; }

/* The picture: as large as its place lets it, never larger than the file — the image service never
   enlarges it either. Absolutely placed with auto margins, so it stays in the middle at any shape. */
.lightbox__stage { position: relative; min-height: 0; }
.lightbox__img {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: calc(100% - 2 * var(--lightbox-gutter));
  max-height: 100%;
  transition: opacity 0.15s ease-out;
}
.lightbox.is-loading .lightbox__img { opacity: 0; }
.lightbox.is-loading .lightbox__stage::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: var(--lightbox-spinner);
  height: var(--lightbox-spinner);
  border: 2px solid color-mix(in srgb, var(--mn-white) 25%, transparent);
  border-top-color: var(--mn-white);
  border-radius: 999px;
  animation: lightbox-spin 0.8s linear infinite;
}
@keyframes lightbox-spin { to { transform: rotate(360deg); } }

/* Leafing: over the edges of the picture, on a dark disc so they read on a light photo too. */
.lightbox__btn--prev,
.lightbox__btn--next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: color-mix(in srgb, var(--mn-gray-900) 55%, transparent);
}
.lightbox__btn--prev { left: 8px; }
.lightbox__btn--next { right: 8px; }
.lightbox__btn--prev:hover,
.lightbox__btn--next:hover { background: color-mix(in srgb, var(--mn-gray-900) 80%, transparent); }

/* Caption and credit, the words of the page; a long caption scrolls in its own box. */
.lightbox__text {
  justify-self: center;
  width: 100%;
  max-width: var(--lightbox-measure);
  max-height: var(--lightbox-words);
  overflow-y: auto;
  padding: 12px var(--lightbox-gutter) var(--lightbox-gutter);
  font-size: var(--lightbox-text-size);
  line-height: var(--lightbox-text-line);
  color: var(--mn-gray-200);
  overflow-wrap: break-word;
}
.lightbox__text a { color: inherit; text-decoration: underline; }
.lightbox__credit { color: var(--mn-gray-400); }

@media (prefers-reduced-motion: reduce) {
  .lightbox__img { transition: none; }
  .lightbox.is-loading .lightbox__stage::after { animation-duration: 2.4s; }
}
