body {
    margin: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #000; /* Black background for the page */
    font-family: Arial, sans-serif;
    color: white;
}

canvas {
    background-color: #000; /* Black background for the game */
    display: block;
    border: 2px solid #333; /* Optional border to define game area */
}

/* Base style for all full-screen overlay screens */
#shopContainer,
#skinPickerScreen,
#mainMenuScreen,
#gameOverScreen,
#towerSelectionScreen,
#achievementsScreen,
#codeEntryScreen,
#accountScreen, /* New: Account Screen */
#leaderboardScreen /* New: Leaderboard Screen */ {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9); /* Semi-transparent dark background */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Changed from center to flex-start for scrolling */
    z-index: 1000; /* Ensure it's on top */
    padding: 20px;
    box-sizing: border-box;
    transition: opacity 0.3s ease-in-out;
    overflow-y: auto; /* Enable vertical scrolling */
    padding-top: 50px; /* Add some top padding for better appearance */
}

/* Hidden class for transitions */
.hidden {
    opacity: 0;
    pointer-events: none; /* Disable interaction when hidden */
}

#gameUI {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 20px;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    transition: opacity 0.3s ease-in-out;
}

#controls {
    position: absolute;
    bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    pointer-events: none; /* Allow clicks to pass through to buttons */
    transition: opacity 0.3s ease-in-out;
}

#topRightControls {
    position: absolute;
    top: 10px;
    right: 10px;
    pointer-events: none; /* Allow clicks to pass through to buttons */
    transition: opacity 0.3s ease-in-out;
    display: flex; /* Make buttons arrange horizontally */
    gap: 10px; /* Space between buttons */
}

#dpad {
    display: flex;
    gap: 10px;
}

#rightSideButtons { /* New style for the container of Jump and Dash buttons */
    display: flex;
    flex-direction: column;
    gap: 10px; /* Space between dash and jump buttons */
    align-items: flex-end; /* Align buttons to the right edge of this container */
}

/* General Button Styles for game controls and game over */
#controls button,
#topRightControls button,
#gameOverScreen button { 
    pointer-events: all; /* Make buttons clickable */
    background-color: rgba(255, 255, 255, 0.2); /* Semi-transparent */
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%; /* Make them circular */
    width: 85px; /* Increased size */
    height: 85px; /* Increased size */
    font-size: 36px; /* Increased font size for icons */
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none; /* Prevent text selection */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    touch-action: manipulation; /* Prevent default touch actions like double tap zoom */
    font-weight: bold;
    transition: background-color 0.2s, border-color 0.2s;
}

/* Adjust size for Menu and Shop buttons in topRightControls */
#topRightControls button {
    width: 95px; /* Slightly larger for text labels */
    height: 60px; /* Rectangular shape for text */
    border-radius: 10px; /* Rounded corners for rectangular buttons */
    font-size: 20px; /* Smaller font size for text */
}

#controls button:active,
#topRightControls button:active,
#gameOverScreen button:active {
    background-color: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.8);
}

/* Specific style for the Dash button to adjust font size for "Dash" text */
#dashButton {
    font-size: 24px; /* Smaller font for text label, scaled up */
    padding-top: 5px; /* Adjust padding if needed to center text */
}

#dashButton:disabled {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
}

/* Shop styles */
.shop-header {
    width: 90%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #555;
}

.shop-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #4CAF50; /* Green theme for shop */
}

#shopCoinsDisplay {
    font-size: 1.5em;
    color: #FFD700; /* Gold color for coins */
}

#closeShopButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%; /* Make them circular */
    width: 70px; /* Adjust size for close button */
    height: 70px;
}

#closeShopButton:hover {
    color: #f00;
}

#shopItems {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    width: 90%;
    max-width: 600px;
    background-color: #222;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    max-height: 70vh;
    overflow-y: auto;
}

.shop-item {
    background-color: #333;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #444;
}

.shop-item h3 {
    margin-top: 0;
    font-size: 1.2em;
    color: #FFF;
}

.shop-item p {
    font-size: 0.9em;
    color: #CCC;
    margin: 10px 0;
}

.buy-button {
    background-color: #4CAF50; /* Green buy button */
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s, opacity 0.2s;
    width: 100%;
    box-sizing: border-box;
    height: auto; /* Allow height to adjust based on padding */
    border-radius: 5px; /* Square buttons for shop items */
}

.buy-button:hover:not(:disabled) {
    background-color: #45a049;
}

.buy-button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Game Over Screen styles */
#gameOverScreen h2 {
    font-size: 3.5em;
    color: #E74C3C; /* Red for Game Over */
    margin-bottom: 20px;
}

#gameOverScreen p {
    font-size: 1.8em;
    color: white;
    margin: 10px 0;
}

#gameOverScreen button {
    margin-top: 30px;
    background-color: #2ECC71; /* Green for Play Again */
    color: white;
    font-size: 2em;
    padding: 15px 40px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    width: auto; /* Override general button width */
    height: auto; /* Override general button height */
}

#gameOverScreen button:hover {
    background-color: #27AE60;
}

