:root {
    --primary-color: #ff6b35;
    --secondary-color: #4a7c59;
    --danger-color: #ff4444;
    --warning-color: #ffc107;
    --success-color: #4CAF50;
    --dark-bg: #1a1a1a;
    --darker-bg: #0f0f0f;
    --medium-bg: #2a2a2a;
    --light-bg: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --border-color: #444;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --scroll-speed: 0.5s;
}

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

body {
    font-family: 'Space Mono', monospace;
    background: var(--dark-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

#gameContainer {
    width: 100%;
    height: 100%;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--dark-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loader-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

/* ========== MAIN MENU ========== */
/* Restored original main menu style */
#mainMenu {
    background: linear-gradient(135deg, var(--darker-bg) 0%, var(--dark-bg) 100%);
    justify-content: center;
}

.menu-content {
    text-align: center;
    max-width: 600px;
    padding: 2rem;
}

#mainMenu h1 {
    font-size: 4rem;
    margin-bottom: 2rem;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(255, 107, 53, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.btn-primary, .btn-secondary, .btn-success, .btn-warning, .btn-danger {
    font-family: 'Space Mono', monospace;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 1rem 2rem;
    background: var(--medium-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    min-width: 250px;
    margin: 0 auto;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-secondary {
    background: var(--medium-bg);
    color: var(--text-primary);
}

.btn-success {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.btn-warning {
    background: var(--warning-color);
    color: black;
    border-color: var(--warning-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    min-width: auto;
}

.btn-back {
    background: none;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    padding: 0.8rem 1.5rem;
}

.badge {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    background: var(--medium-bg);
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.menu-footer {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.version-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.7;
}

/* ========== TANK BUILDER ========== */
#tankBuilder {
    background: var(--darker-bg);
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.builder-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    flex-shrink: 0;
}

.builder-content {
    display: flex;
    gap: 2rem;
    flex: 1;
    min-height: 0; /* Important for flex scrolling */
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Left Side: Scrollable Component Selection */
.component-selection {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 800px;
    background: var(--medium-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.component-scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) rgba(255, 255, 255, 0.1);
}

.component-scroll-container::-webkit-scrollbar {
    width: 8px;
}

.component-scroll-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.component-scroll-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.component-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #ff8b5c;
}

.component-category {
    margin-bottom: 2rem;
}

.component-category:last-child {
    margin-bottom: 0;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.category-header h3 {
    color: var(--text-primary);
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.category-count {
    background: rgba(255, 107, 53, 0.2);
    color: var(--primary-color);
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: bold;
}

.component-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.component-card {
    background: var(--light-bg);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 140px;
}

.component-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.component-card.selected {
    border-color: var(--primary-color);
    background: rgba(255, 107, 53, 0.1);
    box-shadow: 0 0 20px rgba(255, 107, 53, 0.2);
}

.component-icon {
    font-size: 2.2rem;
    margin-bottom: 0.8rem;
    color: var(--primary-color);
    text-align: center;
}

.component-name {
    font-weight: bold;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    text-align: center;
    color: var(--text-primary);
}

.component-tier {
    background: rgba(255, 107, 53, 0.2);
    color: var(--primary-color);
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 0.8rem;
}

.component-stats {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Right Side: Tank Preview (Fixed) */
.tank-preview {
    flex: 0 0 380px;
    background: var(--medium-bg);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-header h3 {
    font-size: 1.4rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.tier-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.4rem 1rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
}

.preview-canvas-container {
    position: relative;
    width: 100%;
    height: 200px;
    background: var(--darker-bg);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
}

#previewCanvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.preview-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

.tank-stats {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    overflow-y: auto;
    padding-right: 5px;
    scrollbar-width: thin;
}

.tank-stats::-webkit-scrollbar {
    width: 4px;
}

.tank-stats::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 2px;
}

.stat-item {
    background: var(--light-bg);
    padding: 0.8rem;
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-primary);
}

.preview-actions {
    display: flex;
    gap: 1rem;
    flex-shrink: 0;
}

/* ========== GAME SCREEN ========== */
#gameScreen {
    background: var(--dark-bg);
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

#gameUI {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 10;
}

.ui-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.ui-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.health-bar {
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    padding: 0.8rem;
    min-width: 200px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.bar-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.bar-container {
    position: relative;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--warning-color));
    transition: width 0.3s ease;
}

.bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.info-panel {
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    padding: 1rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
    color: var(--text-primary);
    font-size: 1rem;
}

.info-item:last-child {
    margin-bottom: 0;
}

.damage-indicators {
    position: absolute;
    pointer-events: none;
    z-index: 20;
}

.damage-indicator {
    position: absolute;
    color: var(--danger-color);
    font-weight: bold;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px);
    }
}

.mini-map {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 150px;
    height: 150px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    border: 2px solid var(--border-color);
    overflow: hidden;
    backdrop-filter: blur(10px);
}

#miniMapCanvas {
    width: 100%;
    height: 100%;
}

/* Mobile Controls */
#mobileControls {
    position: absolute;
    bottom: 1rem;
    left: 0;
    right: 0;
    z-index: 30;
}

.mobile-controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
}

.joystick-zone {
    width: 150px;
    height: 150px;
}

.mobile-buttons {
    display: flex;
    gap: 1rem;
}

.btn-fire {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--danger-color);
    border: none;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
}

.btn-brake {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--warning-color);
    border: none;
    color: black;
    font-size: 0.9rem;
    font-weight: bold;
}

/* Game Menu */
.game-menu {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    display: flex;
    gap: 0.8rem;
}

.btn-menu {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.8rem 1.2rem;
    backdrop-filter: blur(10px);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--medium-bg);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    border: 2px solid var(--border-color);
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1.5rem 0;
}

.settings-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    background: var(--light-bg);
    border-radius: 6px;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* ========== RESPONSIVE DESIGN ========== */
@media (max-width: 1024px) {
    .builder-content {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
    }
    
    .component-selection {
        flex: none;
        max-width: 100%;
        max-height: 50vh;
    }
    
    .tank-preview {
        flex: none;
        width: 100%;
        max-height: 50vh;
    }
    
    .component-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 768px) {
    .ui-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    .health-bar {
        min-width: auto;
    }
    
    .mini-map {
        width: 100px;
        height: 100px;
    }
    
    .mobile-controls-container {
        padding: 0 1rem;
    }
    
    .joystick-zone {
        width: 120px;
        height: 120px;
    }
    
    .btn-fire {
        width: 80px;
        height: 80px;
        font-size: 1rem;
    }
    
    .btn-brake {
        width: 60px;
        height: 60px;
        font-size: 0.8rem;
    }
    
    #mainMenu h1 {
        font-size: 3rem;
    }
    
    .menu-content {
        padding: 1rem;
    }
    
    .btn-primary, .btn-secondary {
        min-width: 200px;
        padding: 0.8rem 1.5rem;
    }
    
    .component-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    #mainMenu h1 {
        font-size: 2.5rem;
    }
    
    .component-grid {
        grid-template-columns: 1fr;
    }
    
    .tank-preview {
        padding: 1rem;
    }
    
    .preview-actions {
        flex-direction: column;
    }
    
    .preview-actions button {
        width: 100%;
    }
}