/* Visionneuse d'images : élément <dialog> natif (focus piégé, Échap, couche supérieure). */
@layer components {
  .lightbox {
    --lbx: 252px; /* hauteur réservée au compteur, à la légende et aux flèches */
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 72px 12px 104px;
    border: 0;
    overflow: hidden;
    background: rgb(var(--rgb-night) / 0.985);
    color: var(--color-cream);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  .lightbox[open] {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: lightbox-in 0.35s ease both;
  }

  .lightbox::backdrop {
    background: transparent;
  }

  .lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
  }

  .lightbox__count {
    position: absolute;
    top: 33px;
    left: 20px;
    font-size: 15px;
    line-height: 18px;
    letter-spacing: 0.14em;
  }

  .lightbox__figure {
    --stack-gap: 16px;
    align-items: center;
    width: 100%;
    max-width: 1400px;
  }

  .lightbox__frame {
    width: min(100%, calc((100vh - var(--lbx)) * 1.7778));
    width: min(100%, calc((100dvh - var(--lbx)) * 1.7778));
    aspect-ratio: 16 / 9;
  }

  .lightbox__img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .lightbox__img--a {
    animation: lightbox-img 0.55s ease both;
  }

  .lightbox__img--b {
    animation: lightbox-img-alt 0.55s ease both;
  }

  .lightbox__caption {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    align-content: flex-start;
    justify-content: center;
    gap: 4px 16px;
    min-height: 56px;
    text-align: center;
  }

  .lightbox__title {
    font-style: italic;
    font-size: clamp(20px, 2.2vw, 26px);
    line-height: 1.2;
  }

  .lightbox__nav {
    position: absolute;
    right: 0;
    bottom: 28px;
    left: 0;
    display: flex;
    justify-content: center;
    gap: 56px;
    pointer-events: none;
  }

  .lightbox__nav .icon-btn {
    pointer-events: auto;
  }

  @keyframes lightbox-in {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  /* Deux keyframes identiques : alterner leur nom relance l'animation à chaque changement d'image. */
  @keyframes lightbox-img {
    from {
      opacity: 0;
      transform: scale(0.985);
    }

    to {
      opacity: 1;
      transform: none;
    }
  }

  @keyframes lightbox-img-alt {
    from {
      opacity: 0;
      transform: scale(0.985);
    }

    to {
      opacity: 1;
      transform: none;
    }
  }

  /* Grand écran ou écran bas : flèches de part et d'autre de l'image. */
  @media (min-width: 900px), (max-height: 520px) {
    .lightbox {
      --lbx: 180px;
      padding: 72px 108px 28px;
    }

    .lightbox__nav {
      top: 50%;
      bottom: auto;
      justify-content: space-between;
      gap: 0;
      padding: 0 28px;
      transform: translateY(-50%);
    }
  }

  @media (max-height: 520px) {
    .lightbox {
      --lbx: 104px;
      padding: 16px 76px;
    }

    .lightbox__figure {
      --stack-gap: 8px;
    }

    .lightbox__caption {
      min-height: 36px;
    }

    .lightbox__nav {
      padding: 0 12px;
    }
  }
}
