* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent scrolling */
}

body {
    background-color: black;
    color: white;
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

canvas {
    display: block;
    margin: auto;
    background-color: skyblue;
    max-width: 100vw;
    max-height: 100vh;
    width: auto;
    height: auto;
    object-fit: contain;
}

body.mobile-mode {
    touch-action: none; /* Disable zoom/scroll gestures */
}
input[type="number"],
input[type="text"] {
    width: 100px;
    margin: 5px;
    padding: 5px;
    border: none;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    text-align: center;
}
input[type="submit"] {
    margin: 10px;
    padding: 10px 20px;
    border: none;
    background-color: #4CAF50;
    color: white;
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    cursor: pointer;
}
.hidden {
    display: none;
}
.visible {
    display: block;
}
#gameOverOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    color: white;
    font-family: 'Press Start 2P', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.5s ease-out;
}

#gameOverMessage {
    font-size: 28px;
    color: #00f7ff;
    text-shadow: 0 0 15px #00f7ff;
    margin-bottom: 40px;
    line-height: 1.6;
    text-align: center;
    animation: slideDown 0.5s ease-out;
}

#gameOverOverlay button {
    background: #ff00ff;
    color: white;
    border: none;
    padding: 15px 30px;
    margin: 10px;
    font-family: 'Press Start 2P', cursive;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 0 10px #ff00ff;
    transition: transform 0.2s, background 0.2s;
}

#gameOverOverlay button:hover {
    transform: scale(1.1);
    background: #ff33ff;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#storeOverlay, #lobbyOverlay, #matchSetupOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-family: 'Press Start 2P', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    overflow-y: auto;
}

.setup-container {
    background-color: #222;
    border: 4px solid white;
    padding: 40px;
    width: 95%;
    max-width: 1000px;
    margin: 20px 0;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
}

@media (max-width: 600px) {
    .setup-container {
        padding: 20px;
    }
    .roster-section, .settings-section {
        min-width: 100%;
    }
}


.setup-sections {
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
    margin: 30px 0;
    text-align: left;
    justify-content: center;
}

.roster-section {
    flex: 1.2;
    min-width: 350px;
    border-right: 2px solid #444;
    padding-right: 40px;
}

.settings-section {
    flex: 1;
    min-width: 350px;
}

@media (max-width: 800px) {
    .roster-section {
        border-right: none;
        padding-right: 0;
        border-bottom: 2px solid #444;
        padding-bottom: 40px;
    }
}


.setup-container h1 {
    font-size: 32px;
    color: #ff00ff;
    margin-bottom: 40px;
    text-shadow: 0 0 10px #ff00ff;
}

.setup-container h2 {
    font-size: 18px;
    color: #00f7ff;
    margin-bottom: 20px;
}

.player-list {
    margin-bottom: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.player-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    background: #333;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #555;
}

.player-row input[type="text"] {
    flex: 1;
    min-width: 120px;
    font-size: 12px;
    padding: 8px;
}

.player-row select {
    flex: 1.5;
    min-width: 200px;
    background: #444;
    color: white;
    border: none;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    padding: 8px;
}


.remove-player-btn {
    background: #ff0000;
    color: white;
    border: none;
    padding: 8px;
    cursor: pointer;
    font-size: 14px;
}

.setting-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-group label {
    font-size: 12px;
    color: #aaa;
}

.setting-group > select, 
.setting-group > input {
    width: 100%;
}

.setting-group select, 
.setting-group input[type="number"] {
    background: #333;
    color: white;
    border: 1px solid #555;
    padding: 10px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.toggle-group input[type="number"] {
    width: 80px;
}


.toggle-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.range-group input[type="range"] {
    flex: 1;
    cursor: pointer;
}

.range-group span {
    font-size: 14px;
    color: #ff00ff;
    min-width: 50px;
    text-align: right;
}

.toggle-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

.coming-soon {
    font-size: 10px;
    color: #666;
    font-style: italic;
}

.setting-group.disabled {
    opacity: 0.5;
}

.setup-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
}

.setup-btn {
    background: #444;
    color: white;
    border: 2px solid white;
    padding: 15px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    transition: all 0.2s;
    min-width: 300px;
}

.setup-btn:hover {
    background: #555;
}

.reset-btn {
    background-color: #555 !important;
    padding: 20px 30px !important;
    font-size: 14px !important;
}

