@font-face {
    font-family: 'PressStart';
    src: url('https://fonts.gstatic.com/s/pressstart2p/v15/e3t4euO8T-267oIAQAu6jDQyK3nVivM.woff2') format('woff2');
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    overflow: hidden;
    font-family: 'Press Start 2P', 'PressStart', monospace;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    cursor: default;
}

/* ===== Chat Panel ===== */
#chat-panel {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 280px;
    max-height: 200px;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid #7C7C7C;
    padding: 6px;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    font-size: 8px;
    line-height: 1.6;
    color: #FCFCFC;
    max-height: 150px;
    scrollbar-width: thin;
    scrollbar-color: #7C7C7C #000;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #7C7C7C;
}

#chat-messages .msg {
    padding: 2px 0;
    opacity: 1;
    transition: opacity 0.5s;
}

#chat-messages .msg.fade {
    opacity: 0.3;
}

#chat-messages .msg .name-p1 {
    color: #FC9838;
}

#chat-messages .msg .name-p2 {
    color: #80D010;
}

#chat-messages .msg .name-system {
    color: #7C7C7C;
}

#chat-input {
    background: #1a1a1a;
    border: 1px solid #7C7C7C;
    color: #FCFCFC;
    font-family: inherit;
    font-size: 8px;
    padding: 4px;
    outline: none;
    margin-top: 4px;
}

#chat-input:focus {
    border-color: #FC9838;
}

/* ===== Touch Controls ===== */
#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 180px;
    pointer-events: none;
    z-index: 20;
}

#dpad {
    position: absolute;
    left: 20px;
    bottom: 20px;
    width: 130px;
    height: 130px;
    pointer-events: auto;
}

.dpad-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active, .dpad-btn.active {
    background: rgba(252, 152, 56, 0.5);
    border-color: #FC9838;
}

.dpad-btn[data-dir="up"] { top: 0; left: 43px; }
.dpad-btn[data-dir="left"] { top: 43px; left: 0; }
.dpad-btn[data-dir="right"] { top: 43px; left: 86px; }
.dpad-btn[data-dir="down"] { top: 86px; left: 43px; }

#fire-btn {
    position: absolute;
    right: 30px;
    bottom: 35px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(252, 60, 60, 0.3);
    border: 3px solid rgba(252, 60, 60, 0.6);
    color: rgba(255, 255, 255, 0.7);
    font-family: inherit;
    font-size: 10px;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

#fire-btn:active, #fire-btn.active {
    background: rgba(252, 60, 60, 0.6);
    border-color: #FC3C3C;
}

/* ===== UI Overlay ===== */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #FCFCFC;
    font-size: 10px;
    pointer-events: auto;
}

#ui-overlay input[type="text"] {
    background: #1a1a1a;
    border: 2px solid #FC9838;
    color: #FCFCFC;
    font-family: inherit;
    font-size: 10px;
    padding: 8px 12px;
    text-align: center;
    outline: none;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#ui-overlay .menu-item {
    padding: 8px 16px;
    margin: 4px 0;
    cursor: pointer;
    transition: color 0.1s;
}

#ui-overlay .menu-item:hover,
#ui-overlay .menu-item.selected {
    color: #FC9838;
}

#ui-overlay .menu-item::before {
    content: '';
    display: inline-block;
    width: 16px;
}

#ui-overlay .menu-item.selected::before {
    content: '▸';
}

#ui-overlay .btn {
    background: none;
    border: 2px solid #FC9838;
    color: #FC9838;
    font-family: inherit;
    font-size: 10px;
    padding: 8px 20px;
    cursor: pointer;
    margin: 4px;
}

#ui-overlay .btn:hover {
    background: #FC9838;
    color: #000;
}

#ui-overlay .btn-secondary {
    border-color: #7C7C7C;
    color: #7C7C7C;
}

#ui-overlay .btn-secondary:hover {
    background: #7C7C7C;
    color: #000;
}

#ui-overlay .room-code {
    font-size: 24px;
    color: #FC9838;
    letter-spacing: 8px;
    margin: 16px 0;
}

#ui-overlay .share-link {
    font-size: 7px;
    color: #7C7C7C;
    word-break: break-all;
    max-width: 300px;
    text-align: center;
    margin: 8px 0;
}

/* ===== Fullscreen Button ===== */
#fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #7C7C7C;
    color: #7C7C7C;
    font-size: 16px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#fullscreen-btn:hover {
    border-color: #FCFCFC;
    color: #FCFCFC;
}

/* ===== Performance Overlay ===== */
#perf-overlay {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 7px;
    color: #80D010;
    z-index: 25;
    pointer-events: none;
    text-shadow: 1px 1px 0 #000;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: #000;
}

::-webkit-scrollbar-thumb {
    background: #3C3C3C;
}

.hidden {
    display: none !important;
}

/* ===== Map Editor ===== */
.editor-toolbar {
    display: flex;
    gap: 4px;
    margin: 8px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.editor-toolbar .tile-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #3C3C3C;
    cursor: pointer;
    image-rendering: pixelated;
}

.editor-toolbar .tile-btn.active {
    border-color: #FC9838;
}

/* ===== Settings ===== */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 300px;
    margin: 8px 0;
    font-size: 8px;
}

.settings-row input[type="range"] {
    width: 120px;
    accent-color: #FC9838;
}

.key-bind {
    padding: 4px 8px;
    border: 1px solid #7C7C7C;
    min-width: 60px;
    text-align: center;
    cursor: pointer;
    font-size: 8px;
}

.key-bind:hover, .key-bind.listening {
    border-color: #FC9838;
    color: #FC9838;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 600px) {
    #chat-panel {
        width: 200px;
        bottom: 185px;
    }

    #fullscreen-btn {
        top: 4px;
        right: 4px;
    }
}

@media (orientation: portrait) and (max-width: 600px) {
    body {
        align-items: flex-start;
        padding-top: 10px;
    }
}
