/* ---------- Variables & Theme Settings ---------- */
:root {
    /* Color Palette (Deep Icy Navy & Cyberpunk Neons) */
    --bg-dark: #030712;
    --bg-core: #0f172a;
    --glass-bg: rgba(15, 23, 42, 0.45);
    --glass-border: rgba(148, 163, 184, 0.15);
    --glass-highlight: rgba(255, 255, 255, 0.1);
    
    /* Neon Glows */
    --neon-cyan: #06b6d4;
    --neon-cyan-glow: rgba(6, 182, 212, 0.6);
    --neon-blue: #3b82f6;
    --neon-green: #10b981;
    --neon-green-glow: rgba(16, 185, 129, 0.6);
    --neon-purple: #8b5cf6;
    
    /* Text */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* UI Dimensions */
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;
    
    /* Transitions */
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --transition-bounce: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ---------- Global Reset & Base ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Poppins', sans-serif;
    
    /* Mobile optimization: Prevent swipe navigation, zoom, and text selection */
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    overscroll-behavior: none;
}

/* ---------- Game Canvas ---------- */
#game-canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    image-rendering: pixelated;
    background: radial-gradient(circle at center, var(--bg-core) 0%, var(--bg-dark) 100%);
}

/* ---------- HUD Container ---------- */
#hud-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px 24px;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 10;
}

/* EXP Bar Container */
#exp-bar-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    height: 18px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 30px;
    border: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.8), 
                0 4px 15px rgba(0, 0, 0, 0.4);
}

/* EXP Bar Fill with Pulsing Glow */
#exp-bar-fill {
    height: 100%;
    width: 0%; /* Dynamic via JS */
    background: linear-gradient(90deg, var(--neon-blue) 0%, var(--neon-cyan) 100%);
    border-radius: 30px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 15px var(--neon-cyan-glow), 
                inset 0 0 8px rgba(255, 255, 255, 0.6);
    position: relative;
}

#exp-bar-fill::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 50%);
    border-radius: 30px;
}

#exp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 2.5px;
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 1), 
                 0 0 8px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    z-index: 2;
}

/* Stats Panel Glassmorphism */
#stats-container {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.stat-box {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-top: 1px solid var(--glass-highlight);
    border-left: 1px solid var(--glass-highlight);
    border-radius: var(--border-radius-md);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: var(--transition-fast);
}

.stat-box:hover {
    transform: translateY(-2px);
    background: rgba(30, 41, 59, 0.65);
    border-color: rgba(255, 255, 255, 0.2);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.stat-icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 6px var(--neon-cyan-glow));
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Nested HP Bar in Stats */
.hp-bar-bg {
    width: 90px;
    height: 10px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 10px;
    overflow: hidden;
    margin-left: 10px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.9);
    border: 1px solid rgba(255,255,255,0.05);
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-highlight);
    border-radius: var(--border-radius-md);
    color: var(--neon-cyan);
    font-size: 1.5rem;
    padding: 10px 18px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: var(--transition-fast);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}
.icon-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    box-shadow: 0 0 15px var(--neon-cyan-glow);
    transform: scale(1.05);
}

#hp-bar-fill {
    height: 100%;
    width: 100%; /* Dynamic via JS */
    background: linear-gradient(90deg, #059669, var(--neon-green));
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 12px var(--neon-green-glow);
}

/* ---------- Virtual Joystick ---------- */
#joystick-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    pointer-events: none; /* Let touches pass through where there is no joystick */
    z-index: 20;
}

#joystick-base {
    position: absolute;
    bottom: 60px;
    right: 60px;
    left: auto;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.08) 100%);
    border: 2px solid var(--glass-border);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 0 25px rgba(0,0,0,0.6), 
                0 15px 35px rgba(0,0,0,0.5),
                inset 0 2px 5px rgba(255,255,255,0.1);
    transition: var(--transition-fast);
}

#joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 65px;
    height: 65px;
    background: linear-gradient(135deg, rgba(255,255,255,0.7), rgba(255,255,255,0.15));
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6), 
                inset 0 4px 10px rgba(255,255,255,0.9);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}

#joystick-base:active {
    box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 
                0 10px 30px rgba(0,0,0,0.5);
    border-color: rgba(255, 255, 255, 0.2);
}

#joystick-base:active #joystick-stick {
    background: linear-gradient(135deg, rgba(255,255,255,0.9), rgba(255,255,255,0.4));
    box-shadow: 0 0 35px var(--neon-cyan), 
                inset 0 4px 12px rgba(255,255,255,1);
    border-color: var(--neon-cyan);
}