.start-btn {
    background: #ff00ff;
    color: white;
    border: none;
    padding: 20px 60px;
    font-family: 'Press Start 2P', cursive;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 0 20px #ff00ff;
    transition: transform 0.2s;
    min-width: 300px;
}

.start-btn:hover {
    transform: scale(1.05);
    background: #ff33ff;
}

#scoreboardContainer {
    width: 90%;
    max-width: 1000px;
    margin-bottom: 30px;
}

.scoreboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 14px;
}

.scoreboard-table th, .scoreboard-table td {
    border: 2px solid #555;
    padding: 15px;
    text-align: center;
}

.scoreboard-table th {
    background-color: #333;
    color: #00f7ff;
}

.player-name-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    padding-left: 10px;
}

.color-swatch {
    width: 20px;
    height: 20px;
    border: 1px solid white;
}

#lobbyPrompt {
    font-size: 20px;
    color: #ff00ff;
    margin-bottom: 20px;
}

#startShoppingButton {
    background-color: #ff00ff;
    color: white;
    border: none;
    padding: 20px 40px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 18px;
    box-shadow: 0 0 15px #ff00ff;
}
.hidden {
    display: none !important;
}

.store-container {
    background-color: #222;
    border: 4px solid white;
    padding: 20px;
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    margin: 20px 0;
}

.store-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #555;
    padding-bottom: 10px;
}

.store-tab {
    background-color: #333;
    color: #aaa;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.store-tab.active {
    background-color: #4CAF50;
    color: white;
}

.store-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.store-item {
    background-color: #333;
    border: 2px solid #4CAF50;
    padding: 10px;
    margin: 10px;
    width: 45%;
    min-width: 200px;
    text-align: center;
}

.item-description {
    font-size: 12px;
    min-height: 40px;
}

.item-price {
    color: gold;
}

.buy-button {
    background-color: #4CAF50;
    border: none;
    padding: 5px 10px;
    color: white;
    font-family: 'Press Start 2P', cursive;
    cursor: pointer;
    font-size: 12px;
    margin-top: 10px;
}

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

.store-message {
    color: gold;
    margin-top: 10px;
    font-size: 14px;
}

.weapon-selector {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00f7ff;
    border-radius: 10px;
    z-index: 50;
    box-shadow: 0 0 10px #00f7ff, inset 0 0 10px rgba(0, 247, 255, 0.2);
}

.weapon-icon {
    width: 50px;
    height: 50px;
    background-color: #333;
    border: 2px solid #555;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.2s ease;
    font-size: 24px; /* Icon/Emoji size */
    color: white;
    text-shadow: 0 0 5px currentColor;
}

.weapon-icon:hover {
    border-color: #ff00ff;
    box-shadow: 0 0 10px #ff00ff;
    transform: scale(1.1);
}

.weapon-icon.selected {
    border-color: #00ff00;
    background-color: #222;
    box-shadow: 0 0 15px #00ff00, inset 0 0 10px rgba(0, 255, 0, 0.3);
}

.weapon-icon.is-ai {
    filter: grayscale(0.8) opacity(0.7);
    cursor: not-allowed;
    border-color: #444;
}

.weapon-count {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: #ff0000;
    color: white;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 50%;
    border: 1px solid white;
}

.weapon-key {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 8px;
    color: #aaa;
}

/* Tooltip */
.weapon-tooltip {
    visibility: hidden;
    width: 150px;
    background-color: rgba(0, 0, 0, 0.9);
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%; /* Position above the icon */
    left: 50%;
    margin-left: -75px;
    opacity: 0;
    transition: opacity 0.3s;
    border: 1px solid #00f7ff;
    box-shadow: 0 0 10px rgba(0, 247, 255, 0.5);
    font-size: 10px;
    pointer-events: none;
}

.weapon-icon:hover .weapon-tooltip {
    visibility: visible;
    opacity: 1;
}

.weapon-tooltip-title {
    color: #00f7ff;
    font-weight: bold;
    margin-bottom: 5px;
    display: block;
    text-transform: uppercase;
}

.weapon-tooltip-stats {
    color: #aaa;
    font-size: 9px;
    margin-top: 5px;
    display: block;
}

.shield-indicator {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 2px solid #00f7ff;
    border-radius: 50%;
}

.health-bar {
    position: absolute;
    height: 4px;
    background-color: red;
}

