.template-art--screenshot {
    display: block;
    min-height: 0;
    padding: 0;
    aspect-ratio: 3 / 4;
    background: #eee9e1;
    border: 1px solid #ded8ce;
    border-radius: 6px;
    box-shadow: 0 10px 28px rgba(36, 62, 52, .08);
    isolation: isolate;
}

.template-art--screenshot::after {
    content: "";
    position: absolute;
    inset: 55% 0 0;
    z-index: 1;
    background: linear-gradient(transparent, rgba(24, 36, 31, .22));
    pointer-events: none;
}

.template-preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    transition: transform .35s ease;
}

.template-art--screenshot:hover .template-preview-image,
.template-art--screenshot:focus-visible .template-preview-image {
    transform: scale(1.025);
}

.template-preview-badge {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 12px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 4px 14px rgba(23, 35, 30, .14);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.2;
    font-weight: 600;
    letter-spacing: .2px;
    transition: transform .25s ease, background .25s ease;
}

.template-caption {
    min-height: 44px;
    margin-top: 14px;
    gap: 12px;
}

.template-caption h3 {
    flex: 1;
    min-width: 0;
    font-size: 18px;
    line-height: 1.3;
    font-weight: 600;
}

.template-caption a {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    min-height: 44px;
    padding: 10px 0 10px 12px;
    font-size: 15px;
    line-height: 1.25;
    font-weight: 500;
    white-space: nowrap;
}

.template-art--screenshot:hover .template-preview-badge,
.template-art--screenshot:focus-visible .template-preview-badge {
    background: #fff;
    transform: translateY(-2px);
}

.template-art--screenshot:focus-visible {
    outline: 3px solid #8a604c;
    outline-offset: 4px;
}

.template-caption a:focus-visible {
    outline: 2px solid #8a604c;
    outline-offset: 4px;
}

@media (max-width: 1100px) {
    .template-caption h3 {
        font-size: 17px;
    }
}

/* Full catalogue on /templates/: four per row, narrowing with the viewport. */
.template-grid--catalog {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 32px 22px;
}

.template-grid--catalog .template-caption h3 {
    font-size: 16px;
}

.template-grid--catalog .template-caption a {
    font-size: 13px;
}

@media (max-width: 1100px) {
    .template-grid--catalog {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .template-grid--catalog {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: none;
        gap: 26px 14px;
    }

    .template-grid--catalog .template-caption {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
    }

    .template-grid--catalog .template-caption a {
        min-height: 36px;
        padding: 6px 0;
    }
}

@media (max-width: 420px) {
    .template-grid--catalog {
        grid-template-columns: 1fr;
        max-width: 380px;
    }
}

/* The preview badge waits for hover on pointer devices; touch screens keep it visible. */
@media (hover: hover) and (pointer: fine) {
    .template-art--screenshot::after,
    .template-preview-badge {
        opacity: 0;
        transition: opacity .25s ease, transform .25s ease, background .25s ease;
    }

    .template-preview-badge {
        transform: translateY(6px);
    }

    .template-art--screenshot:hover::after,
    .template-art--screenshot:focus-visible::after,
    .template-art--screenshot:hover .template-preview-badge,
    .template-art--screenshot:focus-visible .template-preview-badge {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .template-preview-image,
    .template-preview-badge {
        transition: none;
    }

    .template-art--screenshot:hover .template-preview-image,
    .template-art--screenshot:focus-visible .template-preview-image {
        transform: none;
    }
}
