/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: #1a1a1a;
    color: #f0f0f0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Hidden Class */
.hidden {
    display: none !important;
}

/* Login Screen Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, #333333, #111111);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-box {
    background: rgba(30, 30, 30, 0.9);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
    border: 1px solid #333;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-box h1 {
    color: #ffd700;
    font-weight: 800;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.login-box p {
    color: #aaa;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-box input {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 1rem;
    border: none;
    border-radius: 6px;
    background: #2a2a2a;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: background 0.2s;
}

.login-box input:focus {
    background: #3a3a3a;
    box-shadow: 0 0 0 2px #ffd700;
}

.emoji-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.emoji-option {
    font-size: 2rem;
    cursor: pointer;
    border-radius: 10px;
    padding: 5px;
    transition: background 0.2s, transform 0.2s;
    user-select: none;
}

.emoji-option:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.emoji-option.selected {
    background: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.login-box button {
    width: 100%;
    padding: 0.8rem;
    background: #ffd700;
    color: #1a1a1a;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

.login-box button:hover {
    background: #ffea00;
    transform: translateY(-2px);
}

.login-box button:active {
    transform: translateY(0);
}

/* Game Container - Three Column Layout */
#gameContainer {
    display: flex;
    width: 95vw;
    height: 90vh;
    gap: 1.5rem;
}

/* Side Panels */
.side-panel {
    background: #222;
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    border: 1px solid #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.side-panel.left {
    flex: 1;
    min-width: 250px;
    max-width: 300px;
}

.side-panel.right {
    flex: 1;
    min-width: 300px;
    max-width: 350px;
}

.mobile-top-bar {
    display: none;
    /* Hidden on desktop */
}

.mobile-only-btn {
    display: none;
    background: #444;
    color: white;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.panel-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.close-panel-btn {
    display: none;
    /* Only show on mobile */
    background: transparent;
    color: #ff4444;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    font-weight: bold;
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #ffd700;
    border-bottom: 1px solid #333;
    padding-bottom: 0.5rem;
}

/* Scoreboard */
#scoreBoard {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

#scoreBoard li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    background: #2a2a2a;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    font-size: 0.95rem;
    align-items: center;
}

#scoreBoard li .name {
    font-weight: 600;
}

#scoreBoard li .stats {
    color: #ffd700;
    font-weight: bold;
}

/* Controls Info */
.controls-info {
    margin-top: auto;
    background: #1a1a1a;
    padding: 1rem;
    border-radius: 8px;
}

.controls-info h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #aaa;
}

.controls-info ul {
    list-style: none;
    font-size: 0.85rem;
    color: #888;
}

.controls-info li {
    margin-bottom: 0.4rem;
}

kbd {
    background: #333;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    color: white;
    border-bottom: 2px solid #111;
}

/* Shop Styles */
.desktop-shop {
    margin-top: 1rem;
    padding-top: 1rem;
}

.desktop-shop h3 {
    color: #ffd700;
    margin-bottom: 0.5rem;
}

.desktop-shop p {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}

.shop-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.gold-text {
    color: gold;
    font-weight: bold;
}

.shop-item {
    background: #2a2a2a;
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.buy-btn {
    width: 100%;
    background: #007bff;
    color: white;
    border: none;
    padding: 0.6rem;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.buy-btn:hover:not(:disabled) {
    background: #0056b3;
}

.buy-btn:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
}

/* Hide mobile shop panel on desktop */
@media (min-width: 901px) {
    #shopPanel {
        display: none !important;
    }
}

/* Canvas Container */
.canvas-container {
    flex: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #111;
    border-radius: 10px;
    border: 2px solid #333;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8);
}

canvas {
    image-rendering: auto;
    /* Smoother on mobile */
    background: #2b2b2b;
    /* Match empty tile color */
    display: block;
}

/* Chat Layout */
.chat-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: #1a1a1a;
    padding: 0.8rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.msg {
    line-height: 1.4;
    word-break: break-word;
}

.msg.system {
    color: #888;
    font-style: italic;
    font-size: 0.85rem;
    text-align: center;
}

.msg .sender {
    font-weight: bold;
    margin-right: 0.3rem;
}

/* Chat Input */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
}

.chat-input-area input {
    flex: 1;
    padding: 0.6rem;
    border: none;
    border-radius: 4px;
    background: #2a2a2a;
    color: white;
    outline: none;
}

.chat-input-area input:focus {
    box-shadow: 0 0 0 1px #888;
}

