🎄 Christmas Gift Match 🎁

Flip the cards and find all the matching pairs of Christmas treasures. Fewer moves and less time means a higher score!
Moves: 0  |  Time: 0s  |  Score: 0
Press "Start" to deal the cards!

Deck the halls with this festive memory game! Flip the cards to find all 8 pairs of Christmas treasures: Santa 🎅, the tree 🎄, gifts 🎁, snowmen ⛄ and more. Your score depends on how few moves and how little time you need, so train your memory and aim for a perfect game.

Here is the code
CSS
.xmas-game {
    text-align: center;
}

.instructions {
    max-width: 500px;
    margin: 0 auto 15px;
    font-size: 1em;
    color: #555;
}

.xmas-info {
    margin-bottom: 15px;
    font-size: 1.1em;
}

.xmas-board {
    display: grid;
    grid-template-columns: repeat(4, 70px);
    grid-gap: 10px;
    justify-content: center;
}

.xmas-card {
    width: 70px;
    height: 70px;
    border: 2px solid #fff;
    border-radius: 10px;
    background: repeating-linear-gradient(45deg, #c0392b, #c0392b 10px, #a93226 10px, #a93226 20px);
    font-size: 2em;
    line-height: 1;
    color: transparent;
    cursor: pointer;
    transition: transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.xmas-card:hover {
    transform: scale(1.05);
}

.xmas-card.flipped {
    background: #f4fbf4;
    border-color: #1e8449;
    color: inherit;
}

.xmas-card.matched {
    background: #d5f5e3;
    border-color: #1e8449;
    color: inherit;
    cursor: default;
}

.xmas-message {
    margin-top: 15px;
    font-weight: bold;
}

.start-btn {
    margin-top: 15px;
    padding: 10px 20px;
    font-size: 1em;
    background-color: #1e8449;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.start-btn:hover {
    background-color: #239b56;
}
HTML
<div class="xmas-game">
    <h1>🎄 Christmas Gift Match 🎁</h1>
    <div class="instructions">
        Flip the cards and find all the matching pairs of Christmas treasures. Fewer moves and less time means a higher score!
    </div>
    <div class="xmas-info">
        Moves: <span id="xmasMoves">0</span> &nbsp;|&nbsp; Time: <span id="xmasTime">0</span>s &nbsp;|&nbsp; Score: <span id="xmasScore">0</span>
    </div>
    <div class="xmas-board" id="xmasBoard"></div>
    <div class="xmas-message" id="xmasMessage">Press "Start" to deal the cards!</div>
    <button class="start-btn" id="xmasStart">Start</button>
</div>
JS
const board = document.getElementById('xmasBoard');
    const movesDisplay = document.getElementById('xmasMoves');
    const timeDisplay = document.getElementById('xmasTime');
    const scoreDisplay = document.getElementById('xmasScore');
    const message = document.getElementById('xmasMessage');
    const startButton = document.getElementById('xmasStart');
    const hiddenScore = document.getElementById('hiddenScore');

    const SYMBOLS = ['🎅', '🎄', '🎁', '⛄', '🦌', '🔔', '⭐', '🍪'];

    let first = null;
    let second = null;
    let lock = false;
    let moves = 0;
    let seconds = 0;
    let matched = 0;
    let timer;

    function shuffle(array) {
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [array[i], array[j]] = [array[j], array[i]];
        }
        return array;
    }

    function computeScore() {
        // Perfect game = 8 moves. Each extra move and each second costs points.
        return Math.max(0, 100 - (moves - SYMBOLS.length) * 4 - seconds);
    }

    function endGame() {
        clearInterval(timer);
        const score = computeScore();
        scoreDisplay.textContent = score;
        hiddenScore.value = score; // Update hidden score field
        message.textContent = 'Merry Christmas! You found all pairs in ' + moves + ' moves and ' + seconds + 's.';
        startButton.textContent = 'Play again';
        document.querySelector('.share-buttons').style.display = 'flex'; // Show share buttons
    }

    function onCardClick(card) {
        if (lock || card === first || card.classList.contains('matched')) {
            return;
        }
        card.classList.add('flipped');
        card.textContent = card.dataset.symbol;

        if (!first) {
            first = card;
            return;
        }

        second = card;
        moves++;
        movesDisplay.textContent = moves;

        if (first.dataset.symbol === second.dataset.symbol) {
            first.classList.add('matched');
            second.classList.add('matched');
            first = second = null;
            matched++;
            if (matched === SYMBOLS.length) {
                endGame();
            }
        } else {
            lock = true;
            setTimeout(() => {
                [first, second].forEach(c => {
                    c.classList.remove('flipped');
                    c.textContent = '';
                });
                first = second = null;
                lock = false;
            }, 800);
        }
    }

    function startGame() {
        clearInterval(timer);
        first = second = null;
        lock = false;
        moves = 0;
        seconds = 0;
        matched = 0;
        movesDisplay.textContent = 0;
        timeDisplay.textContent = 0;
        scoreDisplay.textContent = 0;
        hiddenScore.value = 0;
        message.textContent = 'Find all the pairs!';
        document.querySelector('.share-buttons').style.display = 'none';
        board.innerHTML = '';

        shuffle([...SYMBOLS, ...SYMBOLS]).forEach(symbol => {
            const card = document.createElement('button');
            card.className = 'xmas-card';
            card.dataset.symbol = symbol;
            card.addEventListener('click', () => onCardClick(card));
            board.appendChild(card);
        });

        timer = setInterval(() => {
            seconds++;
            timeDisplay.textContent = seconds;
        }, 1000);
    }

    startButton.addEventListener('click', startGame);