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

body {
    font-family: 'Special Elite', cursive;
    background: #1a1510;
    color: #d4c4a8;
    overflow: hidden;
    min-height: 100vh;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    background: linear-gradient(135deg, #2a2015 0%, #1a1510 50%, #0f0a05 100%);
}

/* Header */
#game-header {
    background: linear-gradient(180deg, #3a2a1a 0%, #2a1a0a 100%);
    border-bottom: 3px solid #654321;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

#game-header h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(12px, 3vw, 20px);
    color: #ffd700;
    text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 215, 0, 0.5);
    letter-spacing: 2px;
}

#header-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(8px, 2vw, 12px);
    background: rgba(0, 0, 0, 0.4);
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid #654321;
}

.stat img {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

/* Main Game Area */
#game-main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#canvas {
    flex: 1;
    display: block;
    cursor: crosshair;
}

/* Wave Incoming Overlay */
#wave-incoming {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: borderPulse 0.5s infinite alternate;
}

#wave-incoming.hidden {
    display: none;
}

#wave-incoming-content {
    text-align: center;
    animation: shake 0.3s infinite;
}

#wave-incoming-text {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(20px, 5vw, 36px);
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8), 2px 2px 0 #000;
    animation: textPulse 0.5s infinite alternate;
}

#countdown-timer {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(48px, 10vw, 80px);
    color: #ffd700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8), 3px 3px 0 #000;
    margin-top: 20px;
}

@keyframes borderPulse {
    from { box-shadow: inset 0 0 50px rgba(255, 50, 50, 0.3); }
    to { box-shadow: inset 0 0 100px rgba(255, 50, 50, 0.6); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

@keyframes textPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* Tower Panel */
#tower-panel {
    width: 200px;
    background: linear-gradient(180deg, #3a2a1a 0%, #2a1a0a 100%);
    border-left: 3px solid #654321;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#tower-panel h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #ffd700;
    text-align: center;
    border-bottom: 2px solid #654321;
    padding-bottom: 10px;
}

#tower-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.tower-option {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #654321;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tower-option:hover {
    border-color: #ffd700;
    transform: scale(1.05);
}

.tower-option.selected {
    border-color: #0f0;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.tower-option.quick-build {
    border-color: #ff6600;
    animation: quickBuildPulse 1s infinite alternate;
}

.quick-build-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff6600;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    padding: 3px 5px;
    border-radius: 4px;
    animation: badgePulse 0.5s infinite alternate;
}

@keyframes quickBuildPulse {
    from { box-shadow: 0 0 5px rgba(255, 102, 0, 0.5); }
    to { box-shadow: 0 0 15px rgba(255, 102, 0, 0.8); }
}

@keyframes badgePulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

.tower-option img {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}

.tower-cost {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #ffd700;
}

#tower-info {
    font-size: 11px;
    line-height: 1.6;
    color: #a89070;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    min-height: 80px;
}

/* Footer Controls */
#game-footer {
    background: linear-gradient(180deg, #2a1a0a 0%, #3a2a1a 100%);
    border-top: 3px solid #654321;
    padding: 10px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

#next-wave-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    background: linear-gradient(180deg, #4a0 0%, #360 100%);
    color: #fff;
    border: 2px solid #5b0;
    padding: 12px 25px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    text-shadow: 1px 1px 0 #000;
}

#next-wave-btn:hover {
    background: linear-gradient(180deg, #5b0 0%, #4a0 100%);
    transform: scale(1.05);
}

#next-wave-btn.hidden {
    display: none;
}

#skip-wait-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    background: linear-gradient(180deg, #a40 0%, #720 100%);
    color: #fff;
    border: 2px solid #c50;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

#skip-wait-btn:hover {
    background: linear-gradient(180deg, #c50 0%, #a40 100%);
    transform: scale(1.05);
}

#skip-wait-btn.hidden {
    display: none;
}

#speed-controls {
    display: flex;
    gap: 5px;
}

.speed-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #d4c4a8;
    border: 2px solid #654321;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.speed-btn:hover {
    border-color: #ffd700;
}

.speed-btn.active {
    background: #654321;
    border-color: #ffd700;
    color: #ffd700;
}

#pause-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #d4c4a8;
    border: 2px solid #654321;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

#pause-btn:hover {
    border-color: #ffd700;
}

/* Overlay */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#overlay.hidden {
    display: none;
}

#overlay-content {
    background: linear-gradient(180deg, #3a2a1a 0%, #2a1a0a 100%);
    border: 4px solid #654321;
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 90%;
    animation: popIn 0.3s ease-out;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

#overlay-title {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(20px, 5vw, 32px);
    color: #ffd700;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #000, 0 0 20px rgba(255, 215, 0, 0.5);
}

#overlay-message {
    font-size: 16px;
    margin-bottom: 15px;
}

#overlay-score {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: #ffd700;
    margin-bottom: 25px;
}

#restart-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    background: linear-gradient(180deg, #4a0 0%, #360 100%);
    color: #fff;
    border: 3px solid #5b0;
    padding: 15px 30px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

#restart-btn:hover {
    background: linear-gradient(180deg, #5b0 0%, #4a0 100%);
    transform: scale(1.05);
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1510;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-content h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(12px, 3vw, 18px);
    color: #ffd700;
    margin-bottom: 30px;
}

.loading-bar {
    width: 300px;
    max-width: 80vw;
    height: 20px;
    background: #2a1a0a;
    border: 2px solid #654321;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
}

.loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4a0, #ffd700);
    transition: width 0.3s;
}

#loading-text {
    font-size: 14px;
    color: #a89070;
}

/* Countdown active state */
body.countdown-active #tower-panel {
    animation: panelUrgent 0.5s infinite alternate;
}

@keyframes panelUrgent {
    from { border-left-color: #654321; }
    to { border-left-color: #ff4444; }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #tower-panel {
        position: absolute;
        bottom: 60px;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        border-left: none;
        border-top: 3px solid #654321;
        padding: 10px;
        gap: 10px;
        background: rgba(42, 26, 10, 0.95);
    }
    
    #tower-panel h3 {
        display: none;
    }
    
    #tower-options {
        display: flex;
        gap: 10px;
    }
    
    .tower-option {
        padding: 8px;
    }
    
    #tower-info {
        display: none;
    }
    
    #game-footer {
        padding: 8px 10px;
        gap: 10px;
    }
    
    #next-wave-btn {
        font-size: 10px;
        padding: 10px 15px;
    }
    
    #skip-wait-btn {
        font-size: 8px;
        padding: 8px 10px;
    }
    
    .speed-btn {
        font-size: 8px;
        padding: 6px 10px;
    }
    
    #pause-btn {
        font-size: 8px;
        padding: 8px 10px;
    }
    
    #wave-incoming-text {
        font-size: clamp(16px, 4vw, 24px);
    }
    
    #countdown-timer {
        font-size: clamp(36px, 8vw, 60px);
    }
}

/* Footer credit */
#game-footer::after {
    content: 'Inspired by the 1863 DeRussy Defense Plan • Made with 🍓 at berrry.app';
    display: block;
    width: 100%;
    text-align: center;
    font-size: 9px;
    color: #666;
    margin-top: 5px;
}

@media (max-width: 600px) {
    #game-footer::after {
        font-size: 7px;
    }
}