/* ============================================================
   Galerie
   ============================================================ */

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.filter-bar {
  position: sticky;
  top: 80px;
  z-index: 50;
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.filter-btn {
  min-height: 40px;
  padding: 8px 15px;
  border: 1.5px solid var(--line2);
  border-radius: 20px;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  font-family: var(--fm);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition:
    color 0.18s ease,
    border-color 0.18s ease,
    background-color 0.18s ease;
}

.filter-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.filter-btn.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.filter-btn:focus-visible,
.gal-item:focus-visible,
.lb-close:focus-visible,
.lb-nav:focus-visible {
  outline: 3px solid var(--blue-l);
  outline-offset: 3px;
}

.gallery-sec {
  padding: 44px 0 80px;
  background: var(--bg);

  /*
   * Außerhalb des sichtbaren Bereichs darf der Browser zunächst auf
   * aufwendige Layout- und Paint-Arbeit verzichten.
   */
  content-visibility: auto;
  contain-intrinsic-size: 900px;
}

.gal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: 12px;
}

.gal-item {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-lg);
  background:
    linear-gradient(
      110deg,
      color-mix(in srgb, var(--dark) 88%, #fff) 8%,
      color-mix(in srgb, var(--dark) 76%, #fff) 18%,
      color-mix(in srgb, var(--dark) 88%, #fff) 33%
    );
  background-size: 200% 100%;
  cursor: zoom-in;
  contain: layout paint style;
}

.gal-item[hidden] {
  display: none !important;
}

.gal-item.tall {
  grid-row: span 2;
  aspect-ratio: auto;
}

.gal-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gal-lazy {
  opacity: 0;
  transition:
    opacity 0.3s ease,
    transform 0.5s ease;
}

.gal-lazy.is-loaded {
  opacity: 1;
}

.gal-lazy.is-error {
  opacity: 0;
}

.no-js .gal-lazy {
  display: none;
}

.gal-noscript {
  display: block;
}

.gal-item:hover .gal-lazy.is-loaded,
.gal-item:focus-visible .gal-lazy.is-loaded {
  transform: scale(1.05);
}

.gal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px;
  background: linear-gradient(to top, rgba(8, 26, 50, 0.9), transparent 55%);
  opacity: 0;
  transition: opacity 0.28s ease;
}

.gal-item:hover .gal-overlay,
.gal-item:focus-visible .gal-overlay {
  opacity: 1;
}

.gal-cat {
  margin-bottom: 5px;
  color: var(--blue-l);
  font-family: var(--fm);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.gal-title {
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
}


/*
 * Kennzeichnung für Galerieeinträge mit mehreren Ansichten.
 * Beispiel: 1/2. Der eigentliche Bildwechsel erfolgt in der Lightbox.
 */
.gal-count {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: 42px;
  min-height: 30px;
  padding: 5px 10px;

  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;

  background: rgba(8, 26, 50, 0.82);
  color: #fff;

  font-family: var(--fm);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;

  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.gal-zoom {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  opacity: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.28s ease;
}

.gal-item:hover .gal-zoom,
.gal-item:focus-visible .gal-zoom {
  opacity: 1;
}

/* ============================================================
   Lightbox – wird nur zusammen mit galerie.css geladen
   ============================================================ */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 76px 24px 32px;
  background: rgba(6, 18, 34, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lightbox.show {
  display: flex;
}

.lb-dialog {
  --lb-control-size: 52px;
  --lb-control-gap: 18px;

  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  /*
   * Feste Dialogbreite:
   * Die Position der Pfeile hängt dadurch nicht mehr vom
   * Seitenverhältnis des aktuell geladenen Bildes ab.
   */
  width: min(980px, calc(100vw - 48px));
  height: min(820px, calc(100vh - 108px));
  max-width: 100%;
  max-height: 100%;
}

/*
 * Das Raster bleibt bei jedem Bild gleich breit.
 * Nur das Bild selbst wird innerhalb der mittleren Fläche mit
 * object-fit: contain angepasst.
 */
.lb-stage {
  display: grid;
  grid-template-columns:
    var(--lb-control-size)
    minmax(0, 1fr)
    var(--lb-control-size);

  align-items: center;
  gap: var(--lb-control-gap);

  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

/* Bildbeschreibung oberhalb des jeweiligen Bildes */
.lb-figure {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 14px;

  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
}

.lb-cap {
  grid-row: 1;

  width: 100%;
  max-width: min(760px, 100%);
  min-height: 1.5em;
  margin: 0;

  color: rgba(255, 255, 255, 0.8);
  font-family: var(--fm);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
}

.lb-img {
  grid-row: 2;
  display: block;

  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;

  border-radius: 10px;
  object-fit: contain;
}

.lb-close,
.lb-nav {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  z-index: 2;

  width: var(--lb-control-size);
  height: var(--lb-control-size);

  border-radius: 50%;
  font-size: 1.55rem;
  line-height: 1;

  transform: none;
}

.lb-close:hover,
.lb-nav:hover {
  border-color: rgba(255, 255, 255, 0.65);
  background: var(--blue);
}

.lb-close {
  position: absolute;
  top: -58px;
  right: 0;
  z-index: 2;

  width: 46px;
  height: 46px;

  border-radius: 10px;
  font-size: 1.3rem;
}

.lb-nav {
  position: relative;
  z-index: 2;

  width: var(--lb-control-size);
  height: var(--lb-control-size);

  border-radius: 50%;
  font-size: 1.55rem;
  line-height: 1;
}

.lb-nav:active {
  transform: scale(0.96);
}

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

@media (max-width: 980px) {
  .filter-bar {
    top: 68px;
  }
}

@media (max-width: 900px) {
  .gal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gal-item.tall {
    grid-row: span 1;
    aspect-ratio: 4 / 3;
  }

  .lightbox {
    padding-right: 14px;
    padding-left: 14px;
  }

  .lb-dialog {
    --lb-control-size: 48px;
    --lb-control-gap: 10px;

    width: min(820px, calc(100vw - 28px));
    height: min(760px, calc(100vh - 100px));
  }
}

@media (max-width: 560px) {
  .filter-bar {
    padding: 18px 0;
  }

  .filters {
    gap: 7px;
  }

  .filter-btn {
    min-height: 38px;
    padding-right: 12px;
    padding-left: 12px;
    font-size: 10px;
  }

  .gallery-sec {
    padding: 28px 0 56px;
  }

  .gal-grid {
    grid-template-columns: 1fr;
  }

  .gal-overlay,
  .gal-zoom {
    opacity: 1;
  }

  .gal-count {
    top: 12px;
    left: 12px;
    min-width: 40px;
    min-height: 28px;
    padding-inline: 9px;
    font-size: 9px;
  }

  .lightbox {
    padding: 66px 8px 18px;
  }

  .lb-dialog {
    --lb-control-size: 44px;

    width: 100%;
    height: calc(100vh - 92px);
  }

  /*
   * Auf kleinen Displays liegen die Pfeile über der festen Bildfläche.
   * Auch hier bleiben ihre Positionen beim Bildwechsel unverändert.
   */
  .lb-stage {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
  }

  .lb-figure {
    width: 100%;
    height: 100%;
    padding-inline: 38px;
  }

  .lb-close {
    top: -52px;
    right: 4px;
    width: 44px;
    height: 44px;
  }

  .lb-nav {
    position: absolute;
    top: 50%;
    width: 44px;
    height: 44px;
    background: rgba(10, 31, 56, 0.94);
    transform: translateY(-50%);
  }

  .lb-prev {
    left: 0;
  }

  .lb-next {
    right: 0;
  }

  .lb-nav:active {
    transform: translateY(-50%) scale(0.96);
  }

  .lb-cap {
    font-size: 10px;
    letter-spacing: 0.045em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .filter-btn,
  .gal-item img,
  .gal-overlay,
  .gal-zoom,
  .lb-close,
  .lb-nav {
    transition: none;
  }

  .gal-item:hover .gal-lazy,
  .gal-item:focus-visible .gal-lazy {
    transform: none;
  }

  .lb-nav:active {
    transition: none;
  }
}


@media (prefers-reduced-motion: no-preference) {
  .gal-item:has(.gal-lazy:not(.is-loaded):not(.is-error)) {
    animation: galerie-platzhalter 1.5s linear infinite;
  }
}

@keyframes galerie-platzhalter {
  to {
    background-position-x: -200%;
  }
}
