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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background: #0a0e27;
    font-family: 'Arial', sans-serif;
    color: #fff;
    touch-action: none;
}

/* ==================== START SCREEN ==================== */
#startScreen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(53, 96, 255, 0.24), rgba(12, 15, 32, 0) 45%),
        radial-gradient(circle at 80% 75%, rgba(0, 220, 140, 0.16), rgba(10, 14, 39, 0) 48%),
        rgba(3, 6, 18, 0.95);
    backdrop-filter: blur(6px);
}

#startScreen.show {
    display: flex;
}

#startCard {
    width: min(480px, 100%);
    background: linear-gradient(140deg, rgba(13, 20, 46, 0.97), rgba(26, 15, 52, 0.95));
    border: 1px solid rgba(120, 170, 255, 0.5);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

#startTitle {
    font-size: clamp(30px, 5vw, 44px);
    line-height: 1.05;
    margin-bottom: 8px;
    color: #d8e7ff;
}

#startSubtitle {
    color: #a8b7de;
    font-size: 15px;
    margin-bottom: 22px;
}

.start-group {
    margin-bottom: 18px;
}

.start-label {
    display: block;
    margin-bottom: 10px;
    font-size: 13px;
    letter-spacing: 0.6px;
    color: #8fc8ff;
    text-transform: uppercase;
    font-weight: 700;
}

.choice-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid rgba(139, 165, 255, 0.3);
    background: rgba(21, 27, 56, 0.72);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
}

.choice-row input {
    accent-color: #42e7a1;
}

#difficultySelect {
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid rgba(139, 165, 255, 0.4);
    background: rgba(18, 26, 53, 0.95);
    color: #eef4ff;
    font-size: 14px;
}

#startGameBtn {
    width: 100%;
    border: none;
    border-radius: 10px;
    padding: 13px 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    color: #051123;
    background: linear-gradient(110deg, #59f0b2, #6ebeff);
    box-shadow: 0 10px 24px rgba(72, 178, 255, 0.35);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

#startGameBtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(72, 178, 255, 0.48);
}

/* ==================== GAME CANVAS ==================== */
#gameCanvas {
    display: block;
    background: linear-gradient(135deg, #111 0%, #1a1f3a 100%);
    cursor: crosshair;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
}

/* ==================== HUD OVERLAY ==================== */
#ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Top Stats Bar */
#topUI {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
}

#score, #timer, #players, #netStatus {
    background: rgba(0, 0, 0, 0.75);
    padding: 12px 18px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.15);
    font-weight: bold;
    font-size: 14px;
}

#score { color: #00ff88; }
#timer { color: #ff6b00; }
#players { color: #00ccff; }
#netStatus { color: #ff9a9a; }

/* Abilities Container */
#abilities {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    pointer-events: all;
    flex-wrap: wrap;
    max-width: 600px;
}

.ability-btn {
    padding: 10px 14px;
    background: rgba(100, 100, 150, 0.6);
    color: white;
    border: 2px solid rgba(100, 150, 255, 0.6);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s;
    backdrop-filter: blur(5px);
    white-space: nowrap;
}

.ability-btn:hover:not(:disabled) {
    background: rgba(100, 150, 255, 0.8);
    transform: scale(1.05);
}

.ability-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(50, 50, 80, 0.5);
    border-color: rgba(100, 100, 150, 0.3);
}

.ability-btn.active {
    background: rgba(0, 200, 100, 0.7);
    border-color: rgba(0, 255, 150, 0.8);
    box-shadow: 0 0 15px rgba(0, 255, 150, 0.4);
}

/* Stats/Controls at Bottom */
#stats {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    padding: 14px 18px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.15);
    font-size: 13px;
    color: #aaa;
    pointer-events: all;
    z-index: 100;
    max-width: 400px;
}

#stats p {
    margin: 0;
    line-height: 1.4;
}

/* ==================== MINIMAP ==================== */
#minimapCanvas {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.85);
    border: 3px solid rgba(100, 200, 255, 0.6);
    border-radius: 8px;
    backdrop-filter: blur(10px);
    z-index: 99;
    box-shadow: 0 0 20px rgba(100, 200, 255, 0.3);
    width: 200px;
    height: 200px;
}

#leaderboard {
    position: fixed;
    top: 230px;
    right: 20px;
    width: 200px;
    background: rgba(8, 10, 22, 0.35);
    border: 2px solid rgba(255, 210, 120, 0.35);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    z-index: 99;
    box-shadow: 0 0 18px rgba(255, 200, 120, 0.08);
    padding: 8px 10px 10px;
}

#leaderboardTitle {
    font-size: 13px;
    font-weight: 800;
    color: #ffd38e;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

#leaderboardList {
    margin: 0;
    padding-left: 20px;
    color: #f9f2dd;
    font-size: 12px;
    line-height: 1.5;
}

