/* Gallery controls extend the existing palette and leave the page layout intact. */
.gallery-link {
  position: absolute;
  inset: 0;
  display: block;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.gallery-link:focus-visible {
  z-index: 1;
  outline: 3px solid var(--gold-light);
  outline-offset: -5px;
}

.gallery-link:focus-visible img {
  transform: scale(1.018);
}

.gallery-grid figcaption {
  pointer-events: none;
}

.gallery-expand {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: rgba(6, 28, 22, 0.65);
  color: white;
  backdrop-filter: blur(6px);
  transition: background 180ms ease, transform 180ms ease;
}

.gallery-expand svg {
  width: 1.25rem;
  height: 1.25rem;
}

.gallery-link:hover .gallery-expand,
.gallery-link:focus-visible .gallery-expand {
  background: var(--forest-deep);
  transform: scale(1.08);
}

.lightbox {
  --viewer-muted: #b8c2bd;
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  overflow: hidden;
  overscroll-behavior: contain;
  border: 0;
  background: #071510;
  color: #f8f6f0;
  font-family: var(--sans);
  color-scheme: dark;
}

.lightbox::backdrop {
  background: rgba(3, 12, 8, 0.96);
}

.lightbox[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(0.75rem, 2vh, 1.5rem);
  animation: lightbox-enter 200ms ease-out both;
}

.lightbox [hidden] {
  display: none !important;
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.lightbox-brand {
  min-width: 0;
  margin-right: auto;
}

.lightbox-brand-name {
  display: block;
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1.25;
}

.lightbox-brand h2 {
  margin: 0.3rem 0 0;
  color: var(--viewer-muted);
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.lightbox-position {
  color: var(--gold-light);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lightbox-control {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(7, 21, 16, 0.9);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.lightbox-control svg {
  width: 100%;
  height: 100%;
}

.lightbox-control:hover {
  border-color: var(--gold-light);
  background: var(--gold-light);
  color: var(--forest-deep);
}

.lightbox :focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 4px;
}

.lightbox-stage {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.75rem, 2.5vw, 3rem);
  min-width: 0;
  min-height: 0;
  touch-action: pan-y pinch-zoom;
}

.lightbox-frame {
  position: relative;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
}

.lightbox-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  animation: lightbox-photo-enter 240ms ease-out both;
}

.lightbox-loading,
.lightbox-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  text-align: center;
}

.lightbox-spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid rgba(215, 187, 143, 0.2);
  border-top-color: var(--gold-light);
  border-radius: 50%;
  animation: lightbox-spin 700ms linear infinite;
}

.lightbox-error p {
  margin-bottom: 1rem;
}

.lightbox-retry {
  min-height: 2.75rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--gold-light);
  border-radius: 0.3rem;
  background: transparent;
  color: var(--gold-light);
  font: inherit;
  cursor: pointer;
}

.lightbox-footer {
  min-width: 0;
}

.lightbox-description {
  min-width: 0;
  padding: 0 0.25rem;
  text-align: center;
}

.lightbox-caption {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1rem, 1.8vw, 1.375rem);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.lightbox-hint {
  margin: 0.35rem 0 0.6rem;
  color: var(--viewer-muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

.lightbox-hint-desktop > span {
  padding: 0 0.4rem;
}

.lightbox-hint-touch {
  display: none;
}

.lightbox-thumbnails {
  display: flex;
  gap: 0.625rem;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.5rem 0.35rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #567166 transparent;
}

.lightbox-thumbnail {
  flex: 0 0 auto;
  width: 4.75rem;
  height: 3.5rem;
  padding: 3px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  background: transparent;
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 180ms ease, border-color 180ms ease;
}

.lightbox-thumbnail img {
  width: 100%;
  height: 100%;
  border-radius: 0.125rem;
  object-fit: cover;
}

.lightbox-thumbnail[aria-current="true"] {
  border-color: var(--gold-light);
  opacity: 1;
}

.lightbox-thumbnail:hover,
.lightbox-thumbnail:focus-visible {
  opacity: 1;
}

@keyframes lightbox-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes lightbox-photo-enter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lightbox-spin {
  to { transform: rotate(360deg); }
}

@media (pointer: coarse) {
  .lightbox-hint-desktop { display: none; }
  .lightbox-hint-touch { display: inline; }
}

@media (max-width: 680px) {
  .lightbox {
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  }

  .lightbox-toolbar { gap: 0.75rem; }
  .lightbox-brand-name { font-size: 1.125rem; }
  .lightbox-control { width: 2.75rem; height: 2.75rem; padding: 0.65rem; }
  .lightbox-stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.5rem 0.75rem;
  }
  .lightbox-frame { grid-column: 1 / -1; grid-row: 1; }
  .lightbox-previous { grid-column: 1; grid-row: 2; justify-self: end; }
  .lightbox-next { grid-column: 2; grid-row: 2; justify-self: start; }
  .lightbox-thumbnail { width: 3.5rem; height: 2.75rem; }
}

@media (max-height: 560px) {
  .lightbox[open] { gap: 0.5rem; }
  .lightbox-toolbar { padding-bottom: 0.4rem; }
  .lightbox-brand h2, .lightbox-hint, .lightbox-thumbnails { display: none; }
  .lightbox-stage {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr);
  }
  .lightbox-frame { grid-column: 2; grid-row: 1; }
  .lightbox-previous { grid-column: 1; grid-row: 1; }
  .lightbox-next { grid-column: 3; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox *, .gallery-expand {
    animation: none !important;
    transition: none !important;
  }
}
