body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center; /* Center the game container vertically */
    font-family: Arial, sans-serif;
    box-sizing: border-box;
    background-image: url(bg.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    padding: 10px; /* Add some padding to prevent overflow */
}

h1 {
    color: black;
    text-align: center;
    border: 2px solid black;
    width: 100%;
    max-width: 490px;
    background-color: #f6dec2;
    padding: 5px;
    font-variant: small-caps;
    margin-block-end: 5px;
    border-radius: 4px;
    font-size: 24px; /* Default font size */
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    width: 100%;
    max-width: 800px;
}

.board {
    background-color: #f6dec2;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    padding: 2px;
    border: 2px solid black;
    border-radius: 4px;
    width: 100%;
    max-width: 480px; /* Maximum width for larger screens */
    aspect-ratio: 1 / 1; /* Ensure the board itself is square */
}

.board button {
    width: 100%;
    height: 100%;
    border: 2px solid black;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1 / 1; /* Ensure each cell is square */
}

/* Create the checkerboard pattern */
.board button:nth-child(odd) {
    background: #f6dec2;
}

.board button:nth-child(even) {
    background: #c8885a;
}

/* Fix the alternating pattern for even rows */
.board button:nth-child(16n+9),
.board button:nth-child(16n+11),
.board button:nth-child(16n+13),
.board button:nth-child(16n+15) {
    background: #c8885a;
}

.board button:nth-child(16n+10),
.board button:nth-child(16n+12),
.board button:nth-child(16n+14),
.board button:nth-child(16n+16) {
    background: #f6dec2;
}

.visited {
    background-color: black !important;
    cursor: not-allowed;
}

.valid-move {
    background-color: #fa8704 !important;
}

.score-container {
    text-align: center;
    font-size: 20px;
    border: 2px solid black;
    border-radius: 4px;
    width: 100%;
    max-width: 490px;
    background-color: #f6dec2;
    padding: 5px;
    font-variant: small-caps;
}

.expression {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    text-align: left;
    font-family: monospace;
    font-size: 11px;
    border: 2px solid black;
    width: 100%;
    max-width: 490px;
    background-color: #f6dec2;
    padding: 5px;
    border-radius: 4px;
    height: 120px;
}

.expression > span {
    padding: 2px 5px;
}

#button-container {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 490px;
    gap: 10px; /* Add gap between buttons */
}

#playAgain, #generate-certificate, #help {
    background-color: #c8885a;
    border: 2px solid black;
    color: black;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-variant: small-caps;
    flex: 1; /* Allow buttons to grow and fill space */
}

#playAgain:hover, #generate-certificate:hover, #help:hover {
    background-color: #f6dec2;
    border: 2px solid black;
    color: black;
}

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Use fixed positioning to center the modal */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8); /* Semi-transparent background */
    justify-content: center;
    align-items: center;
    z-index: 10; /* Ensure it covers everything */
}

.modal-content {
    width: 90%; /* Adjust width for smaller screens */
    max-width: 480px; /* Maximum width for larger screens */
    height: auto; /* Adjust height for content */
    background: #f6dec2; /* White background */
    border: 2px solid black;
    padding: 20px;
    box-sizing: border-box;
    overflow: auto;
    position: relative;
    margin: 20px; /* Add margin to prevent the modal from touching the edges */
}

.close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    font-weight: bold;
    color: black;
    cursor: pointer;
}

.close:hover {
    color: #fa8704; /* Highlight on hover */
}

/* Media Queries for smaller screens */
@media (max-width: 768px) {
    h1 {
        font-size: 20px; /* Smaller font size for smaller screens */
    }

    .board {
        max-width: 90vw; /* Use viewport width to ensure it fits */
    }

    .board button {
        font-size: 18px; /* Adjust font size for smaller screens */
    }

    .score-container, .expression, #button-container {
        max-width: 90vw; /* Use viewport width to ensure it fits */
    }

    #playAgain, #generate-certificate, #help {
        font-size: 14px; /* Smaller font size for buttons */
        padding: 8px 16px; /* Adjust padding for smaller screens */
    }

    .expression {
        font-size: 10px; /* Slightly smaller font size for tablets */
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 18px; /* Even smaller font size for very small screens */
    }

    .board {
        max-width: 90vw; /* Use viewport width to ensure it fits */
    }

    .board button {
        font-size: 14px; /* Adjust font size for very small screens */
    }

    .score-container, .expression, #button-container {
        max-width: 90vw; /* Use viewport width to ensure it fits */
    }

    #playAgain, #generate-certificate, #help {
        font-size: 12px; /* Smaller font size for buttons */
        padding: 6px 12px; /* Adjust padding for very small screens */
    }

    .expression {
        font-size: 8px; /* Slightly smaller font size for tablets */
    }
}