:root {
    --bg-color: #05070a;
    --text-color: #ffffff;
    --primary: #fb7185;
    --secondary: #3b82f6;
    --accent: #10b981;
    --glass-bg: rgba(15, 23, 42, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: 'Press Start 2P', cursive;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Retro Grid Background */
body::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: 
        linear-gradient(rgba(131, 24, 67, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(131, 24, 67, 0.1) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: -1;
}

/* CRT Scanline effect */
body::after {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 2000;
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
}

/* LOBBY UI */
.lobby {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 500;
    padding: 1rem;
}

.lobby-content {
    background: var(--glass-bg);
    border: 2px solid var(--accent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: 0 0 40px rgba(16, 185, 129, 0.2), inset 0 0 20px rgba(0,0,0,0.5);
    width: 100%;
    max-width: 480px;
    position: relative;
}

.lobby-content::before {
    content: "";
    position: absolute;
    top: -5px; left: -5px; right: -5px; bottom: -5px;
    border: 1px solid rgba(16, 185, 129, 0.4);
    pointer-events: none;
}

h1 {
    font-size: clamp(1.2rem, 5vw, 2.2rem);
    color: var(--primary);
    text-shadow: 4px 4px 0px #881337;
    margin-bottom: 1rem;
    letter-spacing: -2px;
}

.subtitle {
    font-family: 'Inter', sans-serif;
    color: var(--secondary);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 2rem;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.join-container {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.join-container input {
    width: 100%;
    padding: 1.2rem;
    border: 2px solid var(--secondary);
    background: #000;
    color: var(--accent);
    font-size: 1rem;
    font-family: 'Press Start 2P', cursive;
    text-align: center;
    text-transform: uppercase;
}

.join-container input:focus {
    outline: none;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: #475569;
    font-size: 0.6rem;
    margin: 0.5rem 0;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 2px dashed rgba(255,255,255,0.1);
}
.divider span { padding: 0 10px; }

button {
    font-family: 'Press Start 2P', cursive;
    color: white;
    border: none;
    padding: 1.2rem;
    font-size: 0.8rem;
    cursor: pointer;
    box-shadow: 4px 4px 0px #000;
    transition: all 0.1s;
}

button:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px #000;
}

.btn-primary { background-color: var(--accent); }
.btn-secondary { background-color: var(--secondary); }
.btn-back { background: #1e293b; font-size: 0.6rem; margin-top: 1rem; color: #94a3b8; }

/* GAME UI */
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100vh;
    padding: calc(var(--safe-area-top) + 0.5rem) 0.5rem var(--safe-area-bottom);
    justify-content: space-between;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    max-width: 800px;
    padding: 0 1rem;
    z-index: 10;
}

.room-info {
    font-size: 0.5rem;
    color: #64748b;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.highlight { color: var(--accent); font-weight: bold; }
.badge { background: var(--primary); padding: 0.2rem 0.4rem; margin-top: 0.2rem; display: inline-block; }

.score-board {
    display: flex;
    gap: 1.5rem;
    text-align: right;
}

.score { font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.score.p1 { color: var(--accent); }
.score.p2 { color: var(--secondary); }
.score .label { font-size: 0.5rem; color: #475569; }

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
}

.canvas-wrapper {
    position: relative;
    border: 4px solid #1e293b;
    background: #000;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 4/3;
}

#game-canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
}

.wait-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--primary);
    font-size: 0.8rem;
    text-align: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
}
.wait-overlay.show { opacity: 1; pointer-events: all; }

/* MOBILE CONTROLS */
.mobile-controls {
    display: flex;
    width: 100%;
    max-width: 800px;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    user-select: none;
    pointer-events: auto;
}

.dpad, .actions {
    display: flex;
    gap: 0.8rem;
}

.ctrl-btn {
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    color: white;
    box-shadow: none;
    padding: 0;
}

.ctrl-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

.action-btn {
    background: rgba(251, 113, 133, 0.2);
    border-color: rgba(251, 113, 133, 0.4);
    font-size: 0.5rem;
    width: 80px;
}

#ctrl-jump {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
}

.controls-hint {
    font-family: 'Inter', sans-serif;
    font-size: 0.6rem;
    color: #475569;
    text-align: center;
    margin-top: 0.5rem;
    line-height: 1.5;
}

@media (max-width: 600px) {
    .mobile-controls { display: flex !important; }
    .controls-hint { display: none; }
}

@media (min-width: 1024px) {
    .mobile-controls { display: none !important; }
}
