@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', sans-serif;
    overflow: hidden;
}

.game-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    aspect-ratio: 14/7.5;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    display: none;
    width: 100%;
    height: 100%;
}

/* ========== MAIN MENU ========== */
/* ========== MAIN MENU ========== */
.main-menu {
    position: absolute;
    inset: 0;
    /* 4-ERA SPLIT BACKGROUND */
    background: linear-gradient(110deg,
            #5d4037 0%,
            /* Cave */
            #5d4037 25%,
            #1e3c72 25%,
            /* Medieval */
            #1e3c72 50%,
            #2c3e50 50%,
            /* Modern */
            #2c3e50 75%,
            #0f0c29 75%,
            /* Future */
            #0f0c29 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    z-index: 100;
    transition: opacity 0.5s ease-in-out, transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8);
}

.main-menu::after {
    /* Texture Overlay */
    content: '';
    position: absolute;
    inset: 0;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMDUiLz4KPC9zdmc+');
    opacity: 0.3;
    pointer-events: none;
}

.game-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 56px;
    color: #ffd700;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.2;
    text-shadow:
        4px 4px 0 #3e2723,
        -2px -2px 0 #000,
        0 0 20px rgba(255, 215, 0, 0.6),
        0 0 50px rgba(255, 69, 0, 0.4);
    animation: titleFloat 3s ease-in-out infinite;
    z-index: 2;
}

@keyframes titleFloat {

    0%,
    100% {
        transform: translateY(0) rotate(-1deg);
    }

    50% {
        transform: translateY(-10px) rotate(1deg);
    }
}

.subtitle {
    color: #f0f0f0;
    font-size: 18px;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 4px;
    text-shadow: 2px 2px 4px #000;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 15px;
    border-radius: 4px;
    z-index: 2;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
    z-index: 2;
}

.menu-btn {
    padding: 18px 60px;
    font-size: 18px;
    font-family: 'Press Start 2P', cursive;
    color: #fff;
    background: linear-gradient(180deg, #4b6cb7 0%, #182848 100%);
    border: 3px solid #85a3e0;
    border-radius: 0;
    cursor: pointer;
    text-shadow: 2px 2px 0 #000;
    box-shadow:
        0 6px 0 #0d1629,
        0 10px 10px rgba(0, 0, 0, 0.5);
    transition: all 0.1s;
    position: relative;
    overflow: hidden;
}

.menu-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 8px 0 #0d1629,
        0 12px 15px rgba(0, 0, 0, 0.6);
    filter: brightness(1.2);
}

.menu-btn:active {
    transform: translateY(4px);
    box-shadow:
        0 2px 0 #0d1629,
        0 4px 5px rgba(0, 0, 0, 0.4);
}




