@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body {
    background-color: #0d0d1a;
    /* Darker background */
    font-family: 'Rajdhani', sans-serif;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    touch-action: none;
    /* Block all default touch actions like scroll/zoom */
}

#game-container {
    position: relative;
    width: 100vw;
    height: 56.25vw;
    max-height: 100vh;
    max-width: 177.78vh;
    background: #0d0d1a;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    z-index: 0;
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    background: transparent;
}

#menu-bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: rgba(0, 255, 0, 0.2) !important;
    /* DEBUG GREEN */
    pointer-events: none;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

#orientation-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    z-index: 1000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

@media (orientation: portrait) {
    #orientation-warning {
        display: flex;
    }
}

.warning-content span {
    font-size: 80px;
    display: block;
    animation: rotate 2s infinite ease-in-out;
}

@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.warning-content p {
    font-size: 24px;
    margin-top: 20px;
    color: #4ecca3;
    font-weight: bold;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas */
    z-index: 20;
}

#top-bar {
    display: flex;
    gap: 15px;
    padding: 15px 25px;
    background: transparent;
    pointer-events: none;
}

.stat-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 52, 96, 0.4);
    backdrop-filter: blur(15px);
    padding: 8px 18px;
    border-radius: 12px;
    border: 1px solid rgba(0, 234, 255, 0.2);
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-box:hover {
    border-color: #00eaff;
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(0, 234, 255, 0.2);
}

.stat-box.clickable {
    pointer-events: auto;
    cursor: pointer;
}

#restart-btn {
    border-color: rgba(233, 69, 96, 0.4);
    color: #e94560;
}

#restart-btn:hover {
    border-color: #e94560;
    box-shadow: 0 0 15px rgba(233, 69, 96, 0.4);
}

.icon {
    font-size: 18px;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

#lives {
    color: #ff2e63;
}

#money {
    color: #ffd700;
}

#wave {
    color: #4ecca3;
}

#build-menu {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: rgba(13, 13, 26, 0.5);
    backdrop-filter: blur(20px);
    padding: 12px;
    border-radius: 20px;
    pointer-events: auto;
    border: 1px solid rgba(78, 204, 163, 0.2);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.tower-card {
    width: 60px;
    height: 85px;
    background: rgba(15, 52, 96, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.tower-card:hover {
    transform: translateY(-3px);
    border-color: #e94560;
    box-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

.tower-card:active {
    transform: translateY(-1px);
}

.tower-preview-canvas {
    width: 32px;
    height: 32px;
    margin-bottom: 3px;
}

.tower-cost {
    font-size: 11px;
    color: #ffd700;
    font-weight: bold;
}

.tower-name {
    font-size: 9px;
    color: #ccc;
}

#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 100;
}

#game-over-screen.hidden {
    display: none;
}

h1 {
    font-size: 72px;
    color: #e94560;
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.8);
    margin-bottom: 30px;
}

#main-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* Reveal background canvas */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    pointer-events: auto;
    overflow: hidden;
}

#menu-bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.menu-content {
    position: relative;
    z-index: 210;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 60px 80px;
    background: rgba(10, 25, 47, 0.85);
    /* Premium Dark Blue */
    backdrop-filter: blur(20px);
    border: 2px solid rgba(0, 234, 255, 0.4);
    border-radius: 40px;
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.9),
        inset 0 0 30px rgba(0, 234, 255, 0.1);
    animation: menuAppear 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.menu-tag {
    font-size: 14px;
    letter-spacing: 4px;
    color: #4ecca3;
    margin-bottom: 20px;
    font-weight: bold;
    opacity: 0.8;
}

.glitch-text {
    font-size: 84px;
    margin: 0;
    color: #fff;
    text-shadow: 2px 2px #ff2e63, -2px -2px #00eaff;
    animation: glow 2s infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 0 0 10px #ff2e63, 0 0 20px #ff2e63;
    }

    to {
        text-shadow: 0 0 20px #00eaff, 0 0 30px #00eaff;
    }
}

.subtitle {
    font-size: 20px;
    color: #4ecca3;
    letter-spacing: 8px;
    margin-bottom: 40px;
    text-transform: uppercase;
}

.menu-actions {
    margin-bottom: 30px;
}

