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

body {
    font-family: 'Arial', sans-serif;
    background: #1a1a2e;
    min-height: 100vh;
    overflow: hidden;
}

.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: #1a1a2e;
}

.header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 10px 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
    pointer-events: none;
}

.header > * {
    pointer-events: auto;
}

.header h1 {
    color: #ffd700;
    font-size: 1.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 215, 0, 0.3);
    text-align: center;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.castle-info, .stats-info {
    flex: 1;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 15px;
    border-radius: 10px;
    border: 2px solid #4a4a6a;
    max-width: 250px;
}

.castle-info {
    border-color: #4CAF50;
}

.stats-info {
    border-color: #FF9800;
}

.castle-info h3, .stats-info h3 {
    margin-bottom: 5px;
    color: #fff;
    font-size: 0.9em;
}

.castle-info p, .stats-info p {
    color: #ccc;
    margin: 3px 0;
    font-size: 0.85em;
}

.health-bar {
    width: 100%;
    height: 25px;
    background: #333;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
    border: 2px solid #555;
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    transition: width 0.3s ease;
}

.wave-indicator {
    flex: 1;
    font-size: 1.3em;
    font-weight: bold;
    color: #ffd700;
    text-align: center;
    padding: 12px 20px;
    background: rgba(255, 215, 0, 0.15);
    border-radius: 10px;
    border: 2px solid #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    max-width: 300px;
}

#gameCanvas {
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    cursor: crosshair;
    background: #228B22;
    overflow: hidden;
}

#gameCanvas canvas {
    width: 100% !important;
    height: 100% !important;
}

