.kv-photo-gallery {
  background: #f1f6f4;
  scroll-margin-top: 100px;
}

.kv-photo-gallery__track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc((100% - 32px) / 3);
  gap: 16px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 1px;
  scrollbar-width: thin;
  padding: 2px 1px 12px;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  user-select: none;
}

.kv-photo-gallery__track.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
}

.kv-photo-gallery__track:focus-visible {
  outline: 2px solid #0b6f68;
  outline-offset: 3px;
}

.kv-photo-gallery__item {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line, #d9e2e3);
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(21, 33, 38, .04);
  scroll-snap-align: start;
}

.kv-photo-gallery__button {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 7px 7px 0 0;
  background: #dce5e5;
  color: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.kv-photo-gallery__button img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
}

.kv-photo-gallery__button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 35, 34, .03) 35%, rgba(5, 35, 34, .62) 100%);
  pointer-events: none;
  transition: background .2s ease;
}

.kv-photo-gallery__detail {
  display: flex;
  align-items: flex-start;
  position: absolute;
  z-index: 1;
  inset: 0;
  padding: 12px;
  overflow-y: auto;
  background: rgba(5, 48, 46, .91);
  color: #fff;
  font-size: clamp(12px, 1vw, 14px);
  line-height: 1.35;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.kv-photo-gallery__hint {
  position: absolute;
  z-index: 1;
  right: 12px;
  bottom: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 5px rgba(0, 0, 0, .65);
  padding: 5px 7px;
  border-radius: 4px;
  background: rgba(5, 48, 46, .78);
  pointer-events: none;
}

.kv-photo-gallery__item figcaption {
  padding: 12px 14px 14px;
  color: var(--steel, #29424b);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
}

@media (hover: hover) and (pointer: fine) {
  .kv-photo-gallery__button:not(.is-dismissed):hover .kv-photo-gallery__detail {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .kv-photo-gallery__button:not(.is-open):not(.is-dismissed):hover .kv-photo-gallery__hint {
    opacity: 0;
  }
}

.kv-photo-gallery__button.is-open .kv-photo-gallery__detail {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.kv-photo-gallery__button.is-open .kv-photo-gallery__hint,
.kv-photo-gallery__button:focus-visible .kv-photo-gallery__hint {
  opacity: 0;
}

.kv-photo-gallery__button.is-open .kv-photo-gallery__hint {
  opacity: 1;
}

.kv-photo-gallery__button.is-open .kv-photo-gallery__detail {
  padding-bottom: 42px;
}

.kv-photo-gallery__button:focus-visible {
  outline: 3px solid #0b6f68;
  outline-offset: -3px;
}

.kv-photo-gallery__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.kv-photo-gallery__arrows {
  display: flex;
  gap: 8px;
}

.kv-photo-gallery__arrow {
  width: 42px;
  height: 42px;
  border: 1px solid #b9cfc9;
  border-radius: 6px;
  background: #fff;
  color: #08635d;
  font: inherit;
  font-size: 23px;
  cursor: pointer;
}

.kv-photo-gallery__arrow:hover:not(:disabled),
.kv-photo-gallery__arrow:focus-visible {
  background: #e5f1ee;
  outline: 2px solid #0b6f68;
  outline-offset: 2px;
}

.kv-photo-gallery__arrow:disabled {
  opacity: .4;
  cursor: default;
}

.kv-photo-gallery__autoplay {
  min-width: 92px;
  height: 42px;
  border: 1px solid #b9cfc9;
  border-radius: 6px;
  background: #fff;
  color: #08635d;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.kv-photo-gallery__autoplay:hover,
.kv-photo-gallery__autoplay:focus-visible {
  background: #e5f1ee;
  outline: 2px solid #0b6f68;
  outline-offset: 2px;
}

.kv-photo-gallery__autoplay[hidden] {
  display: none;
}

.kv-photo-gallery__count {
  color: var(--steel, #29424b);
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .kv-photo-gallery__track {
    grid-auto-columns: calc((100% - 16px) / 2);
  }
}

@media (max-width: 640px) {
  .kv-photo-gallery__track {
    grid-auto-columns: 100%;
    gap: 12px;
  }

  .kv-photo-gallery__detail {
    padding: 14px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kv-photo-gallery__track {
    scroll-behavior: auto;
  }
  .kv-photo-gallery__detail,
  .kv-photo-gallery__button::after {
    transition: none;
  }
}

/* Small selections still scroll on desktop; larger galleries retain three columns. */
@media (min-width: 641px) {
  .kv-photo-gallery--compact .kv-photo-gallery__track { grid-auto-columns: calc((100% - 16px) / 2); }
}
@media (max-width: 420px) {
  .kv-photo-gallery__controls { gap: 8px; }
  .kv-photo-gallery__arrows { gap: 5px; }
  .kv-photo-gallery__autoplay { min-width: 80px; }
  .kv-photo-gallery__count { font-size: 12px; }
}
