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

body {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a2e 100%);
    color: #00ff88;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    user-select: none;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

/* TOP BAR */
#topBar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(26, 26, 46, 0.98);
    border-bottom: 2px solid #00ff88;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10000;
    box-shadow: 0 2px 20px rgba(0, 255, 136, 0.4);
}

.top-bar-title {
    font-size: 18px;
    font-weight: bold;
    color: #ff6600;
    text-shadow: 0 0 10px #ff6600;
}

.zoom-info {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #00ff88;
    color: #00ff88;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
}

/* BUILDER UI */
#builderUI {
    position: fixed;
    top: 60px;
    left: 10px;
    background: rgba(26, 26, 46, 0.95);
    border: 2px solid #00ff88;
    border-radius: 10px;
    padding: 15px;
    display: none;
    z-index: 1000;
    min-width: 280px;
    max-width: 320px;
}

.builder-section {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(0, 255, 136, 0.3);
}

.builder-section input[type="checkbox"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: #00ff88;
    vertical-align: middle;
}

.builder-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.builder-title {
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.builder-btn {
    width: 100%;
    background: linear-gradient(145deg, rgba(42, 90, 90, 0.8), rgba(26, 70, 70, 0.8));
    border: 1px solid #00ff88;
    color: #00ff88;
    padding: 8px;
    margin: 3px 0;
    cursor: pointer;
    font-size: 12px;
    border-radius: 5px;
    transition: all 0.2s ease;
}

.builder-btn:hover:not(:disabled) {
    background: linear-gradient(145deg, rgba(60, 110, 110, 0.9), rgba(40, 90, 90, 0.9));
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
    transform: translateY(-1px);
}

.builder-btn:disabled {
    background: rgba(30, 30, 30, 0.8);
    border-color: #555;
    color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.builder-btn.active {
    background: linear-gradient(145deg, #00ff88, #00cc70);
    color: #0a0a1a;
    font-weight: 700;
}

.builder-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #00ff88;
    color: #00ff88;
    padding: 6px 10px;
    margin: 5px 0;
    font-size: 12px;
    border-radius: 4px;
}

.path-list {
    max-height: 150px;
    overflow-y: auto;
    margin: 5px 0;
}

.path-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px;
    background: rgba(0, 0, 0, 0.3);
    margin: 2px 0;
    border-radius: 4px;
}

.path-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 8px;
}

.path-info {
    flex: 1;
    display: flex;
    align-items: center;
    font-size: 11px;
}

.path-delete {
    background: #ff4444;
    border: none;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
}

.path-delete:hover {
    background: #ff6666;
}

.map-select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #00ff88;
    color: #00ff88;
    padding: 6px;
    font-size: 12px;
    border-radius: 4px;
}

.builder-stats {
    font-size: 12px;
    color: #aaa;
    margin: 8px 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
}

#mainContainer {
    display: flex;
    width: 100vw;
    height: calc(100vh - 140px);
    /* Adjusted for two-row menu height */
    margin-top: 140px;
    /* Adjusted for two-row menu height */
}

#leftSection {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#sidebar {
    width: 220px;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
    border-left: 2px solid #00ff88;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
    z-index: 100;
    height: 100%;
}

#topMenu {
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid #00ff88;
    padding: 15px 20px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    box-shadow: 0 2px 20px rgba(0, 255, 136, 0.3);
    min-height: 120px;
    position: relative;
    z-index: 1000;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #topBar {
        padding: 8px 12px;
    }

    .top-bar-title {
        font-size: 14px;
    }

    .zoom-info {
        font-size: 10px;
    }

    #builderUI {
        left: 5px;
        right: 5px;
        min-width: auto;
        padding: 10px;
    }

    #mainContainer {
        flex-direction: column;
    }

    #leftSection {
        width: 100vw;
        height: 60vh;
    }

    #sidebar {
        width: 100vw;
        height: 40vh;
        border-left: none;
        border-top: 2px solid #00ff88;
        overflow-x: auto;
        overflow-y: scroll;
    }

    #topMenu {
        padding: 15px 12px;
        gap: 10px;
        min-height: 110px;
    }
}

.menu-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

