* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #1a1a2e;
    color: white;
}

#game-container {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
}

canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ==================== UI PANEL ==================== */
#ui-panel {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.9);
    padding: 12px;
    border-radius: 12px;
    border: 2px solid #4a9eff;
    min-width: 140px;
    max-width: 180px;
    z-index: 100;
    backdrop-filter: blur(10px);
}

#ui-panel h2 {
    color: #4a9eff;
    margin-bottom: 10px;
    text-align: center;
    font-size: 1.1em;
}

.stats-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.stat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px;
    background: rgba(74, 158, 255, 0.15);
    border-radius: 6px;
    font-size: 0.95em;
}

.stat-value {
    color: #4a9eff;
    font-weight: bold;
}

.health-bar-container {
    margin: 8px 0;
    background: #333;
    border-radius: 8px;
    padding: 3px;
}

.health-bar {
    height: 16px;
    background: linear-gradient(90deg, #4a9eff, #6bb3ff);
    border-radius: 6px;
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    font-weight: bold;
}

#castle-status {
    text-align: center;
    margin-top: 8px;
    padding: 6px;
    background: rgba(74, 158, 255, 0.1);
    border-radius: 8px;
}

#castle-status .castle-name {
    font-size: 0.9em;
    color: #4a9eff;
    font-weight: bold;
}

#wave-info {
    text-align: center;
    margin-top: 8px;
    padding: 8px;
    background: linear-gradient(135deg, rgba(255,74,74,0.2), rgba(255,74,74,0.1));
    border-radius: 8px;
}

#wave-info .wave-number {
    font-size: 1.4em;
    color: #ff4a4a;
    font-weight: bold;
}

#unit-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 10px;
}

.unit-btn {
    padding: 10px 4px;
    border: 2px solid #4a9eff;
    background: transparent;
    color: white;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 1.2em;
    text-align: center;
    min-height: 50px;
}

.unit-btn:hover, .unit-btn.active {
    background: #4a9eff;
    color: #1a1a2e;
}

.unit-btn small {
    display: block;
    font-size: 0.65em;
    margin-top: 2px;
}

/* ==================== MOBILE CONTROLS ==================== */
#mobile-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
}

.control-hint {
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85em;
    color: #aaa;
}

/* ==================== INSTRUCTIONS ==================== */
#instructions {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.85);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.75em;
    line-height: 1.8;
    border: 1px solid #4a9eff;
    max-width: 160px;
    z-index: 100;
}

#instructions span {
    color: #4a9eff;
    font-weight: bold;
}

/* ==================== GAME OVER ==================== */
#game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 30px 40px;
    border-radius: 20px;
    border: 3px solid #ff4a4a;
    text-align: center;
    display: none;
    z-index: 200;
    min-width: 250px;
}

#game-over h1 {
    color: #ff4a4a;
    font-size: 1.8em;
    margin-bottom: 15px;
}

#restart-btn {
    padding: 12px 30px;
    font-size: 1em;
    background: #ff4a4a;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 10px;
    margin-top: 15px;
}

/* ==================== RESPONSIVE ==================== */

/* تبلت */
@media (max-width: 768px) {
    #ui-panel {
        top: 5px;
        right: 5px;
        padding: 10px;
        min-width: 120px;
        max-width: 150px;
    }

    #ui-panel h2 {
        font-size: 1em;
        margin-bottom: 8px;
    }

    .stat {
        padding: 5px;
        font-size: 0.85em;
    }

    .unit-btn {
        padding: 8px 4px;
        font-size: 1.1em;
        min-height: 45px;
    }

    #instructions {
        display: none;
    }

    #mobile-controls {
        bottom: 15px;
    }
}

/* موبایل */
@media (max-width: 480px) {
    #ui-panel {
        top: auto;
        bottom: 10px;
        right: 5px;
        left: 5px;
        max-width: none;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
        border-radius: 15px;
    }

    #ui-panel h2 {
        width: 100%;
        margin-bottom: 5px;
    }

    .stats-row {
        flex: 1;
        min-width: 100px;
    }

    #castle-status {
        flex: 1;
        min-width: 100px;
        margin-top: 0;
    }

    #wave-info {
        flex: 0 0 auto;
        min-width: 60px;
        margin-top: 0;
        padding: 6px;
    }

    #wave-info .wave-number {
        font-size: 1.2em;
    }

    #unit-selector {
        width: 100%;
        grid-template-columns: repeat(4, 1fr);
        gap: 5px;
    }

    .unit-btn {
        padding: 8px 2px;
        font-size: 1.3em;
        min-height: 50px;
    }

    .unit-btn small {
        font-size: 0.6em;
    }

    #mobile-controls {
        bottom: 10px;
    }

    .control-hint {
        font-size: 0.75em;
        padding: 6px 12px;
    }
}

/* موبایل کوچک */
@media (max-width: 360px) {
    .unit-btn {
        font-size: 1.1em;
        min-height: 45px;
    }

    .stat {
        font-size: 0.8em;
        padding: 4px;
    }
}