/* Main Menu Screen styles */
#mainMenuScreen {
    z-index: 1002; /* Ensure main menu is above others initially */
}

#mainMenuScreen h1 {
    font-size: 4em;
    color: #FFF;
    margin-bottom: 40px;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.7);
}

#mainMenuScreen button {
    background-color: #007bff; /* Blue for main menu buttons */
    color: white;
    font-size: 2em;
    padding: 15px 40px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    margin: 10px 0;
    transition: background-color 0.2s, transform 0.1s;
    width: 250px; /* Fixed width for consistency */
}

#mainMenuScreen button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

#mainMenuScreen button:active {
    transform: translateY(0);
}

/* Skin Picker Screen styles */
#skinPickerScreen {
    z-index: 1001; /* Above game, below main menu if main menu is present */
}

.skin-picker-header {
    width: 90%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #555;
}

.skin-picker-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #17A2B8; /* Cyan/Teal theme for skin picker */
}

#skinPickerCoinsDisplay {
    font-size: 1.5em;
    color: #FFD700;
}

#closeSkinPickerButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%;
    width: 70px;
    height: 70px;
}

#closeSkinPickerButton:hover {
    color: #f00;
}

#skinItems {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); /* Slightly smaller items */
    gap: 15px; /* Smaller gap */
    width: 90%;
    max-width: 600px;
    background-color: #222;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    max-height: 70vh;
    overflow-y: auto;
}

.skin-item {
    background-color: #333;
    padding: 10px; /* Slightly less padding */
    border-radius: 5px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #444;
}

.skin-item h3 {
    margin-top: 0;
    font-size: 1em; /* Smaller font */
    color: #FFF;
}

.skin-preview {
    width: 60px;
    height: 60px;
    border: 2px solid #FFF;
    margin: 10px 0;
    display: flex; /* For centering content like images */
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Hide overflow for images */
}

.skin-preview.default-square-preview {
    background-color: var(--default-player-color); /* This will be set by JS using COLOR_PLAYER */
    border-radius: 5px; /* Square shape */
}

.skin-preview.skin-image-preview {
    border-radius: 5px; /* Square shape for images */
    object-fit: contain; /* Ensure image fits */
    width: 100%; /* Fill container */
    height: 100%; /* Fill container */
}

.skin-item p {
    font-size: 0.8em; /* Smaller font */
    color: #CCC;
    margin: 5px 0;
}

.skin-button {
    background-color: #17A2B8; /* Cyan/Teal buy/select button */
    color: white;
    border: none;
    padding: 8px 12px; /* Smaller padding */
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s, opacity 0.2s;
    width: 100%;
    box-sizing: border-box;
    height: auto;
}

.skin-button:hover:not(:disabled) {
    background-color: #138496;
}

.skin-button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Tower Selection Screen styles */
#towerSelectionScreen {
    z-index: 1003; /* Above all other screens */
}

.tower-selection-header {
    width: 90%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #555;
}

.tower-selection-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #f7a000; /* Orange theme for towers */
}

#closeTowerSelectionButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%;
    width: 70px;
    height: 70px;
}

#closeTowerSelectionButton:hover {
    color: #f00;
}

#towerItems {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    width: 90%;
    max-width: 600px;
    background-color: #222;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    max-height: 70vh;
    overflow-y: auto;
}

.tower-item {
    background-color: #333;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #444;
}

.tower-item h3 {
    margin-top: 0;
    font-size: 1.8em;
    color: #FFF;
    margin-bottom: 10px;
}

.tower-item p {
    font-size: 1em;
    color: #CCC;
    margin-bottom: 15px;
}

.tower-item .tower-requirements {
    font-size: 0.9em;
    color: #FFD700;
    margin-top: 10px;
    margin-bottom: 15px;
    font-style: italic;
}

.start-tower-button {
    background-color: #f7a000; /* Orange start button */
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2em;
    transition: background-color 0.2s, opacity 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.start-tower-button:hover:not(:disabled) {
    background-color: #d18700;
}

.start-tower-button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Achievements Screen styles */
#achievementsScreen {
    z-index: 1001; /* Similar to shop/skin picker */
}

.achievements-header {
    width: 90%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #555;
}

.achievements-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #8E44AD; /* Purple theme for achievements */
}

#closeAchievementsButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%;
    width: 70px;
    height: 70px;
}

#closeAchievementsButton:hover {
    color: #f00;
}

#achievementItems {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    width: 90%;
    max-width: 600px;
    background-color: #222;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    max-height: 70vh;
    overflow-y: auto;
}

.achievement-item {
    background-color: #333;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #444;
}