.play-btn {
    background: linear-gradient(180deg, #4CAF50, #2E7D32);
    border-color: #1B5E20;
    color: white;
}

.continue-btn {
    background: linear-gradient(180deg, #2196F3, #1565C0);
    border-color: #0D47A1;
    color: white;
}

.upgrades-btn {
    background: linear-gradient(180deg, #FF9800, #E65100);
    border-color: #BF360C;
    color: white;
}

.back-btn {
    background: linear-gradient(180deg, #607D8B, #455A64);
    border-color: #37474F;
    color: white;
    margin-top: 20px;
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.menu-btn:active {
    transform: translateY(0);
}

.menu-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.difficulty-select {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.difficulty-select span {
    color: #c0a080;
    font-weight: bold;
}

.diff-btn {
    padding: 8px 16px;
    border: 2px solid #555;
    background: #333;
    color: #888;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.diff-btn:hover {
    border-color: #888;
    color: #fff;
}

.diff-btn.active {
    background: linear-gradient(180deg, #ff9800, #e65100);
    border-color: #ff9800;
    color: #fff;
}

.stats-preview {
    display: flex;
    gap: 40px;
    color: #a0a0a0;
    font-size: 14px;
    margin-top: 30px;
}

.stats-preview b {
    color: #ffd700;
}

/* ========== UPGRADES MENU ========== */
.upgrades-menu {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #1a2a1a 0%, #0a150a 100%);
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    z-index: 100;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.upgrades-menu.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.upgrades-menu h2 {
    color: #ffd700;
    font-size: 32px;
    margin-bottom: 30px;
}

.upgrades-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 900px;
}

.upgrade-card {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    transition: all 0.2s;
}

.upgrade-card:hover {
    border-color: #ffd700;
    transform: translateY(-5px);
}

.upgrade-card .icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.upgrade-card .name {
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 5px;
}

.upgrade-card .desc {
    color: #888;
    font-size: 12px;
    margin-bottom: 10px;
}

.upgrade-card .level {
    color: #4CAF50;
    font-size: 14px;
    margin-bottom: 10px;
}

.upgrade-card button {
    background: linear-gradient(180deg, #ffd700, #ff9800);
    border: none;
    padding: 10px 25px;
    border-radius: 20px;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.upgrade-card button:hover {
    transform: scale(1.05);
}

.upgrade-card button:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
}

/* ========== GAME UI ========== */
.game-ui {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.game-ui>* {
    pointer-events: auto;
}

/* ========== TOP BAR LAYOUT ========== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent);
    pointer-events: none;
    /* Let clicks pass through empty areas */
}

.top-bar>* {
    pointer-events: auto;
    /* Re-enable pointer events for children */
}

.top-left,
.top-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 250px;
    /* Fixed width for alignment */
}

.top-left {
    align-items: flex-start;
}

.top-right {
    align-items: flex-end;
}

.top-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.center-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.age-display {
    display: flex;
    align-items: center;
    gap: 15px;
}

.wave-display {
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 15px;
    border-radius: 20px;
    color: #ddd;
    border: 1px solid #555;
    font-size: 14px;
    font-weight: bold;
}

.resource-panel {
    background: rgba(0, 0, 0, 0.7);
    padding: 12px 25px;
    border-radius: 30px;
    border: 2px solid #ffd700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.resource-panel #currencyIcon {
    font-size: 28px;
}

.resource-panel #currencyAmount {
    color: #ffd700;
    font-size: 24px;
    font-weight: bold;
    min-width: 80px;
}

.resource-panel .income {
    color: #4CAF50;
    font-size: 14px;
}

#ageName {
    background: linear-gradient(135deg, #3E2723, #000000);
    padding: 10px 30px;
    border-radius: 25px;
    color: #FFD700;
    /* Gold text */
    font-weight: 800;
    /* Extra bold */
    font-size: 20px;
    border: 2px solid #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#evolveBtn {
    background: linear-gradient(180deg, #F57F17, #E65100);
    border: 3px solid #BF360C;
    padding: 12px 30px;
    border-radius: 25px;
    color: white;
    font-weight: 900;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 5px 15px rgba(255, 69, 0, 0.4);
    min-width: 150px;
}

#evolveBtn:hover:not(:disabled) {
    transform: scale(1.1);
    background: linear-gradient(180deg, #FF9800, #F57F17);
    box-shadow: 0 0 20px rgba(255, 140, 0, 0.6);
}

#evolveBtn:disabled {
    background: #444;
    border-color: #333;
    color: #888;
    cursor: not-allowed;
    box-shadow: none;
}

.health-bars {
    display: flex;
    gap: 20px;
}

.hp-bar {
    width: 140px;
    text-align: center;
}

.hp-bar span {
    display: block;
    color: #fff;
    font-size: 12px;
    margin-bottom: 5px;
}

.hp-bar .hp-fill {
    height: 18px;
    border-radius: 10px;
    transition: width 0.3s;
}

.hp-bar.player .hp-fill {
    background: linear-gradient(90deg, #2196F3, #4CAF50);
    width: 100%;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

.hp-bar.enemy .hp-fill {
    background: linear-gradient(90deg, #f44336, #ff5722);
    width: 100%;
    box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
}

.pause-btn {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #fff;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.pause-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 15px 20px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.8), transparent);
}

.units-panel {
    display: flex;
    gap: 10px;
}

/* ========== ENHANCED UNIT BUTTONS ========== */
.unit-btn {
    width: 80px;
    height: 110px;
    padding: 4px;
    border-radius: 8px;
    border: 2px solid #555;
    background: linear-gradient(180deg, #2a2a4a, #1a1a2a);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    transition: all 0.15s;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.unit-btn:hover {
    transform: translateY(-4px);
    border-color: #ffd700;
    box-shadow: 0 8px 15px rgba(255, 215, 0, 0.2);
    background: linear-gradient(180deg, #3a3a5a, #2a2a3a);
}

.unit-btn:active {
    transform: translateY(-1px);
}

/* Internal Layout */
.unit-btn .hotkey-bdg {
    position: absolute;
    top: 2px;
    left: 2px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: bold;
    z-index: 2;
    border: 1px solid #444;
}

.unit-btn .btn-top {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    padding-right: 2px;
    margin-bottom: 2px;
}

.unit-btn .cost {
    color: #ffd700;
    font-size: 11px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    padding: 1px 4px;
    border-radius: 4px;
}

.unit-btn .canvas-container {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 2px;
}

.unit-btn canvas {
    width: 50px;
    height: 50px;
    /* Scaled in CSS for crispness */
    object-fit: contain;
}

.unit-btn .unit-name {
    color: #ddd;
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
    margin-bottom: 2px;
    font-weight: 600;
}

.unit-btn .stats-mini {
    display: flex;
    justify-content: space-evenly;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    padding: 2px 0;
}

.unit-btn .stats-mini span {
    font-size: 9px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 1px;
}

.special-btn {
    background: linear-gradient(180deg, #ff6b00, #cc5500);
    border: 3px solid #aa4400;
    padding: 18px 35px;
    border-radius: 30px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.special-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 107, 0, 0.5);
}

.special-btn:disabled {
    background: #444;
    border-color: #333;
    cursor: not-allowed;
}

/* ========== GAME OVER ========== */
.game-over {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 200;
}

.game-over h1 {
    font-size: 48px;
    text-shadow: 0 0 30px currentColor;
}

.game-over p {
    color: #888;
    font-size: 18px;
}

.game-over-btns {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}

/* ========== PAUSE MENU ========== */
.pause-menu {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 150;
}

.pause-menu h2 {
    color: #fff;
    font-size: 36px;
    margin-bottom: 20px;
}

/* ========== ACTION BUTTONS ========== */
.action-buttons {
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

.turret-btn {
    background: linear-gradient(180deg, #9c27b0, #6a1b9a);
    border: 3px solid #4a148c;
    padding: 15px 25px;
    border-radius: 15px;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.turret-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(156, 39, 176, 0.5);
}

.turret-btn:disabled {
    background: #444;
    border-color: #333;
    cursor: not-allowed;
}

/* ========== BOSS WARNING ========== */
.boss-warning {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(180deg, rgba(139, 0, 0, 0.95), rgba(80, 0, 0, 0.95));
    padding: 20px 60px;
    border-radius: 10px;
    border: 4px solid #ff0000;
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 0 20px #ff0000;
    display: none;
    z-index: 50;
    animation: bossFlash 0.3s ease-in-out infinite alternate;
}

@keyframes bossFlash {
    0% {
        box-shadow: 0 0 30px #ff0000;
    }

    100% {
        box-shadow: 0 0 60px #ff4444, 0 0 100px #ff0000;
    }
}

.boss-warning.show {
    display: block;
}

/* ========== WAVE COUNTER ========== */
.wave-counter {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 25px;
    border-radius: 20px;
    color: #fff;
    font-size: 14px;
    border: 2px solid #666;
}

.wave-counter span {
    color: #ffd700;
    font-weight: bold;
}

/* ========== CONTROL BUTTONS ========== */
.control-btn {
    background: linear-gradient(180deg, #445, #223);
    border: 2px solid #667;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 14px;
}

.control-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #556, #334);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border-color: #889;
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #333;
}

.settings-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 20px;
}

.control-btn.cooldown {
    filter: grayscale(100%);
    opacity: 0.7;
    cursor: wait;
}

/* ========== UNIT TOOLTIP ========== */
.unit-tooltip {
    position: absolute;
    bottom: 110px;
    /* Position above the bottom bar */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #ffd700;
    border-radius: 8px;
    padding: 12px 20px;
    color: white;
    text-align: center;
    pointer-events: none;
    /* Ignore mouse events */
    z-index: 1000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.9);
    min-width: 250px;
    opacity: 0;
    transition: opacity 0.2s;
}

.unit-tooltip.show {
    opacity: 1;
}

.unit-tooltip h3 {
    margin: 0 0 8px 0;
    color: #ffd700;
    font-size: 18px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 5px;
}

.unit-tooltip p {
    margin: 5px 0;
    font-size: 14px;
    color: #ddd;
    font-style: italic;
}

.unit-tooltip .stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-weight: bold;
    color: #fff;
    font-size: 14px;
}

.unit-tooltip .stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.unit-tooltip .stat-item span {
    color: #ccc;
}

/* ========== MOBILE RESPONSIVENESS ========== */
@media (max-width: 1024px) {
    .game-container {
        aspect-ratio: auto;
        height: 100vh;
    }

    .game-title {
        font-size: 32px;
    }

    .subtitle {
        font-size: 11px;
    }

    /* Horizontal Layout for top bar if needed */
    .menu-btn {
        padding: 12px 30px;
        font-size: 14px;
    }

    .unit-btn {
        width: 55px;
        height: 85px;
    }

    .unit-btn canvas {
        width: 40px;
        height: 40px;
    }

    .unit-btn .cost {
        font-size: 9px;
    }

    .unit-btn .unit-name {
        font-size: 8px;
    }

    .unit-btn .hotkey-bdg {
        display: none;
    }

    /* Hide hotkeys on mobile */

    .top-bar {
        padding: 5px;
    }

    .resource-panel {
        padding: 5px 10px;
        gap: 5px;
    }

    .resource-panel #currencyIcon {
        font-size: 20px;
    }

    .resource-panel #currencyAmount {
        font-size: 16px;
        min-width: 40px;
    }

    .resource-panel .income {
        font-size: 10px;
    }

    .age-display {
        gap: 10px;
    }

    #ageName {
        font-size: 14px;
        padding: 5px 15px;
    }

    .wave-display {
        font-size: 11px;
        padding: 4px 10px;
    }

    .center-buttons {
        gap: 4px;
    }

    .control-btn {
        font-size: 10px;
        padding: 5px;
        width: auto;
    }
}

@media (max-width: 768px) {
    .game-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        max-width: none;
    }

    .main-menu {
        padding: 20px;
        text-align: center;
    }

    .game-title {
        font-size: 24px;
        line-height: 1.3;
        margin-bottom: 20px;
    }

    .menu-buttons {
        width: 100%;
        max-width: 300px;
    }

    .menu-btn {
        width: 100%;
        padding: 15px;
    }

    /* Reposition Update Log for Mobile */
    #updateLogContainer {
        position: relative;
        left: auto;
        top: auto;
        transform: none;
        width: 100%;
        max-width: 300px;
        height: 150px;
        order: 2;
        /* Move it below buttons if flex */
        margin-top: 20px;
    }

    /* Game UI Mobile Adjustments */
    .top-bar {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }

    .top-left,
    .top-right {
        flex-direction: row;
        width: auto;
        align-items: center;
        gap: 10px;
    }

    .top-center {
        width: 100%;
        order: -1;
        margin-bottom: 5px;
    }

    .units-panel {
        gap: 4px;
        overflow-x: auto;
        padding-bottom: 5px;
        max-width: 100vw;
    }

    #unitTooltip {
        bottom: 120px;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
    }
}