:root {
    --page-light: #eeece2;
    --page-dark: #a8a6a0;
    --text-dark: #292722;
    --accent: #f4b942;
    --accent-light: #ffd166;
    --accent-border: #9f6b19;
    --accent-shadow: #9f6b19;
    --card-radius: 12px;
    --card-front-background-file: url("./images/card-front-background.jpg");
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, sans-serif;
    background: linear-gradient(335deg, var(--page-light), var(--page-dark));
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
    color: white;
}

.game {
    width: min(900px, 100%);
    text-align: center;
}

h1 {
    margin: 0;
    font-size: clamp(1.5rem, 7vw, 2.5rem);
}

.game-header {
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    gap: 5px;
}

.info {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 10px 0;
    font-size: 1.1rem;
}

.info span {
    font-weight: bold;
}

#restart {
    border: 2px solid var(--accent-border);
    background: var(--accent);
    color: var(--text-dark);
    min-width: 5.5rem;
    height: 2.5rem;
    padding: 0 0.85rem;
    margin: 10px;
    border-radius: 25% 10%;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    white-space: nowrap;
    box-shadow: 0 3px 0 var(--accent-shadow);
    transition: transform 0.2s, background-color 0.2s, box-shadow 0.2s;
}

#restart:hover {
    background: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: 0 5px 0 var(--accent-shadow);
}

.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    perspective: 1000px;
}

.board-container {
    position: relative;
}

.card {
    aspect-ratio: 1 / 1;
    cursor: pointer;
    perspective: 1000px;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.5s;
    transform-style: preserve-3d;
}

.card.flipped .card-inner,
.card.matched .card-inner {
    transform: rotateY(180deg);
}

.card.celebrating .card-inner {
    animation: celebration-flip 3s ease-in-out 1 forwards;
    animation-delay: var(--celebration-delay, 0ms);
}

@keyframes celebration-flip {
    from {
        transform: rotateY(180deg);
    }

    to {
        transform: rotateY(1980deg);
    }
}

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    backface-visibility: hidden;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.25);
}

.card-front {
    border: 3px solid var(--accent-border);
    background: none;
    isolation: isolate;
}

.card-front::before {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: calc(var(--card-radius) - 3px);
    /* background: url("./images/back7.jpg") center / cover no-repeat; */
    background: var(--card-front-background-file) center / cover no-repeat;
    filter: grayscale(100%);
    z-index: -1;
}

.card-back {
    background: white;
    transform: rotateY(180deg);
    border: 3px solid rgba(255, 255, 255, 0.5);
}

.card.mismatched .card-front,
.card.mismatched .card-back {
    border-color: #e63946;
}

.card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card.matched .card-back {
    box-shadow: 0 0 20px #00ff88;
}

.message {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: calc(100% - 1rem);
    padding: clamp(0.6rem, 3vw, 1rem) clamp(0.8rem, 4vw, 1.5rem);
    border: 2px solid rgba(255, 209, 102, 0.8);
    border-radius: 12px;
    background: rgba(41, 39, 34, 0.78);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(3px);
    font-size: clamp(1.2rem, 7vw, 3.3rem);
    font-weight: bold;
    text-align: center;
    line-height: 1.1;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.8);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

.message.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

@media (prefers-reduced-motion: reduce) {
    .message,
    .message.is-visible {
        transition: none;
    }
}

@media (max-width: 480px) {
    .game-header {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 10px;
    }

    .board {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 2px;
    }

    .card {
        flex: 0 0 calc((100% - 4px) / 3);
    }

    h1 {
        grid-column: 1 / -1;
    }

    .info {
        justify-content: flex-start;
        margin: 0 10px 10px 0;
    }

    #restart {
        min-width: 3.5rem;
        height: 1.5rem;
        padding: 0 0.5rem;
        font-size: 1rem;
        margin: 0 10px 10px 0;
    }
}
