/* ============================================================
   JDT Capital — lightbox
   Self-contained. No @import, no webfonts, no network requests.
   Every selector is scoped under .lb so nothing leaks into the
   rest of the site. Tokens are redeclared locally (on .lb, not
   :root) so this file can be dropped onto any page.
   ============================================================ */

.lb {
  /* Palette */
  --lb-ink:       #0C1520;
  --lb-paper:     #F5F1E8;
  --lb-brass:     #B8823A;
  --lb-brass-lt:  #D7A863;
  --lb-rule:      rgba(245, 241, 232, 0.18);
  --lb-soft:      rgba(245, 241, 232, 0.68);
  --lb-faint:     rgba(245, 241, 232, 0.40);
  --lb-wash:      rgba(184, 130, 58, 0.10);

  /* Type */
  --lb-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --lb-body:    "Archivo", "Helvetica Neue", Helvetica, sans-serif;
  --lb-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Form */
  --lb-radius: 2px;
  --lb-ease:   cubic-bezier(0.22, 1, 0.36, 1);
  --lb-dur:    0.42s;
  --lb-pad:    clamp(0.75rem, 2.2vw, 1.6rem);

  position: fixed;
  inset: 0;
  /* Above the site's grain overlay (z-index 9999) so photos stay clean. */
  z-index: 10000;
  display: block;
  font-family: var(--lb-body);
  color: var(--lb-paper);
  opacity: 0;
  overscroll-behavior: contain;
  transition: opacity var(--lb-dur) var(--lb-ease);
  -webkit-tap-highlight-color: transparent;
}

/* Inert + invisible when closed. Declared after .lb so display wins. */
.lb[hidden] { display: none; }

.lb--open { opacity: 1; }

.lb *,
.lb *::before,
.lb *::after { box-sizing: border-box; }

/* ---------- Backdrop ---------- */
.lb__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 21, 32, 0.96);
  -webkit-backdrop-filter: blur(7px) saturate(115%);
  backdrop-filter: blur(7px) saturate(115%);
}

/* ---------- Shell ---------- */
.lb__shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  padding: var(--lb-pad);
  gap: 0;
}

/* ---------- Bars ---------- */
.lb__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  min-width: 0;
}

.lb__bar--top {
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--lb-rule);
}

.lb__bar--bottom {
  padding-top: 0.7rem;
  border-top: 1px solid var(--lb-rule);
}

/* Group title — mono micro-label with a brass tick */
.lb__title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  min-width: 0;
  font-family: var(--lb-mono);
  font-size: 0.6875rem;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--lb-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb__title::before {
  content: "";
  flex: 0 0 auto;
  width: 14px;
  height: 1px;
  background: var(--lb-brass);
}

/* ---------- Stage ---------- */
.lb__stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: clamp(0.75rem, 2.5vw, 2rem) 0;
  touch-action: pan-y;
}

.lb__figure {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
}

.lb__frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  transform: translateY(8px);
  opacity: 0;
  transition:
    opacity var(--lb-dur) var(--lb-ease),
    transform var(--lb-dur) var(--lb-ease);
}

.lb--open .lb__frame {
  transform: translateY(0);
  opacity: 1;
}

.lb__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 82vh;
  max-height: min(82vh, 100%);
  object-fit: contain;
  border-radius: var(--lb-radius);
  background: rgba(245, 241, 232, 0.04);
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.55),
    0 2px 10px rgba(0, 0, 0, 0.35);
}

/* Before the first image resolves, hold a plausible box so the
   frame does not pop from zero to full size. */
.lb--blank .lb__frame {
  min-width: min(60vw, 620px);
  min-height: min(44vh, 420px);
  border: 1px solid rgba(245, 241, 232, 0.10);
  border-radius: var(--lb-radius);
}

.lb--blank .lb__img { visibility: hidden; }

/* ---------- Loading state ---------- */
.lb__status {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(12, 21, 32, 0.42);
  border-radius: var(--lb-radius);
}

.lb--loading .lb__status { display: flex; }

.lb__status-label {
  font-family: var(--lb-mono);
  font-size: 0.625rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--lb-faint);
}

.lb__status-rule {
  position: relative;
  width: 72px;
  height: 1px;
  overflow: hidden;
  background: var(--lb-rule);
}

.lb__status-rule::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 100%;
  background: var(--lb-brass);
  animation: lb-sweep 1.15s var(--lb-ease) infinite;
}

@keyframes lb-sweep {
  0%   { transform: translateX(-28px); }
  100% { transform: translateX(72px); }
}