#leaderboardList li {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== MOBILE OPTIMIZED UI ==================== */
/* Apply mobile UI on screens ≤768px width - ALL elements hidden except joystick, minimap, leaderboard */

body.mobile-mp {
    background: #0a0e27 !important;
}

/* Hide all UI elements in mobile mode */
body.mobile-mp #ui {
    display: none !important;
    pointer-events: none !important;
}

body.mobile-mp #topUI {
    display: none !important;
}

body.mobile-mp #abilities {
    display: none !important;
    pointer-events: none !important;
}

body.mobile-mp #stats {
    display: none !important;
    pointer-events: none !important;
}

body.mobile-mp #hazardPanel {
    display: none !important;
    pointer-events: none !important;
}

/* SHOW Joystick in mobile mode */
body.mobile-mp #joystick {
    display: flex !important;
    pointer-events: all !important;
}

/* Show and position minimap for mobile */
body.mobile-mp #minimapCanvas {
    display: block !important;
    position: fixed !important;
    width: 110px !important;
    height: 110px !important;
    right: 15px !important;
    top: 15px !important;
    bottom: auto !important;
    border: 2px solid rgba(100, 200, 255, 0.6) !important;
    border-radius: 8px !important;
    opacity: 0.85 !important;
    z-index: 130 !important;
    background: rgba(0, 0, 0, 0.4) !important;
    backdrop-filter: blur(8px) !important;
    box-shadow: 0 0 20px rgba(100, 200, 255, 0.3) !important;
    pointer-events: none !important;
}

/* Show and position leaderboard for mobile - TRANSPARENT - TOP LEFT */
body.mobile-mp #leaderboard {
    display: block !important;
    position: fixed !important;
    width: 130px !important;
    height: 160px !important;
    left: 15px !important;
    top: 15px !important;
    right: auto !important;
    bottom: auto !important;
    background: rgba(8, 10, 22, 0.1) !important;
    border: 1px solid rgba(255, 210, 120, 0.15) !important;
    border-radius: 8px !important;
    backdrop-filter: blur(6px) !important;
    z-index: 99 !important;
    padding: 6px 6px !important;
    overflow-y: auto !important;
    max-height: 160px !important;
    pointer-events: auto !important;
    box-shadow: 0 0 8px rgba(255, 200, 120, 0.02) !important;
}

body.mobile-mp #leaderboardTitle {
    font-size: 11px !important;
    font-weight: 800 !important;
    color: rgba(255, 211, 142, 0.5) !important;
    letter-spacing: 0.3px !important;
    margin-bottom: 6px !important;
    display: block !important;
}

body.mobile-mp #leaderboardList {
    margin: 0 !important;
    padding-left: 14px !important;
    color: rgba(249, 242, 221, 0.45) !important;
    font-size: 9px !important;
    line-height: 1.3 !important;
    list-style: decimal !important;
}

body.mobile-mp #leaderboardList li {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    font-size: 9px !important;
}

/* ==================== JOYSTICK STYLING ==================== */
#joystick {
    position: fixed !important;
    bottom: 30px !important;
    left: 30px !important;
    z-index: 120 !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    user-select: none !important;
    touch-action: none !important;
    pointer-events: all !important;
}

#joystickBase {
    position: relative;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle at 30% 30%, rgba(100, 180, 255, 0.35), rgba(40, 80, 180, 0.25));
    border: 3px solid rgba(100, 180, 255, 0.6);
    border-radius: 50%;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.5),
        0 0 30px rgba(100, 180, 255, 0.4),
        0 0 60px rgba(100, 180, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

#joystickKnob {
    position: absolute;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle at 35% 35%, rgba(0, 255, 200, 0.9), rgba(0, 200, 150, 0.7));
    border: 2px solid rgba(0, 255, 200, 0.8);
    border-radius: 50%;
    box-shadow: 
        0 0 15px rgba(0, 255, 200, 0.6),
        inset 0 0 10px rgba(255, 255, 255, 0.3);
    cursor: grab;
    transition: transform 0.05s ease-out;
    will-change: transform;
}

#joystickKnob:active {
    cursor: grabbing;
}

/* ==================== HAZARD UI ==================== */
#hazardPanel {
    margin-top: 14px;
    width: min(540px, calc(100vw - 64px));
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 10px 12px;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(120deg, rgba(68, 18, 24, 0.88), rgba(20, 16, 36, 0.88));
    border: 2px solid rgba(255, 96, 96, 0.65);
    border-radius: 12px;
    box-shadow: 0 0 18px rgba(255, 110, 110, 0.2);
    transform: translateY(-6px);
    opacity: 0.86;
    transition: transform 0.25s ease, opacity 0.25s ease, box-shadow 0.25s ease;
}

