*:has(> .klar-gallery) {
    container-type: inline-size;
    container-name: klar-gallery;
}

.klar-gallery {
    display: grid;
    gap: 0.75rem;
}

.klar-gallery.cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.klar-gallery.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.klar-gallery.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.klar-gallery.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.klar-gallery.cols-5 {
    display: flex;
    flex-wrap: wrap;
}

.klar-gallery a {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 0;
    background: #ecf1f6;
}

.klar-gallery.cols-5 > a {
    flex: 0 0 180px;
    width: 180px;
    max-width: 100%;
    height: 135px;
}

.klar-gallery a img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 220ms ease;
}

.klar-gallery a::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(73, 119, 169, 0.28);
    opacity: 0;
    transition: opacity 220ms ease;
    pointer-events: none;
}

.klar-gallery a i {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1;
    color: #fff;
    font-size: 1.5rem;
    opacity: 0;
    transform: translate(-50%, -50%);
    transition: opacity 220ms ease;
    pointer-events: none;
}

.klar-gallery a:hover img,
.klar-gallery a:focus-visible img {
    transform: scale(1.04);
}

.klar-gallery a:hover::after,
.klar-gallery a:hover i,
.klar-gallery a:focus-visible::after,
.klar-gallery a:focus-visible i {
    opacity: 1;
}

.klar-gallery a:focus-visible {
    outline: 3px solid #4977a9;
    outline-offset: 3px;
}

@container klar-gallery (max-width: 700px) {
    .klar-gallery.cols-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@container klar-gallery (max-width: 480px) {
    .klar-gallery.cols-3,
    .klar-gallery.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@container klar-gallery (max-width: 300px) {
    .klar-gallery.cols-2,
    .klar-gallery.cols-3,
    .klar-gallery.cols-4 { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .klar-gallery a img,
    .klar-gallery a::after,
    .klar-gallery a i { transition: none; }
}