.achievement-item.completed {
    border-color: #2ECC71; /* Green border for completed */
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.achievement-item h3 {
    margin-top: 0;
    font-size: 1.3em;
    color: #FFF;
}

.achievement-item p {
    font-size: 0.9em;
    color: #CCC;
    margin: 5px 0;
}

.achievement-progress {
    font-size: 0.9em;
    font-weight: bold;
    color: #FFD700;
    margin: 5px 0;
}

.achievement-reward-icon {
    width: 50px;
    height: 50px;
    border: 2px solid #FFF;
    margin: 10px 0;
    border-radius: 5px;
    object-fit: contain;
}

.achievement-status {
    font-weight: bold;
    margin-top: 10px;
    padding: 5px 10px;
    border-radius: 5px;
}

.achievement-status.locked {
    background-color: #C0392B; /* Red */
    color: white;
}

.achievement-status.completed {
    background-color: #2ECC71; /* Green */
    color: white;
}

/* Code Entry Screen Styles (New) */
#codeEntryScreen {
    z-index: 1004; /* Highest z-index for pop-up */
}

.code-entry-header {
    width: 90%;
    max-width: 400px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #555;
}

.code-entry-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #FFC107; /* Yellow/Amber theme for codes */
}

#closeCodeEntryButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%;
    width: 70px;
    height: 70px;
}

#closeCodeEntryButton:hover {
    color: #f00;
}

.code-entry-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 90%;
    max-width: 400px;
    background-color: #222;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

#codeInput {
    width: 100%;
    padding: 15px;
    font-size: 1.2em;
    border: 2px solid #555;
    border-radius: 5px;
    background-color: #333;
    color: white;
    box-sizing: border-box; /* Include padding in width */
    text-align: center;
}

#codeInput::placeholder {
    color: #AAA;
}

#redeemCodeButton {
    background-color: #28A745; /* Green redeem button */
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.5em;
    transition: background-color 0.2s;
    width: 100%;
    box-sizing: border-box;
}

#redeemCodeButton:hover {
    background-color: #218838;
}

.code-message {
    margin-top: 10px;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
}

/* New: Account Screen Styles */
#accountScreen {
    z-index: 1005; /* Above code entry */
}

.account-header {
    width: 90%;
    max-width: 400px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #555;
}

.account-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #6C757D; /* Grey/Silver theme for account */
}

#closeAccountButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%; /* Make them circular */
    width: 70px; /* Adjust size for close button */
    height: 70px;
}

#closeAccountButton:hover {
    color: #f00;
}

.account-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 90%;
    max-width: 400px;
    background-color: #222;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

#currentUsernameDisplay {
    font-size: 1.5em;
    color: #FFF;
    margin-bottom: 10px;
}

#usernameInput {
    width: 100%;
    padding: 15px;
    font-size: 1.2em;
    border: 2px solid #555;
    border-radius: 5px;
    background-color: #333;
    color: white;
    box-sizing: border-box;
    text-align: center;
}

#usernameInput::placeholder {
    color: #AAA;
}

#saveUsernameButton {
    background-color: #17A2B8; /* Cyan save button */
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.5em;
    transition: background-color 0.2s;
    width: 100%;
    box-sizing: border-box;
}

#saveUsernameButton:hover {
    background-color: #138496;
}

.account-message {
    margin-top: 10px;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
}

/* New: Leaderboard Screen Styles */
#leaderboardScreen {
    z-index: 1006; /* Above account screen */
}

.leaderboard-header {
    width: 90%;
    max-width: 700px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #555;
}

.leaderboard-header h2 {
    margin: 0;
    font-size: 2.5em;
    color: #FFD700; /* Gold theme for leaderboard */
}

#closeLeaderboardButton {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
    border-radius: 50%;
    width: 70px;
    height: 70px;
}

#closeLeaderboardButton:hover {
    color: #f00;
}

.leaderboard-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 90%;
    max-width: 700px;
    background-color: #222;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    max-height: 75vh;
    overflow-y: auto;
}

#towerSelector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

#towerSelector label {
    font-size: 1.2em;
}

#leaderboardTowerSelect {
    padding: 8px 12px;
    font-size: 1.1em;
    border: 2px solid #555;
    border-radius: 5px;
    background-color: #333;
    color: white;
    appearance: none; /* Remove default dropdown arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%3Cpath%20fill%3D%22%23ffffff%22%20d%3D%22M208.5%2080.5l-80%2080-80-80%2011.3-11.3%2068.7%2068.7%2068.7-68.7z%22%2F%3E%3C%2Fsvg%3E'); /* Custom dropdown arrow */
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

#leaderboardTableContainer {
    width: 100%;
    overflow-x: auto; /* Enable horizontal scrolling if table is too wide */
}

#leaderboardTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    color: white;
    font-size: 1.1em;
}

#leaderboardTable th, #leaderboardTable td {
    border: 1px solid #444;
    padding: 12px;
    text-align: left;
}

#leaderboardTable th {
    background-color: #333;
    font-weight: bold;
    color: #FFD700;
    text-transform: uppercase;
}

#leaderboardTable tr:nth-child(even) {
    background-color: #2a2a2a;
}

#leaderboardTable tr:hover {
    background-color: #3a3a3a;
}

#leaderboardTable td:first-child {
    font-weight: bold;
    color: #FFD700; /* Gold for rank */
}

.leaderboard-message {
    margin-top: 20px;
    font-size: 1em;
    color: #AAA;
    text-align: center;
}