/* BASE GLOBAL CONFIG */
:root {
    --bg-dark: #070913;
    --panel-bg: rgba(13, 17, 33, 0.85);
    --panel-border: rgba(0, 243, 255, 0.2);
    --panel-glow: rgba(0, 243, 255, 0.15);
    
    --neon-cyan: #00f3ff;
    --neon-pink: #ff007f;
    --neon-yellow: #ffdf00;
    --neon-green: #39ff14;
    --neon-red: #ff3131;
    --neon-purple: #9d4edd;
    
    --text-primary: #f0f3ff;
    --text-muted: #8a9fc4;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
}

/* CANVAS setup */
canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    background: radial-gradient(circle at center, #101428 0%, #05060f 100%);
}

/* UI CONTAINER & OVERLAYS */
#uiContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none; /* Let clicks pass to canvas if not on panel */
}

/* GLASS PANEL UTILITY */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 550px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.6), 
                0 0 20px var(--panel-glow);
    pointer-events: auto; /* Re-enable clicks for menus */
    animation: panelAppear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes panelAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 15;
}

.overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* TEXT TYPOGRAPHY */
h1, h2, h3, .hud-label, .info-value, .box-val {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.text-center { text-align: center; }

.game-title {
    font-size: 2.8rem;
    line-height: 1.1;
    margin-bottom: 8px;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.5), 0 0 20px rgba(0, 243, 255, 0.2);
    font-weight: 900;
}

.game-over-title {
    font-size: 3rem;
    color: var(--neon-red);
    text-shadow: 0 0 10px rgba(255, 49, 49, 0.6);
    margin-bottom: 8px;
    font-weight: 900;
}

.highlight {
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(0, 243, 255, 0.6);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* BUTTONS */
.btn {
    font-family: 'Orbitron', sans-serif;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--neon-cyan) 0%, #0088ff 100%);
    color: #000;
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.7);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-primary);
}

.btn-secondary:hover {
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    box-shadow: 0 0 15px rgba(255, 0, 127, 0.3);
    transform: translateY(-2px);
}

.btn-secondary:active {
    transform: translateY(1px);
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    margin-bottom: 20px;
}

/* INPUTS */
.input-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 25px;
}

.input-group label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 2px;
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-family: 'Orbitron', sans-serif;
    outline: none;
    transition: all 0.3s ease;
}

.input-group input:focus {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.3);
}

/* CONTROLS INSTRUCTIONS */
.instructions {
    margin-top: 25px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 15px;
}

/* HUD STYLING */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    padding: 15px;
}

#hud.hidden {
    display: none;
}

/* XP BAR (Top of Screen) */
.xp-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    z-index: 6;
}

.xp-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--neon-pink) 0%, var(--neon-purple) 100%);
    box-shadow: 0 0 10px rgba(255, 0, 127, 0.6);
    transition: width 0.1s ease-out;
}

.level-badge {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--neon-pink);
    box-shadow: 0 0 8px rgba(255, 0, 127, 0.3);
    color: #fff;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* STATS PANEL (Top Left) */
.stats-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 6;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-icon {
    font-size: 1.2rem;
}

.hp-bar-container {
    width: 180px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.hp-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--neon-green) 0%, #1db954 100%);
    box-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
    transition: width 0.15s ease-out;
}

.hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: 700;
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* GAME INFO PANEL (Top Right) */
.game-info-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 20px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    padding: 8px 16px;
    border-radius: 10px;
    z-index: 6;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.info-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.info-value {
    font-size: 0.95rem;
    color: #fff;
}

/* LEVEL UP UPGRADES CARDS */
.cards-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    width: 100%;
}

.upgrade-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.upgrade-card:hover {
    background: rgba(0, 243, 255, 0.08);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.25);
    transform: scale(1.03);
}

.upgrade-icon-box {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.6rem;
    background: rgba(0, 243, 255, 0.15);
    border: 1px solid rgba(0, 243, 255, 0.3);
}

.upgrade-info {
    flex: 1;
}

.upgrade-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}

.upgrade-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* LEADERBOARD TABLE */
.table-container {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 20px;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.leaderboard-table th {
    font-family: 'Orbitron', sans-serif;
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 1px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.5);
    position: sticky;
    top: 0;
}

.leaderboard-table td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.leaderboard-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.leaderboard-table tr:nth-child(1) td { color: var(--neon-yellow); font-weight: bold; }
.leaderboard-table tr:nth-child(2) td { color: #d1d1d1; }
.leaderboard-table tr:nth-child(3) td { color: #cd7f32; }

/* FINAL STATS BOXES */
.final-stats {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin: 25px 0;
}

.final-stat-box {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px 6px;
    display: flex;
    flex-direction: column;
}

.box-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 1px;
}

.box-val {
    font-size: 1.2rem;
    color: #fff;
}

/* VIRTUAL JOYSTICK FOR MOBILE */
#joystickContainer {
    position: absolute;
    bottom: 40px;
    left: 40px;
    width: 120px;
    height: 120px;
    z-index: 8;
    pointer-events: auto;
}