.shop-btn {
    margin-top: 5px;
    padding: 8px 16px;
    font-size: 0.9em;
    font-weight: bold;
    background: linear-gradient(135deg, #ffd700 0%, #ff9800 100%);
    color: #1a1a2e;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.shop-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

/* Spawn Mode Indicator */
.spawn-mode-indicator {
    position: absolute;
    top: 200px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 12px 25px;
    border-radius: 10px;
    text-align: center;
    z-index: 100;
    border: 2px solid #4CAF50;
    display: none;
    animation: pulse-border 1.5s ease-in-out infinite;
}

.spawn-mode-indicator.active {
    display: block;
}

@keyframes pulse-border {
    0%, 100% { border-color: #4CAF50; box-shadow: 0 0 10px rgba(76, 175, 80, 0.3); }
    50% { border-color: #8BC34A; box-shadow: 0 0 20px rgba(76, 175, 80, 0.6); }
}

.spawn-mode-text {
    display: block;
    font-size: 14px;
    font-weight: bold;
    color: #4CAF50;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

.spawn-mode-troop {
    display: block;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 5px;
}

.spawn-mode-hint {
    display: block;
    font-size: 11px;
    color: #aaa;
}

/* Troop Selection Cards */
.troop-cards {
    position: absolute;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 100;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 15px;
    backdrop-filter: blur(5px);
}

.troop-card {
    width: 80px;
    padding: 10px 8px;
    background: linear-gradient(180deg, rgba(60, 60, 80, 0.9) 0%, rgba(30, 30, 50, 0.9) 100%);
    border: 2px solid #555;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.troop-card:hover {
    transform: translateY(-5px);
    border-color: #ffd700;
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.3);
}

.troop-card.selected {
    border-color: #4CAF50;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
    background: linear-gradient(180deg, rgba(76, 175, 80, 0.3) 0%, rgba(30, 30, 50, 0.9) 100%);
}

.troop-card.selected::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #4CAF50;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
}

.troop-card.cant-afford {
    opacity: 0.5;
    border-color: #666;
}

.troop-key {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.troop-icon {
    font-size: 28px;
    margin-bottom: 5px;
}

.troop-name {
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 3px;
}

.troop-cost {
    font-size: 12px;
    font-weight: bold;
    color: #ffd700;
}

.troop-level {
    font-size: 9px;
    color: #4CAF50;
    margin-top: 3px;
}

/* Troop card colors */
.troop-card[data-troop="militia"] .troop-icon { filter: drop-shadow(0 0 5px #27ae60); }
.troop-card[data-troop="swordsman"] .troop-icon { filter: drop-shadow(0 0 5px #2980b9); }
.troop-card[data-troop="knight"] .troop-icon { filter: drop-shadow(0 0 5px #8e44ad); }
.troop-card[data-troop="champion"] .troop-icon { filter: drop-shadow(0 0 5px #f39c12); }
.troop-card[data-troop="builder"] .troop-icon { filter: drop-shadow(0 0 5px #795548); }
.troop-card[data-troop="cannon"] .troop-icon { filter: drop-shadow(0 0 5px #34495e); }
.troop-card[data-troop="officer"] .troop-icon { filter: drop-shadow(0 0 8px #FFD700); }

.troop-card[data-troop="militia"].selected { border-color: #27ae60; box-shadow: 0 0 15px rgba(39, 174, 96, 0.5); }
.troop-card[data-troop="swordsman"].selected { border-color: #2980b9; box-shadow: 0 0 15px rgba(41, 128, 185, 0.5); }
.troop-card[data-troop="knight"].selected { border-color: #8e44ad; box-shadow: 0 0 15px rgba(142, 68, 173, 0.5); }
.troop-card[data-troop="champion"].selected { border-color: #f39c12; box-shadow: 0 0 15px rgba(243, 156, 18, 0.5); }
.troop-card[data-troop="builder"].selected { border-color: #795548; box-shadow: 0 0 15px rgba(121, 85, 72, 0.5); }
.troop-card[data-troop="cannon"].selected { border-color: #34495e; box-shadow: 0 0 15px rgba(52, 73, 94, 0.5); }
.troop-card[data-troop="officer"].selected { border-color: #FFD700; box-shadow: 0 0 20px rgba(255, 215, 0, 0.6); }

@media (max-width: 600px) {
    .troop-cards {
        top: 100px;
        gap: 5px;
        padding: 8px;
    }
    
    .troop-card {
        width: 55px;
        padding: 8px 5px;
    }
    
    .troop-icon {
        font-size: 20px;
    }
    
    .troop-name {
        font-size: 9px;
    }
    
    .troop-cost {
        font-size: 10px;
    }
    
    .troop-level {
        display: none;
    }
}

.shop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.shop.hidden {
    display: none;
}

.shop-content {
    background: linear-gradient(180deg, #2d2d44 0%, #1a1a2e 100%);
    padding: 30px;
    border-radius: 20px;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 215, 0, 0.2);
    border: 3px solid #ffd700;
}

.shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.shop-content h2 {
    color: #ffd700;
    margin: 0;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.shop-exit {
    background: #f44336;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.shop-exit:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

.shop-gold {
    text-align: center;
    font-size: 1.5em;
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 15px;
}

.shop-section-title {
    color: #ffd700;
    font-size: 1.1em;
    margin: 15px 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #4a4a6a;
}

.shop-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.shop-items.troop-upgrades {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.shop-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 10px;
    border: 2px solid #4a4a6a;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.shop-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.3);
    border-color: #ffd700;
}

.shop-item h3 {
    margin-bottom: 5px;
    font-size: 0.95em;
}

.shop-item p {
    margin: 3px 0;
    color: #ccc;
    font-size: 0.8em;
}

.shop-item .cost {
    font-weight: bold;
    color: #ffd700;
    margin-top: 5px;
    font-size: 0.85em;
}

.shop-item button {
    margin-top: 8px;
    padding: 6px 12px;
    font-size: 0.85em;
    font-weight: bold;
    background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
    width: 100%;
}

.shop-item button:hover {
    transform: scale(1.05);
}

.shop-item button:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.shop-item.troop-upgrade {
    border-width: 2px;
}

.shop-item.troop-upgrade h3 {
    font-size: 0.9em;
}

.shop-close {
    display: block;
    margin: 20px auto 0;
    padding: 12px 40px;
    font-size: 1.1em;
    font-weight: bold;
    background: linear-gradient(135deg, #f44336 0%, #e91e63 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}

.shop-close:hover {
    transform: scale(1.05);
}

.instructions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 20px;
    background: linear-gradient(0deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
    z-index: 100;
    pointer-events: none;
}

.instructions h3 {
    color: #ffd700;
    margin-bottom: 5px;
    font-size: 0.9em;
    display: inline;
    margin-right: 10px;
}

.instructions p {
    color: #ccc;
    margin: 3px 0;
    font-size: 0.8em;
    display: inline;
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over.hidden {
    display: none;
}

.game-over-content {
    background: linear-gradient(180deg, #2d2d44 0%, #1a1a2e 100%);
    padding: 50px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 3px solid #f44336;
}

.game-over-content h2 {
    font-size: 2.5em;
    color: #f44336;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(244, 67, 54, 0.5);
}

.game-over-content p {
    color: #ccc;
    font-size: 1.2em;
    margin-bottom: 30px;
}

.restart-btn {
    padding: 15px 40px;
    font-size: 1.3em;
    font-weight: bold;
    background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
}

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

.shake {
    animation: shake 0.3s ease-in-out;
}

@media (max-width: 768px) {
    .game-info {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .header h1 {
        font-size: 1.2em;
    }
    
    .castle-info, .stats-info {
        max-width: 180px;
        padding: 8px 10px;
    }
    
    .wave-indicator {
        font-size: 1em;
        padding: 8px 12px;
    }
    
    .instructions p {
        font-size: 0.7em;
    }
}
