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

body {
    font-family: Arial, sans-serif;
    background: #2c3e50;
    color: #ecf0f1;
    padding: 10px;
}

#game-container {
    max-width: 1900px;
    margin: 0 auto;
}

#ui-top {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 auto 10px auto;
    max-width: 1200px;
    background: #34495e;
    padding: 8px;
    border-radius: 6px;
}

#player-stats, #ai-stats {
    background: #2c3e50;
    padding: 8px;
    border-radius: 4px;
}

#player-stats h3, #ai-stats h3 {
    margin-bottom: 8px;
    color: #3498db;
}

.control-btn {
    margin-top: 4px;
    padding: 5px 10px;
    font-size: 11px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.control-btn:hover {
    background: #2980b9;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: #3498db;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    transition: transform 0.2s;
}

.toggle-btn:hover {
    color: #5dade2;
}

.toggle-btn.expanded {
    transform: rotate(180deg);
}

#game-board {
    display: flex;
    gap: 10px;
    margin: 0 auto 10px auto;
    max-width: 1200px;
    align-items: flex-start;
}

.zone-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.zone-container:nth-child(1),
.zone-container:nth-child(3) {
    width: 200px;
    flex-shrink: 0;
}

.zone-container:nth-child(2) {
    width: 800px;
    flex-shrink: 0;
}

.zone {
    background: #34495e;
    border: 2px solid #7f8c8d;
    border-radius: 6px;
    padding: 8px;
    position: relative;
    overflow: hidden;
    height: 280px;
}

#player-zone {
    border-color: #3498db;
}

#battle-zone {
    border-color: #e74c3c;
}

#ai-zone {
    border-color: #e67e22;
}

.zone h4 {
    text-align: center;
    margin-bottom: 10px;
    opacity: 1;
    color: #f39c12;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(243, 156, 18, 0.3);
}

.zone-health {
    background: rgba(231, 76, 60, 0.9);
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 11px;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    text-align: center;
    border: 2px solid #c0392b;
    width: 100%;
    box-sizing: border-box;
    min-height: 28px;
}

.lives-number {
    color: #ecf0f1;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.boost-indicator {
    color: #2ecc71;
    font-size: 13px;
    font-weight: bold;
    margin-left: 8px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.zone-gold {
    background: rgba(52, 152, 219, 0.9);
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 11px;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    text-align: center;
    border: 2px solid #2980b9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    height: 28px;
}

.gold-number {
    color: #f1c40f;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    font-family: 'Courier New', monospace;
    min-width: 45px;
    display: inline-block;
    text-align: left;
}

.economy-btn {
    background: #f39c12 !important;
    padding: 4px 8px !important;
    font-size: 11px !important;
    white-space: nowrap;
    margin: 0 !important;
    border-radius: 4px !important;
    flex-shrink: 0;
}

.economy-btn:hover:not(:disabled) {
    background: #e67e22 !important;
}

#difficulty-selector {
    display: flex;
    gap: 4px;
}

.difficulty-btn {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 5px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    font-weight: bold;
    transition: all 0.2s;
}

.difficulty-btn:hover {
    background: #95a5a6;
}

.difficulty-btn.active {
    background: #3498db;
    box-shadow: 0 0 8px rgba(52, 152, 219, 0.6);
}

.ai-strategy-btn {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 3px 5px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 8px;
    font-weight: bold;
    transition: all 0.2s;
}

.ai-strategy-btn:hover {
    background: #95a5a6;
}

.ai-strategy-btn.active {
    background: #e74c3c;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.6);
}

.ai-strategy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.player-ai-strategy-btn {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 3px 5px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 8px;
    font-weight: bold;
    transition: all 0.2s;
}

.player-ai-strategy-btn:hover {
    background: #95a5a6;
}

.player-ai-strategy-btn.active {
    background: #3498db;
    box-shadow: 0 0 8px rgba(52, 152, 219, 0.6);
}

.speed-btn {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    font-weight: bold;
    transition: all 0.2s;
    flex: 1;
}

.speed-btn:hover {
    background: #95a5a6;
}

.speed-btn.active {
    background: #27ae60;
    box-shadow: 0 0 8px rgba(39, 174, 96, 0.6);
}

.battle-info {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    background: rgba(52, 73, 94, 0.8);
    padding: 6px 12px;
    border-radius: 6px;
    border: 2px solid #7f8c8d;
    height: 61px;
    box-sizing: border-box;
}

.round-display {
    font-size: 16px;
    font-weight: bold;
    color: #ecf0f1;
}

.timer-display {
    font-size: 16px;
    font-weight: bold;
    color: #f1c40f;
}

#ui-bottom {
    background: #34495e;
    padding: 10px;
    border-radius: 6px;
}

