/**
 * VON Bilderslider
 *
 * Macht aus einem Core-Galerie-Block mit dem Stil "Slider" einen
 * horizontalen Slider. Grundlage ist CSS Scroll-Snap: Wischen auf
 * Touch-Geräten funktioniert damit auch ohne JavaScript.
 * von-slider.js ergänzt Autoplay, Pfeile, Punkte und Pause.
 *
 * Wird nur im Frontend geladen. Im Editor bleibt die Galerie ein
 * normales Raster, damit Bilder bequem gepflegt werden können.
 *
 * Die Selektoren enthalten bewusst :not(#individual-image), weil der
 * Core-Galerie-Block diese Spezifität selbst verwendet.
 */

/* --------------------------------------------------------------------------
   Slider-Spur
   -------------------------------------------------------------------------- */

.wp-block-gallery.is-style-von-slider.has-nested-images {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  margin: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none; /* Firefox */
}

.wp-block-gallery.is-style-von-slider.has-nested-images::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

/* Jede Folie ist genau so breit wie der Slider */
.wp-block-gallery.is-style-von-slider.has-nested-images
  figure.wp-block-image:not(#individual-image) {
  flex: 0 0 100%;
  width: 100%;
  margin: 0;
  scroll-snap-align: start;
}

.wp-block-gallery.is-style-von-slider.has-nested-images.is-cropped
  figure.wp-block-image:not(#individual-image)
  img,
.wp-block-gallery.is-style-von-slider.has-nested-images
  figure.wp-block-image:not(#individual-image)
  img {
  /* Core setzt flex: 1 0 0% im Spalten-Flex der figure. Das würde die Höhe
	   überschreiben, deshalb feste Basis. */
  flex: 0 0 auto;
  width: 100%;
  height: clamp(30rem, 72vh, 40rem);
  object-fit: cover;
  object-position: center top;
}

/* Bildunterschrift als kleines Etikett oben rechts statt Verlauf unten */
.wp-block-gallery.is-style-von-slider.has-nested-images
  figure.wp-block-image
  figcaption {
  top: 1rem;
  right: var(--wp--style--root--padding-right, 1.5rem);
  bottom: auto;
  left: auto;
  width: auto;
  max-width: 60%;
  max-height: none;
  padding: 0.25rem 0.65rem;
  border-radius: 3px;
  background: rgba(38, 35, 37, 0.75);
  font-size: var(--wp--preset--font-size--small);
  text-align: right;
}

.wp-block-gallery.is-style-von-slider.has-nested-images
  figure.wp-block-image:has(figcaption)::before {
  display: none;
}

/* --------------------------------------------------------------------------
   Hero: Slider mit Textfläche darüber
   -------------------------------------------------------------------------- */

.von-hero {
  position: relative;
  overflow: hidden;
  background: var(--wp--preset--color--contrast);
}

/* Abdunklung unten, damit weiße Schrift auf jedem Foto lesbar bleibt */
.von-hero::after {
  content: "";
  position: absolute;
  z-index: 1;
  right: 0;
  bottom: 0;
  left: 0;
  height: 70%;
  background: linear-gradient(
    to top,
    rgba(38, 35, 37, 0.9),
    rgba(38, 35, 37, 0)
  );
  pointer-events: none;
}

.von-hero__content {
  position: absolute;
  z-index: 2;
  right: var(--wp--style--root--padding-right, 1.5rem);
  bottom: 5.5rem; /* Platz für die Slider-Steuerung darunter */
  left: var(--wp--style--root--padding-left, 1.5rem);
  max-width: 50rem;
  margin: 0 !important;
  color: #fff;
}

.von-hero__content h1 {
  margin: 0;
  color: #fff;
}

.von-hero__content .is-style-outline .wp-block-button__link {
  color: #fff;
}

/* --------------------------------------------------------------------------
   Steuerung (wird von von-slider.js erzeugt)
   -------------------------------------------------------------------------- */

.von-slider__controls {
  position: absolute;
  z-index: 3;
  right: var(--wp--style--root--padding-right, 1.5rem);
  bottom: 1.25rem;
  left: var(--wp--style--root--padding-left, 1.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: #fff;
}

/* Ohne Hero-Wrapper: Steuerung unter dem Slider statt darüber */
.von-slider__controls--static {
  position: static;
  padding-block: 1rem;
  color: var(--wp--preset--color--contrast);
}

.von-slider__dots,
.von-slider__nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Punkte: 24 x 24 px Klickfläche (WCAG 2.2, 2.5.8), sichtbar nur 8 px */
.von-slider__dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.von-slider__dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: currentColor;
  opacity: 0.6;
  transition: width 0.3s ease;
}

.von-slider__dot[aria-current="true"]::before {
  width: 28px;
  background: var(--wp--preset--color--accent-1);
  opacity: 1;
}

.von-slider__counter {
  min-width: 4.5rem;
  font-family: var(--wp--preset--font-family--bricolage-grotesque);
  font-weight: 600;
  text-align: right;
}

.von-slider__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.von-slider__btn--pause {
  border-color: var(--wp--preset--color--accent-1);
  background: var(--wp--preset--color--accent-1);
  color: var(--wp--preset--color--contrast);
}

.von-slider__btn svg {
  width: 18px;
  height: 18px;
}

/* Zähler auf sehr schmalen Bildschirmen ausblenden */
@media (max-width: 420px) {
  .von-slider__counter {
    display: none;
  }
}

/* Nur für Screenreader sichtbarer Text */
.von-slider__sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .wp-block-gallery.is-style-von-slider.has-nested-images {
    scroll-behavior: auto;
  }

  .von-slider__dot::before {
    transition: none;
  }
}
