@layer base, components;

@layer base {
    * {
        box-sizing: border-box;
        padding: 0;
        margin: 0;
    }

    :root {
        --cover-size: 15rem;
    }

    @media (max-width: 800px) {
        :root {
            --cover-size: 9rem;
        }
    }

    @media (max-width: 500px) {
        :root {
            --cover-size: 6rem;
        }
    }

    html, body {
        height: 100%;
        width: 100%;
        color: #ccc;
        background: #111;
        text-align: center;
    }

    body {
        font-family: sans-serif;
        display: flex;
        flex-direction: column;
        gap: 0em;
        padding: 0em;
    }

    @supports (place-content: safe center) {
        body {
            place-content: safe center;
        }
    }

    a {
        color: papayawhip;
    }

    footer {
        font-style: italic;
        margin-top: 1em;
    }

    .cards {
        list-style: none;
        overflow-x: scroll;
        width: 100%;
        white-space: nowrap;
        outline: 0px solid #333;
        background: transparent;
    }

    .cards:focus {
        outline-color: #666;
    }

    .cards:not(.active) {
        scroll-snap-type: x mandatory;
    }

    .cards li {
        display: inline-block;
        width: var(--cover-size);
        height: var(--cover-size);
        scroll-snap-align: center;
    }

    .cards li a {  /* Corrected and moved here */
        pointer-events: auto;
        display: block;
        width: 100%;
        height: 100%;
        z-index: 10;
        position: relative;
    }

    .cards li img { /* Corrected and moved here */
        display: block;
        width: var(--cover-size);
        height: var(--cover-size);
        pointer-events: none;
        z-index: 1;
    }

    .cards {
        min-height: calc(var(--cover-size) * 2.5);
        max-width: calc(var(--cover-size) * 6);
        margin: 0 auto;
        padding: calc(var(--cover-size) / 3 * 2) 0;
    }

    .cards li:first-of-type {
        margin-left: calc(50% - var(--cover-size) / 2);
    }

    .cards li:last-of-type {
        margin-right: calc(50% - var(--cover-size) / 2);
    }
}


@layer components {
    @layer warning {
        .warning {
            padding: 1em;
            border: 0px solid blue;
            z-index: 9999;
            color: blue;
            background: rgba(255 255 225 / 0.9);
            z-index: 10001;
            width: max-content;
            margin: 0 auto;
        }

        :is(.warning:hover, .warning:has(:focus-within)) {
            opacity: 1;
        }

        .warning > :first-child {
            margin-top: 0;
        }

        .warning > :last-child {
            margin-bottom: 0;
        }

        .warning a {
            color: blue;
        }

        .warning--info {
            border: 0px solid #123456;
            background: rgba(205 230 255 / 0.8);
        }
    }

    @layer debug {
        #debug {
            position: absolute;
            top: 1em;
            left: 1em;
        }

        #debug::after {
            content: " Show Debug";
            margin-left: 1.5em;
            color: white;
            white-space: nowrap;
        }

        #debug:checked + .cards {
            border: 0px solid lime;
        }

        #debug:checked + .cards li {
            text-align: center;
            color: white;
            border: 1px solid blue;
        }

        #debug:checked + .cards li::before {
            content: attr(id);
            display: block;
            position: absolute;
            inset: 0;
            line-height: var(--cover-size);
            opacity: 0.5;
        }

        #debug:checked + .cards li img {
            opacity: 0.5;
        }
    }
}

@supports (view-timeline: --works) {
    .warning {
        display: none;
    }

    @keyframes adjust-z-index {
        0% {
            z-index: 1;
        }
        50% {
            z-index: 100;
        }
        100% {
            z-index: 1;
        }
    }

    @keyframes rotate-cover {
        0% {
            transform: translateX(-100%) rotateY(-45deg);
        }
        35% {
            transform: translateX(0) rotateY(-45deg);
        }
        50% {
            transform: rotateY(0deg) translateZ(1em) scale(1.5);
        }
        65% {
            transform: translateX(0) rotateY(45deg);
        }
        100% {
            transform: translateX(100%) rotateY(45deg);
        }
    }

    .card-text {
        position: absolute;
        bottom: 10px;
        color: white;
        background: transparent;
        padding: 5px;
        border-radius: 50px;
        text-align: center;
        max-width: 90%;
    }

    .cards li {
        view-timeline-name: --li-in-and-out-of-view;
        view-timeline-axis: inline;
        animation: linear adjust-z-index both;
        animation-duration: auto;
        animation-timeline: --li-in-and-out-of-view;
        animation-range: contain 0% contain 100%;
        perspective: 40em;
        position: relative;
        z-index: 1;
        will-change: z-index;
        user-select: none; /* Make sure this is still here for firefox */
    }

    .cards li > img {
        animation: linear rotate-cover both;
        animation-duration: auto;
        animation-timeline: --li-in-and-out-of-view;
        animation-range: contain 0% contain 100%;
        transform: translateX(-100%) rotateY(-45deg);
        will-change: transform;
    }
    .cards li > a > img {
        animation: linear rotate-cover both;
        animation-duration: auto;
        animation-timeline: --li-in-and-out-of-view;
        animation-range: contain 0% contain 100%;
        transform: translateX(-100%) rotateY(-45deg);
        will-change: transform;
    }
}