#unit-shop h3 {
    margin-bottom: 8px;
    color: #3498db;
}

#tiers-container {
    display: flex;
    flex-direction: row;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.tier-section {
    flex: 0 0 auto;
    min-width: 180px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 2px solid #34495e;
}

.tier-section.locked {
    opacity: 0.5;
    border-color: #7f8c8d;
}

#first-unit-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    animation: pulse-message 2s infinite;
}

@keyframes pulse-message {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.buy-btn.cannot-afford {
    position: relative;
    opacity: 0.6;
}

.buy-btn.cannot-afford::after {
    content: '✕';
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 20px;
    color: rgba(231, 76, 60, 0.95);
    font-weight: bold;
    pointer-events: none;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.9);
}

.upgrade-btn.cannot-afford {
    position: relative;
    opacity: 0.6;
}

.upgrade-btn.cannot-afford::after {
    content: '✕';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 16px;
    color: rgba(231, 76, 60, 0.95);
    font-weight: bold;
    pointer-events: none;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.9);
}

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

.tier-header h4 {
    margin: 0;
    color: #ecf0f1;
}

.tier-countdown {
    color: #e67e22;
    font-size: 12px;
    font-weight: bold;
}

.units-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.buy-btn {
    padding: 6px 10px;
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    border: 2px solid #3498db;
    border-radius: 6px;
    color: #ecf0f1;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
    width: 100px;
    min-height: 70px;
    flex-shrink: 0;
}

.buy-btn .unit-name {
    font-weight: bold;
    font-size: 13px;
    color: #3498db;
}

.buy-btn .unit-stats {
    font-size: 8px;
    color: #95a5a6;
    line-height: 1.3;
    font-family: 'Courier New', monospace;
    word-wrap: break-word;
}

.buy-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border-color: #3498db;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.4);
}

.buy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button {
    margin-right: 8px;
    padding: 6px 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

button:hover:not(:disabled) {
    background: #2980b9;
}

button:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
}

/* Unit styling */
.unit {
    position: absolute;
    width: 30px; 
    height: 30px; 
    border-radius: 6px;
    border: 2px solid #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
}


.target-line {
    position: absolute;
    height: 1px;
    pointer-events: none;
    z-index: 1;
}

.target-line.player {
    background-color: rgba(52, 152, 219, 0.4);
    box-shadow: 0 0 2px rgba(52, 152, 219, 0.6);
}

.target-line.ai {
    background-color: rgba(231, 76, 60, 0.4);
    box-shadow: 0 0 2px rgba(231, 76, 60, 0.6);
}

.unit.tier-2 {
    width: 48px; /* doubled */
    height: 48px; /* doubled */
}

.unit.tier-3 {
    width: 56px; /* doubled */
    height: 56px; /* doubled */
}

/* Team colors - blue vs red */
.unit.player {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border-color: #2980b9;
    box-shadow: 0 0 6px rgba(41, 128, 185, 0.5);
}

.unit.ai {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    border-color: #c0392b;
    box-shadow: 0 0 6px rgba(192, 57, 43, 0.5);
}

/* Shape differences for unit types */
.unit.melee {
    border-radius: 3px; /* Slight rounding for melee */
}

.unit.ranged {
    border-radius: 1px; /* Very square for ranged */
    transform: rotate(45deg); /* Diamond shape */
}

.unit.ranged .unit-hp,
.unit.ranged .unit-timer,
.unit.ranged .health-bar,
.unit.ranged .cooldown-bar {
    transform: rotate(-45deg); /* Counter-rotate content */
}

.unit-timer {
    position: absolute;
    top: -24px; /* moved up to match larger units */
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: bold;
    color: #ecf0f1;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 10;
}

.unit.caster {
    border-radius: 50%; /* Full circle for casters */
}

.unit.player.caster {
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.7); /* Blue glow for player casters */
}

.unit.ai.caster {
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.7); /* Red glow for AI casters */
}

.unit.healer {
    border-radius: 50%; /* Circular like caster */
}

.unit.player.healer {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    border-color: #27ae60;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.7);
}

.unit.ai.healer {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    border-color: #e67e22;
    box-shadow: 0 0 8px rgba(243, 156, 18, 0.7);
}

.health-bar {
    position: absolute;
    bottom: -12px; /* adjusted for larger units */
    left: 0;
    width: 100%;
    height: 4px;
    background: #e74c3c;
}

.health-bar-fill {
    height: 100%;
    background: #2ecc71;
    transition: width 0.2s;
}

.cooldown-bar {
    position: absolute;
    bottom: -20px; /* adjusted for larger units */
    left: 0;
    width: 100%;
    height: 3px;
    background: rgba(0, 0, 0, 0.3);
}

