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

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent shaking caused by vertical scrollbars */
}

h1 {
    font-size: 1.8rem;
}

h2 {
    font-size: 1rem;
    font-style: italic;
}

/* Header at the top */
header {
    width: 100%;
    background-color: #155594;
    color: #FFF;
    text-align: center;
    padding: 8px 10px;
/*     border-bottom: 1px solid #000; */
    z-index: 100;
}

/* Move counter */
.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background-color: #f0f0f0;
    border-radius: 5px;
    margin: 5px 0;
    width: 100%;
    max-width: 520px;
}

#moves-counter {
    font-size: 1.2rem;
    font-weight: bold;
    color: #155594;
}

/* Main content */
main {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    gap: 10px;
    flex-grow: 1;
    overflow-y: auto;
}

p {
    text-align: center;
    font-size: 0.9rem;
    padding: 0 10px;
}

p a {
    color: white;
    text-decoration: none;
}

#congratulations {
    display: none; 
    text-align: center; 
    font-size: 1.3rem; 
    margin-top: 15px;
    color: #2c7d2f;
    font-weight: bold;
    padding: 0 10px;
}

/* Gameboard */
#game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 cards per row by default */
    gap: 8px;
    width: 100%;
    max-width: 520px;
    padding-top: 10px;
}

.card {
    width: 100%;
    aspect-ratio: 1;
    background-image: url(https://vscodeedu.com/cover.png);
    background-size: contain;
    border: 2px solid #000;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
}

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

.card.flipped {
    transform: rotateY(180deg);
    background-image: unset;
}

.card.flipped img {
    display: block;
}

.matched {
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* Confetti container covering the entire screen */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 10;
    overflow: hidden; /* Prevent elements from spilling */
}

/* Confetti pieces */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0.8;
    pointer-events: none;
    animation: fall 2s linear forwards;
    box-sizing: content-box; /* Ensure padding doesn't interfere with size */
}

/* Override different shapes and sizes */
.confetti.small { width: 6px; height: 6px; }
.confetti.medium { width: 12px; height: 12px; }
.confetti.large { width: 16px; height: 16px; }
.confetti.circle { border-radius: 50%; }

/* Falling animation */
@keyframes fall {
    0% {
        transform: translateY(-20vh) rotate(0deg); /* Start well above the screen */
        opacity: 1;
    }
    50% {
        transform: translateY(50vh) rotate(15deg); /* Swing downwards */
    }
    75% {
        transform: translateY(75vh) rotate(-15deg); /* Another swing */
    }
    100% {
        transform: translateY(100vh) rotate(0deg); /* Fall off-screen */
        opacity: 0;
    }
}

/* Play Again button */
#play-again {
    padding: 10px 20px;
    font-size: 18px;
    background-color: #0B8BFF;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    position: relative;
    z-index: 1000;
    display: none;
    margin-top: 15px;
}

#play-again:hover {
    background-color: #007BFF;
}

/* Media queries for responsive design */
@media screen and (max-width: 480px) {
    html, body {
        font-size: 14px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    header {
        padding: 10px 5px;
    }
    
    main {
        padding: 10px;
    }
    
    #game-board {
        grid-template-columns: repeat(3, 1fr); /* 3 cards per row on small screens */
        gap: 6px;
    }
    
    #play-again {
        font-size: 16px;
        padding: 8px 16px;
    }
    
    #moves-counter {
        font-size: 1rem;
    }
}

@media screen and (max-width: 320px) {
    #game-board {
        grid-template-columns: repeat(2, 1fr); /* 2 cards per row on very small screens */
        gap: 5px;
    }
    
    h1 {
        font-size: 1.3rem;
    }
}

@media screen and (min-width: 768px) {
    html, body {
        font-size: 18px;
    }
    
    #game-board {
        gap: 12px;
    }
}

/* Shooting Stars Background */
.night-sky {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #0f2027, #203a43, #2c5364);
    z-index: -10;
    overflow: hidden;
}

.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background-color: #fff;
    border-radius: 50%;
    opacity: 0.8;
}

.shooting-star {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%);
    animation: shooting-star-animation 3s linear infinite;
    opacity: 0;
    transform: rotate(-45deg) translateX(0);
}

.shooting-star::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 2px;
    background: linear-gradient(to right, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 100%);
    transform: translateX(-100%);
}

@keyframes shooting-star-animation {
    0% {
        opacity: 0;
        transform: rotate(-45deg) translateX(0);
    }
    10% {
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: rotate(-45deg) translateX(100vw);
    }
}

/* Adjust the background for main content sections */
header {
    background-color: rgba(21, 85, 148, 0.8); /* Make header slightly transparent */
    position: relative;
    z-index: 1;
}

.game-info {
    background-color: rgba(240, 240, 240, 0.8); /* Make game info slightly transparent */
    position: relative;
    z-index: 1;
}

main {
    position: relative;
    z-index: 1;
}

/* Ensure card backs are visible against the dark background */
.card {
    background-color: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Make congratulations overlay more visible */
#congratulations-overlay {
    background-color: rgba(0, 0, 0, 0.8);
}

#congratulations {
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
}

/* Enhance confetti visibility */
.confetti {
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}