/* First section (Bank, Lives, Interest) - takes half width */
.menu-section:nth-child(1) {
    flex: 0 1 48%;
    justify-content: flex-start;
}

/* Second section (Control buttons) - takes full width on second row */
.menu-section:nth-child(2) {
    flex: 1 1 100%;
    order: 3;
}

/* Third section (Wave, Score, Enemies, Incoming) - takes half width */
.menu-section:nth-child(3) {
    flex: 0 1 48%;
    justify-content: flex-end;
}

.incoming-wave-box {
    background: linear-gradient(145deg, rgba(26, 26, 46, 0.95), rgba(16, 16, 32, 0.95));
    border: 1px solid rgba(255, 100, 0, 0.6);
    border-radius: 12px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 20px rgba(255, 100, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.incoming-wave-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 100, 0, 0.1), transparent);
    transition: left 0.5s ease;
}

.incoming-wave-box:hover::before {
    left: 100%;
}

.wave-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #ff6600;
    flex-shrink: 0;
}

.wave-info {
    display: flex;
    flex-direction: column;
    font-size: 10px;
    line-height: 1.2;
}

.wave-name {
    font-weight: bold;
    color: #ffffff;
    font-size: 11px;
}

.wave-stats {
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.wave-hp {
    color: #ff4444;
}

.wave-reward {
    color: #ffff00;
}

@media (max-width: 768px) {
    .incoming-wave-box {
        padding: 6px 10px;
        gap: 8px;
    }

    .wave-icon {
        width: 20px;
        height: 20px;
    }

    .wave-info {
        font-size: 9px;
    }

    .wave-name {
        font-size: 10px;
    }
}

.game-title {
    color: #ff6600;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 0 0 10px #ff6600;
}

@media (max-width: 768px) {
    .game-title {
        font-size: 14px;
    }
}

.stat-box {
    background: linear-gradient(145deg, rgba(26, 26, 46, 0.95), rgba(16, 16, 32, 0.95));
    border: 1px solid rgba(0, 255, 136, 0.4);
    border-radius: 12px;
    padding: 10px 12px;
    margin: 0 4px;
    min-width: 80px;
    max-width: 250px;
    /* Increased for very long numbers */
    text-align: center;
    font-size: 11px;
    backdrop-filter: blur(10px);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    flex: 0 1 auto;
    /* Allow shrinking/growing */
}

/* Special handling for the money box */
.stat-box:first-child {
    flex: 1 1 auto;
    /* Allow money box to grow more */
    max-width: 300px;
}

.stat-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 255, 136, 0.1), transparent);
    transition: left 0.5s ease;
}

.stat-box:hover::before {
    left: 100%;
}

