/*
 * Base stylesheet of the photo lightbox (kit `site`, `assets/lightbox.js`, a native <dialog class="tix-lightbox">).
 *
 * Plain CSS over a few custom properties: no build step, no font, no `!important`, nothing to load. A site loads
 * it BEFORE its own stylesheet and, if it wants another look, sets the properties below (on `:root` or anywhere
 * above the dialog, which lives directly in <body>). The defaults sit in `:where(:root)` (zero specificity), so
 * whatever the site sets wins.
 *
 *   --tix-lightbox-scrim      the veil over the page (a dark, mostly opaque colour in both colour schemes)
 *   --tix-lightbox-ink        icons, the counter, the caption and the focus ring
 *   --tix-lightbox-control    the resting background of the round buttons
 *   --tix-lightbox-control-hover  the same on hover
 *   --tix-lightbox-radius     corners of the photo
 *
 * The photo always fits the window: its height is the viewport (dynamic on phones) minus room for the caption
 * and the buttons, its width at most 94% of the window.
 */

:where(:root) {
  --tix-lightbox-scrim: rgb(10 9 8 / 92%);
  --tix-lightbox-ink: #ffffff;
  --tix-lightbox-control: rgb(255 255 255 / 14%);
  --tix-lightbox-control-hover: rgb(255 255 255 / 26%);
  --tix-lightbox-radius: .25rem;
}

/* `[open]` matters: a bare `display: flex` would beat the UA's `dialog:not([open]) { display: none }`
   and leave a closed dialog over the whole page, eating clicks. */
.tix-lightbox[open] {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  overflow: hidden;
  background: transparent;
  color: var(--tix-lightbox-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Horizontal drags reach the script as swipes; vertical scroll and pinch stay with the browser. */
  touch-action: pan-y pinch-zoom;
}
.tix-lightbox::backdrop { background: var(--tix-lightbox-scrim); }

.tix-lightbox__stage {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  max-width: 100%;
}
.tix-lightbox__img {
  display: block;
  max-width: min(94vw, 90rem);
  max-height: calc(100vh - 8rem);
  max-height: calc(100dvh - 8rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--tix-lightbox-radius);
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity .15s;
}
.tix-lightbox.is-loading .tix-lightbox__img { opacity: .35; }
.tix-lightbox__caption {
  max-width: min(94vw, 44rem);
  margin: 0;
  text-align: center;
  font-size: .95rem;
  line-height: 1.4;
}

.tix-lightbox__close, .tix-lightbox__prev, .tix-lightbox__next {
  position: absolute;
  z-index: 1; /* above the photo, which becomes a stacking context while it loads (opacity) */
  border: 0;
  padding: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background: var(--tix-lightbox-control);
  color: var(--tix-lightbox-ink);
  cursor: pointer;
}
/* `:not([hidden])`: an author `display: grid` would outrank the UA's `[hidden] { display: none }`
   and the arrows of a single photo would show. */
.tix-lightbox__close:not([hidden]), .tix-lightbox__prev:not([hidden]), .tix-lightbox__next:not([hidden]) {
  display: grid;
  place-items: center;
}
.tix-lightbox__close:hover, .tix-lightbox__prev:hover, .tix-lightbox__next:hover { background: var(--tix-lightbox-control-hover); }
/* The buttons carry all of the keyboard use; without a ring the lightbox would be worse than the plain link. */
.tix-lightbox__close:focus-visible, .tix-lightbox__prev:focus-visible, .tix-lightbox__next:focus-visible {
  outline: 2px solid var(--tix-lightbox-ink);
  outline-offset: 2px;
}
.tix-lightbox__close { top: 1rem; right: 1rem; }
.tix-lightbox__prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.tix-lightbox__next { right: 1rem; top: 50%; transform: translateY(-50%); }
.tix-lightbox__count {
  position: absolute;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: .85rem;
}
/* Read by screen readers only (position and alt on every step). */
.tix-lightbox__status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Phone: the arrows move under the photo so they never cover it. */
@media (max-width: 40rem) {
  .tix-lightbox__img { max-height: calc(100vh - 9.5rem); max-height: calc(100dvh - 9.5rem); }
  .tix-lightbox__close { top: .6rem; right: .6rem; }
  .tix-lightbox__prev, .tix-lightbox__next { top: auto; bottom: .75rem; transform: none; }
  .tix-lightbox__prev { left: .75rem; }
  .tix-lightbox__next { right: .75rem; }
  .tix-lightbox__count { bottom: 1.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tix-lightbox__img { transition: none; }
}

/* A <dialog> does not lock the scroll of the page behind it. */
body:has(.tix-lightbox[open]) { overflow: hidden; }