/* ---------- Modals & Overlays ---------- */
.hidden {
    display: none !important;
}

.focused-item {
    outline: 3px solid var(--neon-cyan) !important;
    outline-offset: 4px;
    transform: scale(1.05) translateY(-5px) !important;
    box-shadow: 0 0 25px var(--neon-cyan-glow) !important;
    background: rgba(255, 255, 255, 0.1) !important;
}

#level-up-modal, #game-over-modal, #character-select-modal, #difficulty-select-modal, #pause-modal, #ranking-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(3, 7, 18, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    animation: fadeInOverlay 0.4s ease-out forwards;
}

.modal-content {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
    border: 1px solid var(--glass-highlight);
    border-top: 1px solid rgba(255,255,255,0.2);
    border-left: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--border-radius-lg);
    padding: 60px 50px;
    text-align: center;
    max-width: 1200px;
    width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    touch-action: pan-y; /* 모바일에서 위아래 스와이프 스크롤 허용 */
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.9), 
                0 0 60px var(--neon-cyan-glow);
    animation: slideUpBounce var(--transition-bounce) forwards;
}

/* 스크롤바 디자인 */
.modal-content::-webkit-scrollbar { width: 8px; }
.modal-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.3); border-radius: var(--border-radius-sm); }
.modal-content::-webkit-scrollbar-thumb { background: rgba(6, 182, 212, 0.5); border-radius: var(--border-radius-sm); }
.modal-content::-webkit-scrollbar-thumb:hover { background: rgba(6, 182, 212, 0.8); }

.modal-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 15px;
    background: linear-gradient(to right, #ffffff, var(--neon-cyan), var(--neon-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 5px;
    filter: drop-shadow(0 0 15px var(--neon-cyan-glow));
}

.modal-subtitle {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin-bottom: 50px;
    font-weight: 500;
}

#game-over-stats {
    font-size: 1.5rem;
    color: var(--text-main);
    font-weight: 700;
    margin-bottom: 25px;
    padding: 20px;
    background: rgba(255,255,255,0.03);
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

/* Leaderboard */
#leaderboard-container, .leaderboard-container-style {
    background: rgba(0, 0, 0, 0.4);
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 15px 20px;
    margin-bottom: 30px;
    text-align: left;
    max-height: 350px;
    overflow-y: auto;
    box-shadow: inset 0 5px 15px rgba(0,0,0,0.6);
}

.leaderboard-title {
    color: var(--neon-cyan);
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 12px;
    text-align: center;
    letter-spacing: 2px;
    text-shadow: 0 0 10px var(--neon-cyan-glow);
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 1rem;
    color: #e2e8f0;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.rank-idx { font-weight: 800; color: var(--neon-green); width: 35px; }
.rank-name { flex: 1; font-weight: 600; color: #fff; }
.rank-score { font-weight: 700; color: var(--neon-purple); text-shadow: 0 0 5px rgba(139, 92, 246, 0.5); }

/* Skill Cards */
.cards-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    perspective: 1200px;
}

.skill-card {
    flex: 1;
    min-width: 220px;
    max-width: 280px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 30px 20px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Radial Glow Behind Content */
.skill-card::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, var(--neon-cyan-glow) 0%, transparent 60%);
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
    transition: var(--transition-smooth);
    z-index: 0;
}

.skill-card:hover {
    transform: translateY(-15px) rotateX(8deg) scale(1.05);
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--neon-cyan);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7), 
                0 0 40px var(--neon-cyan-glow),
                inset 0 0 25px rgba(6, 182, 212, 0.2);
}

.skill-card:hover::before {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.skill-card > * {
    position: relative;
    z-index: 1;
}

.skill-icon {
    font-size: 4rem;
    background: linear-gradient(135deg, rgba(30,41,59,0.9), rgba(15,23,42,0.95));
    width: 110px;
    height: 110px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: inset 0 4px 20px rgba(0,0,0,0.8), 
                0 8px 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.15);
    transition: var(--transition-smooth);
}

.skill-card:hover .skill-icon {
    transform: scale(1.15);
    box-shadow: inset 0 4px 15px rgba(0,0,0,0.8), 
                0 0 30px var(--neon-cyan);
    border-color: var(--neon-cyan);
}

.skill-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
    margin-bottom: 10px;
    letter-spacing: 1px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

.skill-desc {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.6;
    font-weight: 400;
}

