/* Image lightbox (components/lightbox.js): an OS 9 window over a dimmed desktop. Semantic tokens only.
   Sits above the menu bar and under the CRT overlay (so it still gets scanlines) and the toggle tray.
   Phones: fills the screen under the menu bar. */

.lb {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-os-menubar) + 500);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--menubar-h) + var(--space-4)) var(--space-5) var(--space-5);
  background: color-mix(in srgb, var(--os-outline) 60%, transparent);
}

.lb[hidden] { display: none; }

.lb .lb__win {
  position: relative;
  left: auto;
  top: auto;
  width: min(100%, 75rem);
  height: 100%;
  max-height: 56rem;
  cursor: default;
  animation: lb-in 0.12s ease-out;
}

@keyframes lb-in { from { opacity: 0; transform: scale(0.98); } }

.lb__bar { cursor: default; }

.lb .lb__body {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: var(--space-3);
  background: var(--surface-sunken);
}

.lb__body picture { display: contents; }

.lb__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

/* Wide images: full size, scroll sideways */
.lb .lb__body.is-pan {
  grid-template: auto / auto;
  place-content: safe center; /* centered when smaller; "safe" = starts at the edge when bigger, so every part can be scrolled to */
  place-items: start;
  overscroll-behavior: contain;
}
.lb__body.is-pan .lb__img { max-width: none; max-height: none; }
.lb__body:focus-visible { outline: 2px solid var(--os-focus); outline-offset: -2px; }

.lb__foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0 0;
}

.lb__cap {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--os-text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.45;
}

/* Gallery captions: brand in bold, the type under it */
.lb__cap--two { display: grid; gap: 2px; }
.lb__cap--two span { color: var(--os-text-muted); font-size: 0.9375rem; }

.lb__count {
  color: var(--os-text-muted);
  font-family: var(--font-chrome);
  font-size: var(--os-size);
  white-space: nowrap;
}

/* The page behind doesn't scroll while the lightbox is open */
.os-browser__page.is-lb-locked { overflow: hidden; }

@media (max-width: 43.75rem) {
  .lb { padding: var(--menubar-h) 0 0; }
  .lb .lb__win { width: 100%; height: 100%; max-height: none; }
  .lb__foot { flex-wrap: wrap; }
  .lb__cap { order: -1; flex-basis: 100%; }
  .lb__count { margin-inline: auto; }
}

/* 44px tap targets on phones / touch screens (the close box keeps its look, with a bigger hit area) */
@media (max-width: 43.75rem), (pointer: coarse) {
  .lb__foot .os-btn { min-height: 44px; padding-inline: 16px; }
  .lb__close::before { content: ""; position: absolute; inset: -16px; }
}

@media (prefers-reduced-motion: reduce) {
  .lb .lb__win { animation: none; }
}