.stat-box:hover {
    border-color: rgba(0, 255, 136, 0.6);
    box-shadow:
        0 6px 20px rgba(0, 255, 136, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.stat-label {
    display: block;
    font-size: 9px;
    font-weight: 600;
    color: rgba(0, 255, 136, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.stat-value.money {
    color: #00ff88;
    text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
    font-size: 12px;
    word-break: break-all;
    line-height: 1.2;
}

.stat-value.lives {
    color: #ff4466;
    text-shadow: 0 0 8px rgba(255, 68, 102, 0.5);
}

.stat-value.score {
    color: #ffaa00;
    text-shadow: 0 0 8px rgba(255, 170, 0, 0.5);
}

.stat-value.wave {
    color: #4488ff;
    text-shadow: 0 0 8px rgba(68, 136, 255, 0.5);
}

.stat-value.enemies {
    color: #ff6600;
    text-shadow: 0 0 8px rgba(255, 102, 0, 0.5);
}

.stat-value.interest {
    color: #88ff44;
    text-shadow: 0 0 8px rgba(136, 255, 68, 0.5);
}

@media (max-width: 768px) {
    .stat-box {
        min-width: 60px;
        padding: 6px 10px;
        margin: 0 2px;
        border-radius: 10px;
    }

    .stat-label {
        font-size: 8px;
        margin-bottom: 1px;
    }

    .stat-value {
        font-size: 12px;
    }
}

.control-btn {
    background: linear-gradient(145deg, rgba(42, 90, 90, 0.9), rgba(26, 70, 70, 0.9));
    border: 1px solid rgba(0, 255, 136, 0.5);
    color: #00ff88;
    padding: 10px 18px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.3s ease;
    white-space: nowrap;
    backdrop-filter: blur(10px);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 255, 136, 0.2), transparent);
    transition: left 0.5s ease;
}

.control-btn:hover::before {
    left: 100%;
}

@media (max-width: 768px) {
    .control-btn {
        padding: 6px 12px;
        font-size: 11px;
    }
}

.control-btn:hover:not(:disabled) {
    background: linear-gradient(145deg, rgba(60, 110, 110, 0.95), rgba(40, 90, 90, 0.95));
    border-color: rgba(0, 255, 136, 0.8);
    box-shadow:
        0 6px 20px rgba(0, 255, 136, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}

.control-btn:disabled {
    background: linear-gradient(145deg, rgba(30, 30, 30, 0.8), rgba(20, 20, 20, 0.8));
    border-color: rgba(85, 85, 85, 0.5);
    color: #555;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.control-btn.active {
    background: linear-gradient(145deg, #00ff88, #00cc70);
    color: #0a0a1a;
    font-weight: 700;
    box-shadow:
        0 6px 20px rgba(0, 255, 136, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

#gameCanvas {
    background: linear-gradient(45deg, #0a0a1a 0%, #0f0f2a 50%, #0a0a1a 100%);
    flex: 1;
    cursor: crosshair;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    #gameCanvas {
        height: 100%;
        width: 100vw;
    }
}

.section-header {
    background: linear-gradient(90deg, #2a5a5a 0%, #3a6a6a 50%, #2a5a5a 100%);
    padding: 8px 12px;
    text-align: center;
    font-weight: bold;
    font-size: 12px;
    border-bottom: 1px solid #00ff88;
    color: #ffffff;
    position: sticky;
    top: 0;
    z-index: 10;
}

@media (max-width: 768px) {
    .section-header {
        font-size: 11px;
        padding: 6px 10px;
    }
}

.tower-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    padding: 8px;
    background: rgba(16, 16, 32, 0.8);
}

@media (max-width: 768px) {
    .tower-grid {
        gap: 2px;
        padding: 6px;
        grid-template-columns: repeat(4, 1fr);
    }
}

.tower-column {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

@media (max-width: 768px) {
    .tower-column {
        gap: 2px;
    }
}

.tower-slot {
    width: 45px;
    height: 45px;
    border: 1px solid;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.2s ease;
    border-radius: 4px;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    .tower-slot {
        width: 40px;
        height: 40px;
    }
}

.tower-slot:hover,
.tower-slot:active {
    transform: scale(1.05);
    box-shadow: 0 0 15px currentColor;
}

@media (max-width: 768px) {

    .tower-slot:hover,
    .tower-slot:active {
        transform: scale(1.1);
    }
}

.tower-slot.selected {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px currentColor;
}

.tower-slot[style*="opacity: 0.5"] {
    cursor: not-allowed;
}

.tower-slot[style*="opacity: 0.5"]:hover {
    transform: none;
    box-shadow: none;
}

.tower-icon {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 2px;
}

@media (max-width: 768px) {
    .tower-icon {
        font-size: 14px;
    }
}

.tower-price {
    font-size: 8px;
    color: #ffff00;
    font-weight: bold;
}

@media (max-width: 768px) {
    .tower-price {
        font-size: 7px;
    }
}

.tower-detail-section {
    padding: 8px;
    background: rgba(16, 16, 32, 0.8);
    border-top: 1px solid #00ff88;
    font-size: 11px;
}

@media (max-width: 768px) {
    .tower-detail-section {
        padding: 6px;
        font-size: 10px;
    }
}

.tower-detail-content {
    padding: 4px;
}

.tower-detail-header {
    color: #ffffff;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
    text-align: center;
    padding-bottom: 8px;
    border-bottom: 1px solid #00ff88;
}

@media (max-width: 768px) {
    .tower-detail-header {
        font-size: 12px;
        margin-bottom: 6px;
        padding-bottom: 6px;
    }
}

/* NEW SIMPLIFIED TOWER STATS LAYOUT */
.tower-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 4px;
}

.stat-item-label {
    font-size: 9px;
    color: #00ff88;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-item-value {
    font-size: 13px;
    color: #ffffff;
    font-weight: bold;
    margin-top: 2px;
}

.tower-special-stats {
    margin-top: 8px;
    padding: 6px;
    background: rgba(0, 255, 136, 0.1);
    border-radius: 4px;
    text-align: center;
    font-size: 10px;
}

@media (max-width: 768px) {
    .tower-stats-grid {
        gap: 6px;
        padding: 6px;
    }

    .stat-item-label {
        font-size: 8px;
    }

    .stat-item-value {
        font-size: 11px;
    }

    .tower-special-stats {
        font-size: 9px;
    }
}

.upgrade-options {
    margin-top: 12px;
}

.upgrade-btn {
    width: 100%;
    background: rgba(42, 90, 90, 0.8);
    border: 1px solid #00ff88;
    color: #00ff88;
    padding: 8px;
    margin: 3px 0;
    cursor: pointer;
    font-size: 11px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

@media (max-width: 768px) {
    .upgrade-btn {
        padding: 6px;
        font-size: 10px;
        margin: 2px 0;
    }
}

.upgrade-btn:hover:not(:disabled) {
    background: rgba(60, 110, 110, 0.9);
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
}

.upgrade-btn.affordable {
    border-color: #ffff00;
    color: #ffff00;
}

.upgrade-btn:disabled {
    background: rgba(30, 30, 30, 0.8);
    border-color: #555;
    color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.mode-indicator {
    position: fixed;
    top: 150px;
    /* Adjusted for two-row menu height */
    left: 20px;
    background: rgba(26, 26, 46, 0.9);
    border: 1px solid #00ff88;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 4px;
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: none;
}

@media (max-width: 768px) {
    .mode-indicator {
        top: 170px;
        left: 10px;
        right: 10px;
        font-size: 11px;
        padding: 6px 10px;
        text-align: center;
    }
}

.feature-note {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(26, 26, 46, 0.8);
    border: 1px solid #00ff88;
    padding: 6px 10px;
    font-size: 10px;
    border-radius: 4px;
    color: #88ff88;
    opacity: 0.7;
    max-width: 300px;
    z-index: 1000;
}

@media (max-width: 768px) {
    #topMenu {
        padding: 12px;
        gap: 8px;
        min-height: 110px;
        /* Two rows on mobile */
    }

    .menu-section {
        gap: 8px;
    }

    /* On mobile, first and third sections can be narrower */
    .menu-section:nth-child(1),
    .menu-section:nth-child(3) {
        flex: 0 1 45%;
    }

    .mode-indicator {
        top: 120px;
        left: 10px;
        right: 10px;
        font-size: 11px;
        padding: 6px 10px;
        text-align: center;
    }
}

/* Boss Bonus Modal */
.boss-bonus-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.boss-bonus-content {
    background: linear-gradient(145deg, #1a1a2e, #0a0a1a);
    border: 2px solid #00ff88;
    border-radius: 15px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 255, 136, 0.3);
}

.boss-bonus-title {
    color: #ffffff;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #ffffff;
}

.bonus-options {
    display: grid;
    gap: 15px;
    margin: 20px 0;
}

.bonus-option {
    background: linear-gradient(145deg, rgba(42, 90, 90, 0.8), rgba(26, 70, 70, 0.8));
    border: 2px solid #00ff88;
    color: #00ff88;
    padding: 15px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 600;
}

.bonus-option:hover {
    background: linear-gradient(145deg, rgba(60, 110, 110, 0.9), rgba(40, 90, 90, 0.9));
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 255, 136, 0.4);
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .tower-slot:hover {
        transform: none;
        box-shadow: none;
    }

    .tower-slot:active {
        transform: scale(1.1);
        box-shadow: 0 0 20px currentColor;
    }

    .control-btn:hover {
        background: #2a5a5a;
        box-shadow: none;
    }

    .control-btn:active {
        background: #3a6a6a;
        box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
    }
}

/* Scrollbar styling */
#sidebar::-webkit-scrollbar,
.path-list::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track,
.path-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

#sidebar::-webkit-scrollbar-thumb,
.path-list::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 136, 0.5);
    border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover,
.path-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 136, 0.7);
}