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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: #fff;
}

.screen {
    display: none !important;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex !important;
    justify-content: center;
    align-items: center;
}

/* Ensure only one screen is ever visible */
body > .screen:not(.active) {
    visibility: hidden !important;
    pointer-events: none !important;
}

.container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.container.wide {
    max-width: 800px;
}

h1 {
    text-align: center;
    font-size: 3rem;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(255, 100, 0, 0.8);
    color: #ff6600;
    letter-spacing: 4px;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #fff;
}

h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #aaa;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #aaa;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: #fff;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: #ff6600;
    box-shadow: 0 0 10px rgba(255, 100, 0, 0.3);
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn.primary {
    background: linear-gradient(135deg, #ff6600, #ff9933);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 100, 0, 0.4);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 100, 0, 0.6);
}

.btn.danger {
    background: linear-gradient(135deg, #cc0000, #ff3333);
    color: #fff;
}

.btn.danger:hover {
    transform: translateY(-2px);
}

.btn:not(.primary):not(.danger) {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn:not(.primary):not(.danger):hover {
    background: rgba(255, 255, 255, 0.3);
}

.error {
    color: #ff4444;
    font-size: 0.9rem;
    margin-top: 10px;
    text-align: center;
}

/* Lobby Browser */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.player-info {
    color: #aaa;
    font-size: 0.9rem;
}

.player-info span {
    color: #ff6600;
    font-weight: bold;
}

.lobby-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.lobby-actions input {
    flex: 1;
    min-width: 150px;
}

.lobby-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.no-lobbies {
    color: #666;
    text-align: center;
    padding: 50px;
}

.lobby-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.lobby-item:hover {
    background: rgba(255, 255, 255, 0.15);
}

.lobby-item:last-child {
    margin-bottom: 0;
}

.lobby-item-info h4 {
    color: #fff;
    margin-bottom: 5px;
}

.lobby-item-info span {
    color: #888;
    font-size: 0.85rem;
}

.lobby-item-info .in-game {
    color: #ff6600;
}

/* Lobby Room */
.lobby-room-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 768px) {
    .lobby-room-container {
        grid-template-columns: 1fr;
    }
}

.lobby-info {
    display: flex;
    flex-direction: column;
}

.players-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    flex: 1;
    min-height: 150px;
    margin-bottom: 20px;
}

.player-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    margin-bottom: 8px;
}

.player-item:last-child {
    margin-bottom: 0;
}

.player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 10px;
}

.bot-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.bot-buttons .btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.9rem;
    background: rgba(100, 100, 255, 0.3);
    border: 1px solid rgba(100, 100, 255, 0.5);
}

.bot-buttons .btn:hover {
    background: rgba(100, 100, 255, 0.5);
}

.lobby-buttons {
    display: flex;
    gap: 10px;
}

.lobby-buttons .btn {
    flex: 1;
}

/* Chat */
.chat-container {
    display: flex;
    flex-direction: column;
}