.cooldown-bar-fill {
    height: 100%;
    background: #f39c12;
    transition: width 0.1s linear;
}

/* Projectile styling */
.projectile {
    position: absolute;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle, #f39c12 0%, #e67e22 100%);
    border-radius: 50%;
    box-shadow: 0 0 4px #f39c12;
    pointer-events: none;
}

/* Animation for caster AOE */
@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes melee-hit {
    0% {
        transform: scale(0.3);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.6;
    }
    100% {
        transform: scale(0.8);
        opacity: 0;
    }
}
@keyframes melee-hit {
    0% {
        transform: scale(0.3);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.6;
    }
    100% {
        transform: scale(0.8);
        opacity: 0;
    }
}
/* New shop grid layout */
.shops-container {
    display: flex;
    gap: 20px;
    justify-content: space-between;
}

.shop-section {
    flex: 1;
}

.shop-section h3 {
    margin-bottom: 8px;
    color: #3498db;
}

.units-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.unit-section {
    display: flex;
    flex-direction: row;
    gap: 6px;
    align-items: stretch;
}

.upgrade-btn {
    padding: 4px 8px;
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    border: 2px solid #27ae60;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 1px;
    align-items: center;
    font-size: 11px;
    width: 80px;
    min-height: 50px;
}

.upgrade-btn div {
    font-weight: bold;
    font-size: 11px;
    word-wrap: break-word;
}

.upgrade-btn small {
    font-size: 9px;
    opacity: 0.9;
    word-wrap: break-word;
}

.upgrade-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    border-color: #1abc9c;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(46, 204, 113, 0.4);
}

.ai-readonly {
    cursor: default;
    pointer-events: none;
}

.strategy-name {
    color: #f39c12;
    font-weight: bold;
    margin-top: 8px;
    font-size: 15px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 8px;
    border-radius: 4px;
    border: 2px solid rgba(243, 156, 18, 0.5);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    box-shadow: 0 0 8px rgba(243, 156, 18, 0.3);
}

/* Cursor preview for unit placement */
.cursor-preview {
    pointer-events: none !important;
    opacity: 0.6 !important;
    z-index: 9999;
}

/* Failed placement indicator */
.placement-failed {
    position: absolute;
    color: #e74c3c;
    font-size: 30px;
    font-weight: bold;
    pointer-events: none;
    z-index: 10000;
    animation: failedPlacement 0.5s ease-out;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

@keyframes failedPlacement {
    0% {
        opacity: 1;
        transform: scale(0.5);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
    100% {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* ── Mobile / phone layout ── */
@media (max-width: 600px) {
    body {
        padding: 5px;
    }

    #ui-top {
        max-width: 100%;
    }

    #game-board {
        gap: 4px;
        max-width: 100%;
        margin-bottom: 6px;
    }

    /* Player and AI build zones: narrow fixed width */
    .zone-container:nth-child(1),
    .zone-container:nth-child(3) {
        width: 70px;
        flex-shrink: 0;
    }

    /* Battle zone: fill remaining space */
    .zone-container:nth-child(2) {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    /* Shorter zones */
    .zone {
        height: 200px;
        padding: 4px;
    }

    .zone h4 {
        font-size: 10px;
        padding: 2px 4px;
        margin-bottom: 4px;
    }

    /* Compact health / gold bars */
    .zone-health,
    .zone-gold {
        font-size: 9px;
        padding: 2px 4px;
        min-height: 22px;
        height: 22px;
    }

    .lives-number,
    .gold-number {
        font-size: 11px;
        min-width: 30px;
    }

    .economy-btn {
        font-size: 8px !important;
        padding: 2px 3px !important;
    }

    /* Compact round/timer info bar */
    .battle-info {
        gap: 6px;
        padding: 4px 6px;
        height: 50px;
    }

    .round-display,
    .timer-display {
        font-size: 12px;
    }

    /* Smaller buy buttons */
    .buy-btn {
        width: 72px;
        min-height: 55px;
        padding: 4px 6px;
    }

    .buy-btn .unit-name {
        font-size: 11px;
    }

    .buy-btn .unit-stats {
        font-size: 7px;
    }

    /* Smaller upgrade buttons */
    .upgrade-btn {
        width: 52px;
        min-height: 48px;
        padding: 3px 4px;
        font-size: 9px;
    }

    .upgrade-btn div {
        font-size: 9px;
    }

    .upgrade-btn small {
        font-size: 7px;
    }

    /* Stack the two shops vertically */
    .shops-container {
        flex-direction: column;
        gap: 10px;
    }

    .units-grid {
        gap: 6px;
    }
}
