/* Hover video tiles: one-line title; font scales with tile width and name length (--title-chars from JS). */

/* Isolate stacking; parent .card:hover uses transform: scale(var(--card-hover-scale)). */
.card--hover-preview {
    isolation: isolate;
}

/* Hide inline thumbnail layers while preview video is showing (opacity fade otherwise reveals them). */
.card--hover-preview:hover,
.card--hover-preview:focus-within {
    background-image: none !important;
    background-color: #0a0a0a !important;
}

body.light .card--hover-preview:hover,
body.light .card--hover-preview:focus-within,
body.light-play .card--hover-preview:hover,
body.light-play .card--hover-preview:focus-within {
    background-color: #1c1c1c !important;
}

.card-hover-preview-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.card--hover-preview:hover .card-hover-preview-video,
.card--hover-preview:focus-within .card-hover-preview-video {
    opacity: 1;
}

/* Bottom title bar for all game tiles (with or without hover video). */
.card::after {
    content: attr(data-game-title);
    position: absolute;
    inset: auto 0 0 0;
    top: auto;
    width: 100%;
    min-width: 0;
    min-height: 2.25em;
    height: auto;
    max-height: min(28%, 3.25rem);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    align-content: center;
    padding: 6px 8px 8px;
    box-sizing: border-box;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    font-size: clamp(0.65rem, calc(92cqw / (3.5 + var(--title-chars, 12))), 1.85rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0.01em;
    text-align: center;
    color: #fff;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.55) 55%, transparent 100%);
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 1),
        0 0 12px rgba(0, 0, 0, 0.9);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.card:hover::after,
.card:focus-visible::after {
    opacity: 1;
}

body.light .card::after,
body.light-play .card::after {
    color: #fff;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.5) 55%, transparent 100%);
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 1),
        0 0 10px rgba(0, 0, 0, 0.85);
}

@container (max-width: 108px) {
    .card::after {
        font-size: clamp(0.55rem, calc(72cqw / (3.5 + var(--title-chars, 12))), 0.95rem);
        max-height: min(32%, 2.6rem);
        padding: 4px 5px 5px;
    }
}

@container (min-width: 109px) and (max-width: 132px) {
    .card::after {
        font-size: clamp(0.58rem, calc(78cqw / (3.5 + var(--title-chars, 12))), 1.05rem);
        max-height: min(30%, 2.75rem);
        padding: 5px 6px 6px;
    }
}

@container (min-width: 133px) and (max-width: 168px) {
    .card::after {
        font-size: clamp(0.6rem, calc(84cqw / (3.5 + var(--title-chars, 12))), 1.2rem);
        max-height: min(29%, 2.9rem);
        padding: 5px 7px 7px;
    }
}

@container (min-width: 169px) and (max-width: 220px) {
    .card::after {
        font-size: clamp(0.62rem, calc(88cqw / (3.5 + var(--title-chars, 12))), 1.4rem);
        max-height: min(28%, 3rem);
        padding: 6px 8px 8px;
    }
}

@container (min-width: 221px) and (max-width: 300px) {
    .card::after {
        font-size: clamp(0.65rem, calc(90cqw / (3.5 + var(--title-chars, 12))), 1.65rem);
        max-height: min(28%, 3.15rem);
        padding: 6px 9px 9px;
    }
}

@container (min-width: 301px) {
    .card::after {
        font-size: clamp(0.68rem, calc(92cqw / (3.5 + var(--title-chars, 12))), 1.85rem);
        max-height: min(28%, 3.25rem);
        padding: 7px 10px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .card-hover-preview-video {
        display: none !important;
    }

    .card--hover-preview:hover .card-hover-preview-video,
    .card--hover-preview:focus-within .card-hover-preview-video {
        opacity: 0;
    }

    .card::after {
        transition: none;
        opacity: 0;
        inset: auto 0 0 0;
        top: auto;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-wrap: nowrap;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        font-weight: 800;
        line-height: 1.15;
        letter-spacing: 0.01em;
        text-align: center;
        color: #fff;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.55) 55%, transparent 100%);
        text-shadow:
            0 1px 2px rgba(0, 0, 0, 1),
            0 0 12px rgba(0, 0, 0, 0.9);
    }

    .card:hover::after,
    .card:focus-visible::after {
        opacity: 1;
    }

    body.light .card::after,
    body.light-play .card::after {
        color: #fff;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.5) 55%, transparent 100%);
        text-shadow:
            0 1px 2px rgba(0, 0, 0, 1),
            0 0 10px rgba(0, 0, 0, 0.85);
    }
}