.main-btn {
    background: linear-gradient(135deg, #00eaff, #0077ff);
    border: none;
    padding: 15px 60px;
    font-size: 32px;
    border-radius: 50px;
    box-shadow: 0 0 30px rgba(0, 234, 255, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    color: #fff;
    font-weight: bold;
    letter-spacing: 2px;
    transition: all 0.3s ease;
}

.main-btn:hover {
    transform: scale(1.05);
    background: linear-gradient(135deg, #00d2ff, #0055ff);
    box-shadow: 0 0 45px rgba(0, 234, 255, 0.7);
}

.btn-icon {
    font-size: 24px;
}

.pulse {
    animation: pulse-animation 2s infinite;
}

/* Unified HUD Buttons */
.hud-btn {
    position: absolute;
    top: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    padding: 0;
    font-size: 24px;
    background: rgba(10, 25, 47, 0.95);
    backdrop-filter: blur(5px);
    border: 2px solid;
    cursor: pointer;
    z-index: 1000;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.hud-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.hud-btn:active {
    transform: scale(0.95);
}

#settings-btn {
    right: 20px;
    border-color: #00eaff !important;
    box-shadow: 0 0 10px rgba(0, 234, 255, 0.3);
}

#settings-btn:hover {
    background: rgba(0, 234, 255, 0.2);
    box-shadow: 0 0 20px rgba(0, 234, 255, 0.6);
    transform: rotate(90deg) scale(1.1);
}

#pause-btn {
    right: 90px;
    border-color: #4ecca3 !important;
    box-shadow: 0 0 10px rgba(78, 204, 163, 0.3);
}

#pause-btn:hover {
    background: rgba(78, 204, 163, 0.2);
    box-shadow: 0 0 20px rgba(78, 204, 163, 0.6);
}

#speed-btn {
    right: 160px;
    border-color: #e94560 !important;
    font-size: 20px;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(233, 69, 96, 0.3);
}

#speed-btn:hover {
    background: rgba(233, 69, 96, 0.2);
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.6);
}

/* Upgrade Menu */
#upgrade-menu {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 20, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 234, 255, 0.3);
    border-radius: 16px;
    padding: 15px;
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 2000;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6), 0 0 10px rgba(0, 234, 255, 0.1);
    animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.upgrade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    cursor: move;
    /* Indicates draggable */
    padding: 10px;
    /* Larger hit area for dragging */
    background: rgba(255, 255, 255, 0.05);
    /* Slight highlight */
    border-radius: 8px;
    margin: -10px -10px 10px -10px;
    /* Expand to edges */
}

#upgrade-name {
    color: #00eaff;
    font-weight: 800;
    font-size: 20px;
    text-shadow: 0 0 10px rgba(0, 234, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-badge {
    background: #ffcc00;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 12px;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.stat-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.stat-label {
    font-size: 10px;
    color: #888;
    font-weight: bold;
    letter-spacing: 1px;
}

.stat-bar-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #00eaff, #0076a3);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.stat-values {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-family: monospace;
}

#upg-dmg-current,
#upg-rng-current,
#upg-spd-current {
    color: #fff;
    font-weight: bold;
}

.stat-next {
    color: #00eaff;
    /* Neon Blue for improvement */
    opacity: 0;
    /* Hidden by default, shown via JS */
    transition: opacity 0.2s;
}

.upgrade-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 5px;
}

.action-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s;
}

.action-btn.upgrade {
    background: linear-gradient(90deg, #00eaff, #0076a3);
    color: #000;
    box-shadow: 0 0 15px rgba(0, 234, 255, 0.3);
}

.action-btn.upgrade:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

.action-btn.upgrade:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.action-btn.sell {
    background: rgba(255, 46, 99, 0.1);
    border: 1px solid rgba(255, 46, 99, 0.5);
    color: #ff2e63;
}

.action-btn.sell:hover {
    background: rgba(255, 46, 99, 0.2);
    box-shadow: 0 0 10px rgba(255, 46, 99, 0.2);
}

.btn-cost {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

#sell-action-btn {
    background: rgba(255, 46, 99, 0.2);
    border: 1px solid #ff2e63;
    border-radius: 8px;
    padding: 8px;
    color: #ff2e63;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
}

#sell-action-btn:hover {
    background: #ff2e63;
    color: #fff;
}

.close-mini-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: #ff2e63;
    border: 2px solid #fff;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.close-mini-btn:hover {
    transform: scale(1.1);
}

button {
    padding: 15px 40px;
    font-size: 24px;
    font-family: 'Rajdhani', sans-serif;
    font-weight: bold;
    color: #fff;
    background: #0f3460;
    border: 2px solid #e94560;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 2px;
}

button:hover {
    background: #e94560;
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.8);
}

/* Level Selection Screen */
#level-select-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* Reveal background canvas */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 250;
    pointer-events: auto;
}

#level-select-screen h2 {
    font-size: 54px;
    color: #4ecca3;
    text-shadow: 0 0 20px rgba(78, 204, 163, 0.5);
    margin-bottom: 50px;
    letter-spacing: 10px;
}

.level-grid {
    display: flex;
    gap: 30px;
    margin-bottom: 60px;
}