/* ---------- Error state ---------- */
.lb__error {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin: 0;
  padding: 1.5rem;
  text-align: center;
  border: 1px solid var(--lb-rule);
  border-radius: var(--lb-radius);
  background: rgba(12, 21, 32, 0.72);
}

.lb--error .lb__error { display: flex; }
.lb--error .lb__img   { visibility: hidden; }
.lb--error .lb__frame {
  min-width: min(60vw, 520px);
  min-height: min(38vh, 340px);
}

.lb__error-line {
  font-family: var(--lb-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--lb-brass-lt);
}

.lb__error-caption {
  max-width: 44ch;
  font-family: var(--lb-body);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--lb-soft);
}

/* ---------- Meta: caption + counter ---------- */
.lb__meta {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  min-width: 0;
}

.lb__caption {
  margin: 0;
  min-width: 0;
  font-family: var(--lb-body);
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--lb-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb__counter {
  flex: 0 0 auto;
  margin: 0;
  font-family: var(--lb-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  color: var(--lb-faint);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}

.lb__count-now { color: var(--lb-brass-lt); }
.lb__count-sep { margin: 0 0.35em; color: var(--lb-rule); }
.lb__count-all { color: var(--lb-faint); }

/* Screen-reader-only text inside the live region */
.lb__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

/* ---------- Controls ---------- */
.lb__controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.lb__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 36px;
  padding: 0 0.75rem;
  margin: 0;
  background: transparent;
  color: var(--lb-soft);
  border: 1px solid var(--lb-rule);
  border-radius: var(--lb-radius);
  font-family: var(--lb-mono);
  font-size: 0.625rem;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition:
    color 0.28s var(--lb-ease),
    border-color 0.28s var(--lb-ease),
    background-color 0.28s var(--lb-ease);
}

.lb__btn:hover {
  color: var(--lb-brass-lt);
  border-color: var(--lb-brass);
  background: var(--lb-wash);
}

.lb__btn:focus-visible {
  outline: 1px solid var(--lb-brass);
  outline-offset: 2px;
  color: var(--lb-brass-lt);
  border-color: var(--lb-brass);
}

/* Fallback for engines without :focus-visible */
.lb__btn:focus { color: var(--lb-brass-lt); border-color: var(--lb-brass); }
.lb__btn:focus:not(:focus-visible) { color: var(--lb-soft); border-color: var(--lb-rule); }

.lb__btn:active { background: rgba(184, 130, 58, 0.18); }

.lb__glyph {
  font-family: var(--lb-mono);
  font-size: 0.8125rem;
  line-height: 1;
}

.lb__label { line-height: 1; }

/* Single-image group: navigation is meaningless, hide it. */
.lb--single .lb__btn--prev,
.lb--single .lb__btn--next { display: none; }

/* ---------- Mobile: bottom-anchored, thumb-sized controls ---------- */
@media (max-width: 720px) {
  .lb__shell { padding: 0.75rem 0.9rem calc(0.9rem + env(safe-area-inset-bottom, 0px)); }

  .lb__stage { padding: 0.9rem 0; }

  .lb__img {
    max-height: 68vh;
    max-height: min(68vh, 100%);
  }

  .lb__bar--bottom {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 0.75rem;
  }

  .lb__meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }

  .lb__caption {
    white-space: normal;
    font-size: 0.875rem;
    text-overflow: clip;
    /* Two lines maximum — the caption must never crowd the image. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .lb__controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
  }

  .lb__btn {
    min-height: 48px;
    padding: 0 0.5rem;
    font-size: 0.5625rem;
    letter-spacing: 0.16em;
  }

  .lb--single .lb__controls { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .lb__label { display: none; }
  .lb__glyph { font-size: 1rem; }
  .lb__btn--close .lb__label { display: inline; }
}

/* Short viewports — keep the image from swallowing the bars */
@media (max-height: 560px) {
  .lb__img {
    max-height: 64vh;
    max-height: min(64vh, 100%);
  }
  .lb--blank .lb__frame { min-height: min(38vh, 260px); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .lb,
  .lb *,
  .lb *::before,
  .lb *::after {
    transition: none !important;
    animation: none !important;
  }

  .lb__frame { transform: none; }

  /* Static determinate-looking rule instead of a sweep */
  .lb__status-rule::after {
    width: 100%;
    opacity: 0.5;
    transform: none;
  }
}

/* ---------- Forced colors / high contrast ---------- */
@media (forced-colors: active) {
  .lb__btn { border-color: ButtonText; }
  .lb__backdrop { background: Canvas; }
}