.chat-input-area button {
    padding: 0 1rem;
    background: #444;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.chat-input-area button:hover {
    background: #555;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* Mobile Virtual Controls */
.mobile-controls {
    display: none;
    /* Hidden on desktop by default */
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    padding: 0 20px;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    /* Let clicks pass through empty spaces */
    z-index: 100;
}

.joystick-zone {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: rgba(50, 50, 50, 0.6);
    border: 2px solid #777;
    position: relative;
    pointer-events: auto;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.joystick-knob {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(220, 220, 220, 0.9);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.ctrl-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(50, 50, 50, 0.7);
    color: white;
    border: 2px solid #555;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    /* iOS Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* Internet Explorer/Edge */
    touch-action: none;
    /* Prevent zooming/scrolling on iOS */
    cursor: pointer;
}

.ctrl-btn:active {
    background: rgba(100, 100, 100, 0.9);
    border-color: #ffd700;
}

.action-pad {
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.toggle-ctrl {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    margin-bottom: 10px;
}

.dpad-zone {
    width: 140px;
    height: 140px;
    position: relative;
    pointer-events: auto;
}

.dpad-btn {
    position: absolute;
    width: 45px;
    height: 45px;
    background: rgba(50, 50, 50, 0.7);
    color: white;
    border: 2px solid #555;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    touch-action: none;
    user-select: none;
}

.dpad-btn:active {
    background: rgba(100, 100, 100, 0.9);
    border-color: #ffd700;
}

.dpad-btn.up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-btn.down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-btn.left {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.dpad-btn.right {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.ctrl-btn.act {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    font-size: 1rem;
    font-weight: bold;
    background: rgba(200, 150, 0, 0.8);
    border-color: #ffea00;
    transition: transform 0.1s ease, background 0.1s ease;
}

.ctrl-btn.act:active {
    transform: scale(0.9);
    background: rgba(255, 200, 0, 0.9);
}

/* Weapon Hotbar */
.weapon-hotbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px;
    border-radius: 8px;
    border: 2px solid #555;
    z-index: 100;
}

.hotbar-slot {
    width: 60px;
    height: 60px;
    background: rgba(50, 50, 50, 0.8);
    border: 2px solid #444;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.1s ease;
    user-select: none;
}

.hotbar-slot:hover:not(.locked) {
    background: rgba(80, 80, 80, 0.9);
}

.hotbar-slot.active {
    border-color: #ffd700;
    background: rgba(100, 80, 20, 0.9);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    transform: scale(1.05);
}

.hotbar-slot.locked {
    opacity: 0.3;
    cursor: not-allowed;
}

.hotbar-key {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 1px 1px 0 #000;
}

.hotbar-icon {
    font-size: 1.8rem;
}

/* Modal Overlay base */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.modal-content {
    background: #2a2a2a;
    border: 2px solid #555;
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    pointer-events: auto;
}

.modal-content .shop-item {
    background: #333;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 8px;
    border: 1px solid #444;
}

/* Responsive adjustments for Mobile/Tablets */
@media (max-width: 900px) {
    #gameContainer {
        display: block;
        width: 100vw;
        height: 100vh;
        padding: 0;
        margin: 0;
        border-radius: 0;
        position: relative;
    }

    .weapon-hotbar {
        left: unset;
        right: 15px;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%) scale(0.85);
        flex-direction: column;
    }

    .canvas-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .mobile-top-bar {
        display: flex;
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
        justify-content: space-between;
        align-items: flex-start;
        z-index: 100;
        pointer-events: none;
    }

    .left-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .right-actions {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }

    .close-panel-btn {
        display: block;
    }

    .ctrl-btn.act {
        width: 100px;
        height: 100px;
        font-size: 1.4rem;
    }

    .mobile-top-bar button {
        pointer-events: auto;
        background: rgba(30, 30, 30, 0.8);
        color: #ffd700;
        border: 2px solid #555;
        padding: 8px 15px;
        border-radius: 20px;
        font-weight: bold;
        cursor: pointer;
        backdrop-filter: blur(4px);
    }

    /* Panels become absolute overlays */
    .side-panel {
        position: absolute;
        z-index: 101;
        background: rgba(34, 34, 34, 0.95);
        display: none;
        /* hidden by default */
        border: 1px solid #555;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(4px);
    }

    .side-panel.active-overlay {
        display: flex;
    }

    .side-panel.left {
        /* Leaderboard & Shop overlay */
        top: 60px;
        left: 10px;
        bottom: 150px;
        width: 250px;
        height: auto;
        max-width: 90vw;
        border-radius: 12px;
    }

    .side-panel.right {
        /* Chat overlay */
        top: 60px;
        right: 10px;
        bottom: 150px;
        width: 320px;
        height: auto;
        max-width: 90vw;
        border-radius: 12px;
    }

    .side-panel.right.expanded {
        height: auto;
        /* Reset older rule */
    }

    .mobile-only-btn {
        display: block;
    }

    .mobile-controls {
        display: flex;
        bottom: 20px;
    }

    #leaderboardPanel .controls-info,
    #leaderboardPanel .desktop-shop {
        display: none !important;
    }
}

/* Version Label */
#versionLabel {
    position: fixed;
    bottom: 10px;
    right: 10px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1000;
}