.chat-messages {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    flex: 1;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.chat-messages.small {
    min-height: 100px;
    max-height: 150px;
}

.chat-message {
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.chat-message:last-child {
    margin-bottom: 0;
}

.chat-message .name {
    font-weight: bold;
    color: #ff6600;
}

.chat-message .text {
    color: #ddd;
}

.chat-message.system {
    color: #888;
    font-style: italic;
}

.chat-input-container {
    display: flex;
    gap: 10px;
}

.chat-input-container input {
    flex: 1;
}

/* Game Screen */
#game-screen.active {
    padding: 10px;
    align-items: flex-start;
    justify-content: center;
}

.game-layout {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.game-sidebar {
    width: 160px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-player {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 10px;
    border: 2px solid transparent;
}

.sidebar-player.current-player {
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar-player.dead {
    opacity: 0.4;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.player-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-name {
    font-size: 0.85rem;
    font-weight: bold;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.stat-row canvas {
    display: block;
}

.game-main {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-header {
    width: 100%;
    margin-bottom: 10px;
    display: flex;
    justify-content: flex-end;
}

.btn.small {
    padding: 6px 12px;
    font-size: 0.75rem;
}

/* Mobile Stats Bar - hidden on desktop */
.mobile-stats {
    display: none;
}

#game-canvas {
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.game-chat {
    width: 100%;
    max-width: 600px;
    margin-top: 10px;
}

.game-chat .chat-messages {
    min-height: 60px;
    max-height: 100px;
}

.game-chat input {
    font-size: 0.9rem;
    padding: 8px 12px;
}

/* Responsive: stack sidebar on small screens */
@media (max-width: 800px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
    }

    .game-sidebar {
        width: 100%;
        max-width: 600px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .sidebar-player {
        flex: 0 0 auto;
        min-width: 140px;
    }
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: visible;
    opacity: 1;
}

.overlay.hidden {
    display: none !important;
    visibility: hidden;
    opacity: 0;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
}

.overlay-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #ff6600;
}

.overlay-content p {
    font-size: 1.2rem;
    margin-bottom: 10px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: rgba(30, 30, 50, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 10px;
    color: #ff6600;
}

.modal-content .hint {
    text-align: center;
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.keybind-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.keybind-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.keybind-row span {
    color: #ccc;
}

.keybind-btn {
    padding: 8px 16px;
    min-width: 100px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.keybind-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.keybind-btn.listening {
    border-color: #ff6600;
    background: rgba(255, 100, 0, 0.2);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons .btn {
    flex: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 100, 0, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 100, 0, 0.7);
}

/* Controls hint */
.controls-hint {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #888;
}

.controls-hint kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    margin: 0 2px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #444;
    border-radius: 26px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #ff6600;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

/* Touch Controls */
.touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 600px;
    padding: 20px;
    margin-top: 10px;
}

.touch-controls.hidden {
    display: none;
}

/* D-Pad Layout */
.touch-dpad {
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 5px;
}

.touch-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 60px;
    height: 60px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 24px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

.touch-btn:active,
.touch-btn.active {
    background: rgba(255, 100, 0, 0.5);
    border-color: #ff6600;
}

.dpad-up { grid-area: up; }
.dpad-down { grid-area: down; }
.dpad-left { grid-area: left; }
.dpad-right { grid-area: right; }

.bomb-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    font-size: 32px;
}

/* Small modal variant */
.modal-content.small {
    max-width: 320px;
    text-align: center;
}

.modal-content.small h3 {
    color: #ff6600;
    font-size: 1.3rem;
    margin-bottom: 15px;
}

.modal-content.small p {
    color: #ccc;
    margin-bottom: 20px;
}

/* Mobile Game Screen - Full viewport fixed layout */
@media (max-width: 650px) {
    /* Prevent scrolling when game is active */
    body.game-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    #game-screen.active {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100dvh;
        padding: 0;
        display: flex !important;
        flex-direction: column;
        overflow: hidden;
        touch-action: none;
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    }

    .game-layout {
        flex-direction: column;
        height: 100%;
        width: 100%;
        gap: 0;
        background: transparent;
    }

    /* Hide sidebar and chat on mobile */
    .game-sidebar,
    .game-chat,
    .controls-hint {
        display: none !important;
    }

    .game-main {
        flex: 1;
        width: 100%;
        display: flex;
        flex-direction: column;
        padding: 0;
        min-height: 0; /* Important for flex shrinking */
        background: transparent;
    }

    .game-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 12px;
        margin: 0;
        flex-shrink: 0;
        background: rgba(0, 0, 0, 0.4);
    }

    /* Mobile Stats Bar */
    .mobile-stats {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .mobile-stats .stat-group {
        display: flex;
        align-items: center;
        gap: 2px;
    }

    .mobile-stats canvas {
        display: block;
    }

    /* Canvas container takes remaining space above controls */
    #game-canvas {
        flex: 1;
        width: 100%;
        height: auto;
        max-height: calc(100dvh - 220px); /* Leave room for controls */
        object-fit: contain;
        border-radius: 0;
    }

    /* Touch controls fixed at bottom */
    .touch-controls {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px 20px;
        padding-bottom: max(15px, env(safe-area-inset-bottom));
        background: linear-gradient(to top, rgba(0,0,0,0.9), rgba(0,0,0,0.7));
        margin: 0;
        max-width: none;
        height: auto;
        z-index: 100;
    }

    /* Larger D-pad for mobile - use viewport units */
    .touch-dpad {
        grid-template-columns: repeat(3, 18vw);
        grid-template-rows: repeat(3, 18vw);
        gap: 2vw;
    }

    .touch-btn {
        width: 18vw;
        height: 18vw;
        max-width: 70px;
        max-height: 70px;
        font-size: 7vw;
        border-radius: 12px;
        border-width: 3px;
    }

    .bomb-btn {
        width: 25vw;
        height: 25vw;
        max-width: 100px;
        max-height: 100px;
        font-size: 10vw;
        border-radius: 50%;
    }
}

/* Even smaller screens */
@media (max-width: 400px) {
    .touch-dpad {
        grid-template-columns: repeat(3, 16vw);
        grid-template-rows: repeat(3, 16vw);
    }

    .touch-btn {
        width: 16vw;
        height: 16vw;
        font-size: 6vw;
    }

    .bomb-btn {
        width: 22vw;
        height: 22vw;
        font-size: 9vw;
    }
}