/* Mobile Styles */
.mobile-fs-btn {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    background: #00f7ff;
    color: black;
    border: none;
    padding: 10px 20px;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 0 15px #00f7ff;
    z-index: 1000;
    transition: transform 0.2s;
}

.mobile-fs-btn:active {
    transform: scale(0.95);
}

body:not(.mobile-mode) .mobile-fs-btn {
    display: none !important;
}

/* Match Setup Mobile Refinement */
.setup-container {
    background-color: #222;
    border: 4px solid white;
    padding: 20px;
    width: 95%;
    max-width: 1000px;
    max-height: 90vh; /* Ensure it fits on small screens */
    overflow-y: auto; /* Allow scrolling within the setup UI */
    margin: 10px 0;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
}

/* Mobile Controls Layout */
.mobile-only {
    display: none;
}

body.mobile-mode .mobile-only:not(.hidden) {
    display: block;
}

#mobileControls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
}

.mobile-left-controls, .mobile-right-controls {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: auto;
    display: flex;
    gap: 10px;
}

.mobile-left-controls {
    left: max(5px, env(safe-area-inset-left));
    height: 90%;
}

.mobile-right-controls {
    right: max(5px, env(safe-area-inset-right));
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Vertical Sliders */
.mobile-slider-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    width: 40px; /* Slimmer */
    opacity: 0.5; /* Transparent */
    transition: opacity 0.2s;
}

.mobile-slider-group:active, .mobile-slider-group:hover {
    opacity: 0.9;
}

.mobile-slider-group label {
    font-size: 8px; /* Smaller */
    color: #aaa;
    margin-bottom: 5px;
}

.slider-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.slider-track.vertical {
    width: 8px; /* Slimmer track */
    flex: 1;
    background: rgba(34, 34, 34, 0.5); /* Transparent */
    border: 1px solid #444;
    border-radius: 4px;
    position: relative;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.slider-handle {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 28px; /* Smaller handle */
    height: 28px;
    background: rgba(0, 247, 255, 0.6); /* Transparent */
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(0, 247, 255, 0.5);
    cursor: pointer;
}

.fine-tune-btn {
    width: 34px; /* Smaller */
    height: 34px;
    background: rgba(51, 51, 51, 0.4); /* Transparent */
    border: 1px solid #555;
    color: rgba(255, 255, 255, 0.7);
    font-family: 'Press Start 2P', cursive;
    font-size: 14px; /* Smaller */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
}

.fine-tune-btn:active {
    background: rgba(68, 68, 68, 0.8);
    transform: scale(0.9);
}

#angleValueDisplay, #powerValueDisplay {
    font-size: 12px;
    color: #ff00ff;
    text-shadow: 0 0 5px #ff00ff;
    margin-top: 10px;
    min-width: 60px;
    transition: transform 0.1s;
}

.pulsing {
    transform: scale(1.3);
    color: #00f7ff !important;
    text-shadow: 0 0 10px #00f7ff !important;
}

/* Action Buttons */
.mobile-action-btn {
    font-family: 'Press Start 2P', cursive;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 15px currentColor;
    transition: transform 0.1s, opacity 0.2s;
    opacity: 0.5; /* Transparent */
}

.mobile-action-btn:active {
    opacity: 1.0;
    transform: scale(0.9);
}

.mobile-action-btn.fire {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.4); /* Transparent red */
    color: rgba(255, 255, 255, 0.8);
    border: 5px solid rgba(255, 255, 255, 0.5);
    font-size: 20px;
    box-shadow: 0 0 25px rgba(255, 0, 0, 0.3);
}

.mobile-action-btn.secondary {
    padding: 15px 25px;
    background: #333;
    color: white;
    border: 2px solid #ff00ff;
    font-size: 12px;
    width: 120px;
}

.mobile-action-btn:active {
    transform: scale(0.9);
}

.mobile-secondary-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Inventory Bar */
.mobile-inventory {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.3); /* Mostly transparent */
    padding: 5px 15px;
    border-radius: 15px;
    border: 1px solid rgba(68, 68, 68, 0.5);
    opacity: 0.6;
}

.mobile-inventory:hover, .mobile-inventory:active {
    opacity: 1.0;
}

/* Reuse desktop icon styles but maybe tweak for mobile */
.mobile-inventory .weapon-icon {
    width: 44px;
    height: 44px;
    font-size: 18px;
}
