/* Reset default margins and paddings */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
}

body {
    background-color: black;
    overflow: hidden; /* Prevent scrollbars */
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: Arial, sans-serif;
}

#gameContainer {
    position: relative; /* For positioning child elements */
    background-color: #000; /* Optional: background color for the container */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 1200px; /* Increased max-width for wider screens */
    max-height: 100vh;
    padding: 10px; /* Optional padding */
}

/* Ensure the gameCanvas maintains the correct aspect ratio and scales appropriately */
#gameCanvas {
    background-color: black;
    width: 100%;
    height: auto;
    max-width: 800px; /* Adjust based on your preference */
    max-height: 840px; /* 21 rows * 40px tile size */
    aspect-ratio: 19 / 21; /* Maintain aspect ratio based on map dimensions */
    margin-bottom: 60px; /* Adjust based on footer height */
    display: block;
    border: 2px solid #FFFFFF; /* Optional: Add a border for better visibility */
    border-radius: 10px; /* Optional: Rounded corners */
    /* Dynamic scaling based on viewport height */
    max-width: calc((19 / 21) * (100vh - 100px)); /* Adjust 100px based on other UI elements */
    max-height: calc((21 / 19) * (100vw - 40px)); /* Adjust 40px based on other UI elements */
}

/* Disclaimer Styling */
#disclaimer {
    color: #000;
    text-align: center;
    font-size: 0.8em;
    padding: 10px 20px; /* Simplified padding */
    background-color: #f2f2f2;
    position: fixed; /* Fixed at the bottom */
    bottom: 0;
    left: 50%; /* Center horizontally */
    transform: translateX(-50%); /* Center horizontally */
    width: 90%; /* Responsive width */
    max-width: 600px; /* Prevent excessive width on very wide screens */
    opacity: 1;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    visibility: visible;
    z-index: 1000; /* Stay above other elements */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px; /* Optional: Rounded corners */
}

#disclaimer.hidden {
    opacity: 0;
    visibility: hidden;
}

#closeDisclaimer {
    position: absolute;
    right: 15px;
    top: 10px;
    background: none;
    border: none;
    font-size: 1em;
    cursor: pointer;
    color: #000;
    padding: 0;
    margin: 0;
}

/* Touch Controls Styling */
#touchControls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1001; /* Above disclaimer */
    gap: 10px; /* Space between controls */
}

#touchControls div {
    display: flex;
    gap: 10px; /* Space between buttons */
}

.direction-button {
    width: 60px;
    height: 60px;
    font-size: 24px;
    border: none;
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s, background-color 0.2s;
}

.direction-button:active {
    background-color: rgba(255, 255, 255, 1);
    transform: scale(0.95); /* Slight shrink on press */
}

/* Responsive Adjustments for Width */
@media (max-width: 600px) {
    .direction-button {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

@media (min-width: 1200px) {
    .direction-button {
        width: 70px;
        height: 70px;
        font-size: 28px;
    }
}

/* Responsive UI Elements for Width */
@media (max-width: 800px) {
    #disclaimer {
        font-size: 0.7em;
        padding: 8px 16px;
        width: 95%;
    }

    #closeDisclaimer {
        right: 10px;
    }
}

/* Responsive Adjustments for Height */
@media (max-height: 600px) {
    #gameCanvas {
        margin-bottom: 40px;
        max-width: calc((19 / 21) * (100vh - 60px)); /* Adjusted based on UI elements */
        max-height: calc((21 / 19) * (100vw - 40px));
    }

    #touchControls {
        bottom: 10px;
        left: 10px;
    }

    .direction-button {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* Handling Extremely Wide Screens */
@media (min-width: 1600px) {
    #gameContainer {
        max-width: 1200px; /* Maintain a reasonable max-width */
    }

    #gameCanvas {
        max-width: 1000px; /* Increase canvas size on very wide screens */
        max-height: 1050px; /* Adjust based on aspect ratio */
    }

    #disclaimer {
        max-width: 700px; /* Allow a bit more space for disclaimer text */
    }

    #touchControls {
        left: 30px;
        bottom: 30px;
    }
}

/* Handling Extremely Tall Screens */
@media (min-height: 1200px) {
    #gameContainer {
        max-height: 100vh; /* Ensure it doesn't exceed viewport */
    }

    #gameCanvas {
        max-height: calc((21 / 19) * 1000px); /* Adjust based on aspect ratio */
    }

    #disclaimer {
        max-width: 700px;
    }

    .direction-button {
        width: 70px;
        height: 70px;
        font-size: 28px;
    }
}

/* Handling Ultra-Wide and Ultra-Tall Screens */
@media (min-width: 2000px), (min-height: 1600px) {
    #gameContainer {
        max-width: 1400px; /* Further increase if needed */
    }

    #gameCanvas {
        max-width: 1200px;
        max-height: 1260px; /* 19 * 60 = 1140; adjusted for aspect ratio */
    }

    #disclaimer {
        max-width: 800px;
    }

    .direction-button {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }
}