/* Level Map System - IMAGE BACKGROUND */
#level-map-container {
    position: relative;
    width: 90%;
    height: 70%;
    margin-bottom: 20px;
    background: url('assets/seviyesec.png') no-repeat center center;
    background-size: 100% 100%;
    border-radius: 10px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    overflow: visible;
}

/* Dim overlay to make UI pop if background is bright */
#level-map-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    pointer-events: none;
    z-index: 0;
}

.map-connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    filter: drop-shadow(0 0 5px #00eaff);
}

.map-path {
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 4;
    stroke-dasharray: 10, 10;
}

.map-path.unlocked-path {
    stroke: #00eaff;
    stroke-width: 6;
    stroke-dasharray: none;
    stroke-linecap: round;
    animation: pulsePath 3s infinite alternate;
}

@keyframes pulsePath {
    from {
        stroke-opacity: 0.6;
        stroke-width: 5;
    }

    to {
        stroke-opacity: 1;
        stroke-width: 7;
    }
}

.map-node {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    /* Clean Circle Style */
    background: #0f3460;
    /* Dark Blue Fill */
    border: 3px solid #00eaff;
    /* Cyan Border */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 0 20px rgba(0, 234, 255, 0.5);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.map-node:hover:not(.locked) {
    transform: translate(-50%, -50%) scale(1.15);
    background: #00eaff;
    box-shadow: 0 0 40px rgba(0, 234, 255, 0.9);
    z-index: 100;
}

.map-node.unlocked {
    background: rgba(0, 234, 255, 0.1);
    /* Semi-transparent center */
    backdrop-filter: blur(5px);
}

.map-node.locked {
    background: #333;
    border-color: #555;
    box-shadow: none;
    cursor: not-allowed;
    filter: grayscale(1);
}

.node-icon {
    font-size: 28px;
    font-weight: 800;
    color: #fff;
    z-index: 2;
    text-shadow: 0 0 5px rgba(0, 234, 255, 0.8);
}

.map-node:hover .node-icon {
    color: #000;
    text-shadow: none;
}

.node-lock {
    position: absolute;
    font-size: 24px;
    color: #888;
    z-index: 3;
}

/* Info Popup - ALWAYS VISIBLE (Mobile Optimized) */
.node-info {
    position: absolute;
    top: 65px;
    /* Closer to node */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 20, 35, 0.9);
    border: 1px solid rgba(0, 234, 255, 0.5);
    padding: 6px 10px;
    border-radius: 8px;
    width: 120px;
    text-align: center;
    pointer-events: none;
    opacity: 1;
    /* Always visible */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
}

.node-title {
    display: none;
}

.node-stars {
    color: #ffd700;
    font-size: 14px;
    letter-spacing: 2px;
    line-height: 1;
}

.node-record {
    font-size: 10px;
    color: #4ecca3;
    font-weight: bold;
    text-transform: uppercase;
}

/* Fade locked info slightly */
.map-node.locked .node-info {
    opacity: 0.5;
    border-color: #555;
    background: rgba(0, 0, 0, 0.8);
}

.hidden {
    display: none !important;
}

.back-btn {
    background: transparent;
    border: 2px solid #e94560;
    color: #e94560;
    padding: 12px 50px;
    border-radius: 50px;
    font-size: 20px;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: bold;
}

.back-btn:hover {
    background: #e94560;
    color: #fff;
    box-shadow: 0 0 25px rgba(233, 69, 96, 0.5);
}

.hidden {
    display: none !important;
}



/* Settings Modal */
/* Settings Modal Overlay */
#settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3001;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

/* Settings Content Box */
.settings-content {
    background: rgba(15, 52, 96, 0.95);
    border: 2px solid #00eaff;
    border-radius: 15px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 400px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 234, 255, 0.4);
    transform: scale(1);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#settings-modal h2 {
    color: #00eaff;
    margin-bottom: 10px;
}

.setting-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.setting-row label {
    font-size: 20px;
    color: #fff;
}

.setting-row input[type=range] {
    width: 80%;
    accent-color: #e94560;
}

.setting-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.setting-actions button {
    width: 100%;
    padding: 10px;
    font-size: 18px;
    background: #1a1a2e;
    border: 1px solid #4ecca3;
}

.setting-actions button:hover {
    background: #4ecca3;
    color: #1a1a2e;
}

.setting-actions .close-btn {
    border-color: #ff2e63;
    margin-top: 10px;
}

.setting-actions .close-btn:hover {
    background: #ff2e63;
    color: white;
}

#victory-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 13, 26, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 300;
    pointer-events: auto;
}

#victory-screen .glitch-text {
    color: #4ecca3;
    text-shadow: 2px 2px #00eaff, -2px -2px #0f0;
}

#vic-stats {
    font-size: 18px;
    letter-spacing: 2px;
    color: #fff;
    opacity: 0.8;
}