* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #0b1120;
    --panel: #131c31;
    --panel-2: #1b2742;
    --border: #2a3a5c;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --p1: #0284c7;
    --p2: #dc2626;
    --spec: #7c3aed;
    --ok: #10b981;
    --warn: #f59e0b;
    --err: #ef4444;
}
body {
    background: radial-gradient(circle at top, #16223d 0%, var(--bg) 65%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
}
button, input, select { font-family: inherit; }

/* ---------- LOBBY ---------- */
.lobby-wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 18px 14px 36px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.hero-header {
    background: linear-gradient(135deg, #162447, #0f172a);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}
.brand h1 { font-size: 20px; font-weight: 800; letter-spacing: 0.3px; }
.brand p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.header-right { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.nick-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 10px;
}
.nick-box label { font-size: 11px; color: var(--muted); font-weight: 700; }
.nick-box input {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    width: 130px;
    outline: none;
}
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 7px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--err); box-shadow: 0 0 8px var(--err); }

.lobby-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
}
@media (max-width: 860px) {
    .lobby-grid { grid-template-columns: 1fr; }
}
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.card h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.7px; color: #cbd5e1; }

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #0ea5e9, #0369a1); border-color: #38bdf8; }
.btn-accent { background: linear-gradient(135deg, #10b981, #047857); border-color: #34d399; }
.btn-secondary { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn-sm { padding: 6px 10px; font-size: 11px; border-radius: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--muted); font-weight: 700; }
.field input[type="text"],
.field input[type="password"],
.field select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
}
.field input:focus { border-color: #38bdf8; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.row-inline > * { flex: 1; }
.check-label { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #cbd5e1; cursor: pointer; }
.divider { height: 1px; background: var(--border); margin: 2px 0; }
.alert-msg { font-size: 12px; color: #fca5a5; min-height: 16px; }

.rooms-list { display: flex; flex-direction: column; gap: 10px; }
.room-item {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.room-main { display: flex; flex-direction: column; gap: 4px; }
.room-title { font-size: 15px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.code-tag {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: #0f172a;
    border: 1px solid #334155;
    color: #38bdf8;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 6px;
}
.room-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 10px; }
.score-pill { color: #ffd54f; font-weight: 800; }
.empty-rooms { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); border-radius: 10px; }

/* Chat panel (shared Lobby & Room) */
.chat-log {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    height: 170px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
}
.chat-line { line-height: 1.35; word-break: break-word; }
.chat-author { font-weight: 800; margin-right: 5px; }
.chat-author.p1 { color: #38bdf8; }
.chat-author.p2 { color: #f87171; }
.chat-author.spectator { color: #c084fc; }
.chat-form { display: flex; gap: 6px; }
.chat-form input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    outline: none;
}

/* ---------- GAME ROOM ---------- */
body.room-body {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px 8px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.room-topbar {
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 6px;
    background: rgba(19, 28, 49, 0.92);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.tb-group { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.role-badge {
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
}
.role-badge.p1 { background: linear-gradient(135deg, #0284c7, #0369a1); border: 1px solid #38bdf8; }
.role-badge.p2 { background: linear-gradient(135deg, #dc2626, #991b1b); border: 1px solid #f87171; }
.role-badge.spectator { background: linear-gradient(135deg, #7c3aed, #5b21b6); border: 1px solid #c084fc; }
.score-badge {
    background: #0f172a;
    border: 1px solid #334155;
    color: #ffd54f;
    font-size: 12px;
    font-weight: 900;
    padding: 3px 9px;
    border-radius: 8px;
}
.tb-btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: #e2e8f0;
    font-size: 10px;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 7px;
    cursor: pointer;
    text-decoration: none;
}
.tb-btn:hover:not(:disabled) { border-color: #60a5fa; }
.tb-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tb-btn.mode-2p { color: #ffd54f; border-color: #ffd54f; }
.tb-btn.mode-1p { color: #94a3b8; border-color: #64748b; }
.ping-pill {
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 8px;
    background: #0f172a;
    border: 1px solid #334155;
}
.ping-good { color: #10b981; }
.ping-med { color: #f59e0b; }
.ping-bad { color: #ef4444; }

.screen-wrap {
    width: 100%;
    max-width: 420px;
    height: 41vh;
    background: #000;
    border: 3px solid #334155;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: inset 0 0 12px rgba(0,0,0,0.8), 0 6px 18px rgba(0,0,0,0.45);
}
.screen-wrap img {
    height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}
.screen-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 17, 32, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    text-align: center;
    font-size: 13px;
}
.hidden { display: none !important; }

/* Spectator control bar */
.spec-bar {
    width: 100%;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid #6d28d9;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}
.spec-bar p { font-size: 13px; color: #ddd6fe; }

/* Virtual Phone Deck (same layout + masks as NetControllerUI) */
.phone-deck {
    width: 100%;
    max-width: 390px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    justify-content: center;
    touch-action: none;
}
.nav-deck { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.softkey {
    width: 68px;
    height: 44px;
    background: linear-gradient(180deg, #334155, #1e293b);
    border: 1px solid #475569;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #f1f5f9;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    touch-action: none;
}
.softkey .sub { font-size: 8px; color: #94a3b8; font-weight: 600; margin-top: 1px; }
.softkey.active, .softkey:active { background: #2563eb; border-color: #60a5fa; transform: scale(0.95); }
.nav-dpad {
    width: 132px;
    height: 82px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    align-items: center;
    justify-items: center;
}
.dpad-key {
    width: 39px;
    height: 25px;
    background: linear-gradient(180deg, #334155, #1e293b);
    border: 1px solid #475569;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    color: #cbd5e1;
    touch-action: none;
}
.dpad-key.active, .dpad-key:active { background: #0284c7; color: #fff; transform: scale(0.92); }
.d-up { grid-column: 2; grid-row: 1; }
.d-left { grid-column: 1; grid-row: 2; }
.d-ok { grid-column: 2; grid-row: 2; background: #0f766e; border-color: #14b8a6; color: #fff; font-size: 10px; }
.d-right { grid-column: 3; grid-row: 2; }
.d-down { grid-column: 2; grid-row: 3; }

.num-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 2px 8px; }
.num-key {
    height: 45px;
    background: linear-gradient(180deg, #242c3d, #181f2c);
    border: 1px solid #334155;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
}
.num-key .main-char { font-size: 16px; font-weight: 700; color: #f8fafc; line-height: 1; }
.num-key .sub-char { font-size: 9px; color: #94a3b8; margin-top: 2px; font-weight: 700; text-transform: uppercase; }
.num-key.active, .num-key:active { background: #2563eb; border-color: #60a5fa; transform: scale(0.94); }
.key-pass { background: linear-gradient(180deg, #0369a1, #075985); border-color: #38bdf8; }
.key-shoot { background: linear-gradient(180deg, #c2410c, #9a3412); border-color: #fb923c; }
.key-trick { background: linear-gradient(180deg, #6d28d9, #5b21b6); border-color: #c084fc; }

/* Chat drawer & modal */
.chat-drawer {
    position: fixed;
    right: 12px;
    bottom: 12px;
    width: 300px;
    max-width: calc(100vw - 24px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.55);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-drawer-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 800; }
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 22, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 16px;
}
.modal-card {
    width: 100%;
    max-width: 360px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.toast {
    position: fixed;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f766e;
    color: #fff;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    z-index: 60;
    box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