#joystickContainer.hidden {
    display: none !important;
}

/* Hide joystick completely on desktop/mouse-only devices */
@media (hover: hover) and (pointer: fine) {
    #joystickContainer {
        display: none !important;
    }
}


#joystickBase {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(0, 243, 255, 0.3);
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.1);
}

#joystickKnob {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--neon-cyan) 0%, #0088ff 100%);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
    transition: transform 0.05s ease-out;
}

/* PULSE ANIMATION */
.pulse {
    animation: textPulse 2s infinite alternate;
}

@keyframes textPulse {
    from {
        text-shadow: 0 0 5px rgba(0, 243, 255, 0.2);
    }
    to {
        text-shadow: 0 0 15px rgba(0, 243, 255, 0.7);
    }
}

/* RESPONSIVE MEDIA QUERIES */
@media (max-width: 600px) {
    .game-title {
        font-size: 2.1rem;
    }
    
    .game-over-title {
        font-size: 2.4rem;
    }
    
    .glass-panel {
        padding: 20px;
    }
    
    .final-stats {
        flex-direction: column;
        gap: 8px;
        margin: 15px 0;
    }
    
    .final-stat-box {
        padding: 8px;
    }

    .stats-panel {
        top: 15px;
        left: 10px;
    }

    .hp-bar-container {
        width: 100px;
    }

    .game-info-panel {
        top: 48px;
        right: 10px;
        padding: 6px 12px;
        gap: 12px;
    }

    .info-value {
        font-size: 0.85rem;
    }

    .info-label {
        font-size: 0.6rem;
    }

    #joystickContainer {
        bottom: 30px;
        left: 30px;
        width: 100px;
        height: 100px;
    }
    
    #joystickKnob {
        width: 40px;
        height: 40px;
    }
}

/* Hide PC/Mobile specific elements depending on features */
@media (hover: none) and (pointer: coarse) {
    .pc-instr { display: none; }
    .mobile-instr { display: block; }
}

@media (hover: hover) {
    .pc-instr { display: block; }
    .mobile-instr { display: none; }
}

/* PAUSE BUTTON HUD */
.hud-pause-btn {
    background: transparent;
    border: none;
    font-size: 1.1rem;
    color: #fff;
    cursor: pointer;
    margin-left: 10px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.8;
}

.hud-pause-btn:hover {
    transform: scale(1.15);
    opacity: 1;
}

.hud-pause-btn:active {
    transform: scale(0.9);
}

/* INVENTORY DISPLAY IN PAUSE MENU */
.inventory-section {
    margin-top: 15px;
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.inv-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.inv-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    width: 100%;
    padding-bottom: 4px;
    text-align: left;
}

.inv-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    width: 100%;
}

.inv-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    text-align: left;
}

.inv-item-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    background: rgba(0, 243, 255, 0.08);
    border: 1px solid rgba(0, 243, 255, 0.2);
}

.inv-item-info {
    flex: 1;
}

.inv-item-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
}

.inv-item-level {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.65rem;
    color: var(--neon-cyan);
}

/* EVOLVED ITEMS */
.inv-item.evolved {
    border-color: var(--neon-yellow);
    box-shadow: 0 0 10px rgba(255, 223, 0, 0.2);
    background: rgba(255, 223, 0, 0.03);
}

.inv-item.evolved .inv-item-icon {
    background: rgba(255, 223, 0, 0.15);
    border-color: var(--neon-yellow);
    box-shadow: 0 0 8px rgba(255, 223, 0, 0.3);
}

.inv-item.evolved .inv-item-level {
    color: var(--neon-yellow);
    animation: textPulse 1s infinite alternate;
}

/* Golden Evolution Card highlight in Level Up choices */
.upgrade-card.evolution {
    border-color: var(--neon-yellow);
    box-shadow: 0 0 15px rgba(255, 223, 0, 0.3);
    background: rgba(255, 223, 0, 0.05);
}

.upgrade-card.evolution:hover {
    background: rgba(255, 223, 0, 0.1);
    box-shadow: 0 0 25px rgba(255, 223, 0, 0.5);
}

.upgrade-card.evolution .upgrade-icon-box {
    background: rgba(255, 223, 0, 0.2);
    border-color: var(--neon-yellow);
    color: var(--neon-yellow);
}

.upgrade-card.evolution .upgrade-title {
    color: var(--neon-yellow);
}

