/* ==============================================================
   MODAL DE FOTOS (galeria.html)
   Sobe de baixo para cima; a página atrás fica desfocada, não
   escurecida.
   ============================================================== */

/* Trava a rolagem da página enquanto o modal está aberto */
html:has(.lightbox[open]) {
  overflow: hidden;
}

.lightbox {
  width: min(1120px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 0;
  overflow: visible;
  color: var(--ink);
  background: transparent;
}

/* Fundo desfocado com um véu claro bem leve */
.lightbox::backdrop {
  background: rgba(253, 241, 225, 0.16);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  backdrop-filter: blur(18px) saturate(1.15);
}

.lightbox[open] {
  animation: lightbox-up 520ms var(--ease-out);
}

.lightbox[open]::backdrop {
  animation: backdrop-in 380ms ease;
}

.lightbox.is-closing {
  animation: lightbox-down 260ms ease forwards;
}

.lightbox.is-closing::backdrop {
  animation: backdrop-out 260ms ease forwards;
}

/* ---------- Painel ---------- */

.lightbox-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  /* Altura travada na tela: a foto ocupa o espaço que sobrar */
  height: min(calc(100dvh - 32px), 860px);
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(253, 241, 225, 0.94);
  box-shadow:
    0 40px 100px rgba(17, 20, 17, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 8px;
}

.lightbox-counter {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  letter-spacing: 0;
}

.lightbox-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(17, 20, 17, 0.06);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 200ms ease;
}

.lightbox-close:hover {
  background: rgba(17, 20, 17, 0.12);
}

/* ---------- Foto ---------- */

.lightbox-stage {
  position: relative;
  min-height: 0;
}

.lightbox-figure {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  height: 100%;
  margin: 0;
}

.lightbox-figure img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: rgba(17, 20, 17, 0.05);
}

.lightbox-figure figcaption {
  color: var(--muted);
  font-size: var(--fs-small);
  line-height: var(--lh-small);
  text-align: center;
}

.lightbox-nav {
  position: absolute;
  top: calc(50% - 16px);
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(253, 241, 225, 0.82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(17, 20, 17, 0.14);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  translate: 0 -50%;
  transition: background-color 200ms ease, scale 200ms var(--ease-out);
}

.lightbox-nav:hover {
  background: var(--paper);
  scale: 1.06;
}

.lightbox-nav[hidden] {
  display: none;
}

.lightbox-prev {
  left: 14px;
}

.lightbox-next {
  right: 14px;
}

/* ---------- Miniaturas ---------- */

.lightbox-thumbs {
  display: flex;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px;
  scrollbar-width: none;
}

.lightbox-thumbs::-webkit-scrollbar {
  display: none;
}

.lightbox-thumbs[hidden] {
  display: none;
}

.lightbox-thumb {
  flex: 0 0 auto;
  width: 76px;
  height: 56px;
  padding: 0;
  overflow: hidden;
  border-radius: 10px;
  background: linear-gradient(135deg, #b9bf8f, #737b3e 55%, #c27a5a);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 200ms ease, box-shadow 200ms ease;
}

.lightbox-thumb:hover {
  opacity: 0.85;
}

.lightbox-thumb[aria-current="true"] {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--olive);
}

.lightbox-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Animações ---------- */

@keyframes lightbox-up {
  from {
    opacity: 0;
    translate: 0 56px;
    scale: 0.98;
  }
  to {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}

@keyframes lightbox-down {
  to {
    opacity: 0;
    translate: 0 40px;
  }
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes backdrop-out {
  to {
    opacity: 0;
  }
}

/* ==============================================================
   RESPONSIVO
   ============================================================== */

@media (max-width: 640px) {
  .lightbox {
    width: calc(100vw - 20px);
  }

  .lightbox-panel {
    height: calc(100dvh - 20px);
    padding: 10px;
    border-radius: var(--radius-md);
  }

  .lightbox-figure img {
    border-radius: 12px;
  }

  .lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 1.35rem;
  }

  .lightbox-prev {
    left: 8px;
  }

  .lightbox-next {
    right: 8px;
  }

  .lightbox-thumbs {
    justify-content: flex-start;
  }

  .lightbox-thumb {
    width: 62px;
    height: 46px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox[open],
  .lightbox[open]::backdrop,
  .lightbox.is-closing,
  .lightbox.is-closing::backdrop {
    animation: none;
  }

  .lightbox-close,
  .lightbox-nav,
  .lightbox-thumb {
    transition: none;
  }
}