#hazardPanel.active {
    opacity: 1;
    transform: translateY(0);
    box-shadow: 0 0 28px rgba(255, 120, 120, 0.45);
    animation: hazardPulse 0.75s ease;
}

#hazardIcon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 20px;
    color: #201011;
    background: radial-gradient(circle at 30% 25%, #ffd79d, #ff5f5f);
    box-shadow: 0 0 12px rgba(255, 100, 100, 0.55);
}

#hazardTextWrap {
    min-width: 0;
}

#hazardTitle {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #ffc4c4;
}

#hazardText {
    margin-top: 2px;
    font-size: 12px;
    color: #f6dede;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#hazardCooldown {
    grid-column: 1 / -1;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
}

#hazardCooldownFill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #ff7373, #ffd78e);
    transition: width 0.15s linear;
}

#shockwaveFlash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 220;
    opacity: 0;
    background: radial-gradient(circle at center, rgba(255, 170, 96, 0.24), rgba(255, 35, 35, 0.1) 45%, rgba(0, 0, 0, 0) 70%);
}

#shockwaveFlash.active {
    animation: shockwaveFlash 0.5s ease-out;
}

@keyframes hazardPulse {
    0% { transform: translateY(-2px) scale(1); }
    45% { transform: translateY(0) scale(1.02); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes shockwaveFlash {
    0% { opacity: 0; }
    15% { opacity: 1; }
    100% { opacity: 0; }
}

/* ==================== GAME OVER SCREEN ==================== */
#gameOverScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

#gameOverScreen.show {
    display: flex;
}

#gameOverContent {
    text-align: center;
    background: rgba(20, 30, 60, 0.98);
    padding: 60px 50px;
    border-radius: 16px;
    border: 2px solid rgba(100, 200, 255, 0.5);
    box-shadow: 0 0 50px rgba(100, 200, 255, 0.3);
    animation: popIn 0.5s ease-out;
    max-width: 500px;
}

@keyframes popIn {
    from {
        transform: scale(0.3);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

#gameOverTitle {
    font-size: 56px;
    margin-bottom: 25px;
    text-shadow: 0 0 20px rgba(255, 200, 0, 0.6);
    font-weight: bold;
}

#gameOverMessage {
    font-size: 28px;
    margin-bottom: 35px;
    color: #00ff88;
}

#restartBtn {
    padding: 18px 40px;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    color: #000;
    border: none;
    border-radius: 10px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    pointer-events: all;
}

#restartBtn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(0, 255, 150, 0.8);
}

/* ==================== RESPONSIVE DESIGN ==================== */
@media (max-width: 1024px) {
    #topUI {
        gap: 10px;
    }
    
    #score, #timer, #players {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .ability-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
}

@media (max-width: 768px) {
    #startCard {
        padding: 22px;
    }

    #topUI {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    #score, #timer, #players {
        padding: 8px 12px;
        font-size: 12px;
        flex: 1;
        min-width: 120px;
    }
    
    #abilities {
        max-width: 100%;
        gap: 8px;
    }
    
    .ability-btn {
        padding: 7px 10px;
        font-size: 10px;
    }
    
    #stats {
        bottom: 15px;
        left: 15px;
        font-size: 11px;
        padding: 10px 14px;
        max-width: calc(100vw - 30px);
    }
    
    #gameOverContent {
        padding: 40px 30px;
        margin: 20px;
    }
    
    #gameOverTitle {
        font-size: 40px;
    }
    
    #gameOverMessage {
        font-size: 20px;
    }

    #hazardPanel {
        width: calc(100vw - 30px);
    }

    #hazardText {
        font-size: 11px;
    }

    #leaderboard {
        width: 170px;
        top: 218px;
    }

    #leaderboardList {
        font-size: 11px;
    }
    
    #restartBtn {
        padding: 14px 30px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    #startCard {
        padding: 18px;
    }

    #ui {
        padding: 12px;
    }
    
    #topUI {
        gap: 6px;
    }
    
    #score, #timer, #players {
        padding: 7px 10px;
        font-size: 11px;
        flex: 0.8;
    }
    
    #abilities {
        gap: 6px;
        margin-top: 10px;
    }
    
    .ability-btn {
        padding: 6px 8px;
        font-size: 9px;
    }
    
    #stats {
        bottom: 12px;
        left: 12px;
        padding: 8px 12px;
        font-size: 10px;
        max-width: calc(100vw - 24px);
    }

    #hazardPanel {
        grid-template-columns: 34px 1fr;
        padding: 8px 10px;
        margin-top: 10px;
    }

    #hazardIcon {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }

    #leaderboard {
        width: 150px;
        top: 208px;
        right: 12px;
        padding: 7px 8px 8px;
    }

    #leaderboardTitle {
        font-size: 12px;
    }
}