/* Glowing Neon Button */
.glow-btn {
    background: transparent;
    color: var(--neon-cyan);
    font-family: 'Poppins', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    padding: 20px 60px;
    border: 2px solid var(--neon-cyan);
    border-radius: 50px;
    cursor: pointer;
    transition: var(--transition-bounce);
    text-transform: uppercase;
    letter-spacing: 3px;
    box-shadow: 0 0 25px var(--neon-cyan-glow), 
                inset 0 0 15px var(--neon-cyan-glow);
    position: relative;
    overflow: hidden;
    margin-top: 20px;
    backdrop-filter: blur(5px);
}

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

.glow-btn:hover {
    background: var(--neon-cyan);
    color: #020617;
    box-shadow: 0 0 50px rgba(6, 182, 212, 0.8), 
                0 0 100px rgba(6, 182, 212, 0.5);
    transform: scale(1.1) translateY(-4px);
}

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

.glow-btn.danger {
    color: #ff4444;
    border-color: #ff4444;
    box-shadow: 0 0 25px rgba(255, 68, 68, 0.4), inset 0 0 15px rgba(255, 68, 68, 0.4);
}

.glow-btn.danger:hover {
    background: #ff4444;
    color: #fff;
    box-shadow: 0 0 50px rgba(255, 68, 68, 0.8), 0 0 100px rgba(255, 68, 68, 0.5);
}

.diff-easy { color: #10b981; border-color: #10b981; box-shadow: 0 0 25px rgba(16, 185, 129, 0.4), inset 0 0 15px rgba(16, 185, 129, 0.4); }
.diff-easy:hover { background: #10b981; color: #fff; box-shadow: 0 0 50px rgba(16, 185, 129, 0.8), 0 0 100px rgba(16, 185, 129, 0.5); }
.diff-normal { color: #f59e0b; border-color: #f59e0b; box-shadow: 0 0 25px rgba(245, 158, 11, 0.4), inset 0 0 15px rgba(245, 158, 11, 0.4); }
.diff-normal:hover { background: #f59e0b; color: #fff; box-shadow: 0 0 50px rgba(245, 158, 11, 0.8), 0 0 100px rgba(245, 158, 11, 0.5); }
.diff-hard { color: #ef4444; border-color: #ef4444; box-shadow: 0 0 25px rgba(239, 68, 68, 0.4), inset 0 0 15px rgba(239, 68, 68, 0.4); }
.diff-hard:hover { background: #ef4444; color: #fff; box-shadow: 0 0 50px rgba(239, 68, 68, 0.8), 0 0 100px rgba(239, 68, 68, 0.5); }

/* ---------- Animations ---------- */
@keyframes fadeInOverlay {
    from { 
        opacity: 0; 
        backdrop-filter: blur(0px); 
        -webkit-backdrop-filter: blur(0px);
    }
    to { 
        opacity: 1; 
        backdrop-filter: blur(16px); 
        -webkit-backdrop-filter: blur(16px);
    }
}

@keyframes slideUpBounce {
    0% { transform: translateY(80px) scale(0.9); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 768px) {
    #hud-container {
        padding: 8px;
        gap: 8px;
    }
    
    #stats-container {
        gap: 6px;
    }
    
    .stat-box {
        padding: 6px 8px;
        font-size: 0.8rem;
        gap: 6px;
    }

    .hp-bar-bg {
        width: 50px;
        margin-left: 6px;
    }
    
    #joystick-base {
        right: 20px;
        left: auto;
        bottom: 30px;
        width: 130px;
        height: 130px;
    }
    
    #joystick-stick {
        width: 55px;
        height: 55px;
    }
    
    .modal-content {
        padding: 40px 25px;
        width: 95%;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    .modal-title {
        font-size: 2.5rem;
        letter-spacing: 2px;
    }

    .modal-subtitle {
        font-size: 1.05rem;
        margin-bottom: 35px;
    }
    
    .cards-container {
        flex-direction: column;
        gap: 18px;
    }

    .skill-card {
        min-width: 100%;
        padding: 22px;
        flex-direction: row;
        text-align: left;
    }
    
    .skill-card:hover {
        transform: scale(1.03) translateX(8px);
    }
    
    .skill-icon {
        width: 85px;
        height: 85px;
        font-size: 3rem;
        flex-shrink: 0;
    }

    .skill-info {
        flex: 1;
    }
    
    .skill-name {
        font-size: 1.3rem;
        margin-bottom: 5px;
    }

    .skill-desc {
        font-size: 0.9rem;
    }

    .glow-btn {
        padding: 16px 45px;
        font-size: 1.25rem;
        width: 100%;
    }
}
```