* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    cursor: none !important; /* Replaced everywhere by the crown VIP cursor, see #mouse-vip-cursor */
}

body {
    background: #0d0d0d;
    color: #e0e0e0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 32px 48px;
    gap: 28px;
}

/* ── Header ────────────────────────────────────────────────────────────── */

#lobby-header {
    width: 100%;
    max-width: 1000px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#lobby-header h1 {
    font-size: 1.8rem;
    letter-spacing: 1px;
}
#conn-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #666;
    font-family: monospace;
}
#status { font-size: 1rem; line-height: 1; transition: color 0.3s; }
#status.connected    { color: #4f8; }
#status.disconnected { color: #333; }
#status.connecting   { color: #fa4; }
#status.error        { color: #f44; }

/* ── Room code ─────────────────────────────────────────────────────────── */

#room-code-section {
    text-align: center;
}
#room-code-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}
#room-code-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 2px;
}
#room-code {
    font-size: 4rem;
    font-weight: bold;
    letter-spacing: 10px;
    color: #8af;
    font-family: monospace;
}
#lobby-controller-id {
    font-size: 0.75rem;
    color: #777;
    font-family: monospace;
}
#room-code-hint {
    font-size: 0.85rem;
    color: #e8c547;
    background: rgba(232, 197, 71, 0.12);
    border: 1px solid rgba(232, 197, 71, 0.4);
    border-radius: 6px;
    padding: 6px 12px;
    margin-top: 8px;
}
/* Only set `display` when not hidden, since `hidden` makes browser set `display: none` */
#room-code-hint:not([hidden]) {
    display: inline-block;
}

#room-qr-section {
    margin-top: 12px;
}
/* Only set `display` when not hidden, since `hidden` makes browser set `display: none` */
#room-qr-section:not([hidden]) {
    display: flex;
    justify-content: center;
}
#room-qr-code {
    width: 160px;
    height: 160px;
    background: #fff;
    border-radius: 8px;
    padding: 8px;
}
#room-qr-link:hover #room-qr-code {
    background: #e8c547;
    box-shadow: 0 0 0 3px #0d0d0d, 0 0 0 6px #ffd700;
}
#room-qr-notice {
    max-width: 240px;
    color: #e8c547;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: left;
}

@media (max-width: 549px) {
    #room-code-row {
        flex-direction: column;
        gap: 4px;
    }
    #room-qr-section {
        order: -1;
        margin-top: 0;
    }
    #room-qr-notice {
        text-align: center;
    }
    #room-code-label {
        display: none;
    }
    #room-code {
        font-size: 0.875rem;
        font-weight: normal;
        letter-spacing: 1px;
    }
}

/* ── Outgoing game command track ──────────────────────────────────────── */
/* Global runway (distinct from the per-player .player-input-track) showing
    every GsGameCmd the lobby sends out, in order, regardless of recipient. See
   sendGameCmd() in lobby.js. */
#gamecmd-track-label {
    margin-top: 18px;
    font-size: 0.7rem;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}
#gamecmd-track {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 26px;
    margin: 6px auto 0;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid #2a2a2a;
    border-radius: 6px;
}
.gamecmd-token {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    height: 18px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-family: monospace;
    font-weight: bold;
    white-space: nowrap;
    line-height: 1;
    animation: gamecmd-token-travel 2.2s linear forwards;
}
@keyframes gamecmd-token-travel {
    from { left: 0%; opacity: 1; }
    to   { left: 100%; opacity: 0; }
}
.gamecmd-token.cmd-room   { background: #8af; color: #111; }
.gamecmd-token.cmd-vip    { background: #da4; color: #111; }
.gamecmd-token.cmd-lobby  { background: #a6f; color: #fff; }
.gamecmd-token.cmd-conn   { background: #555; color: #ccc; }
.gamecmd-token-count {
    font-weight: normal;
    opacity: 0.8;
}

/* ── Players ───────────────────────────────────────────────────────────── */

#players-section {
    width: 100%;
    max-width: 1000px;
}
#players-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
#players-section h2 {
    font-size: 0.9rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0;
}
#players-count {
    color: #555;
}
#players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
#players-empty-hint {
    color: #555;
    font-size: 0.9rem;
    grid-column: 1 / -1;
}
.player-card {
    background: #161616;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}
.player-card.is-vip {
    box-shadow: 0 0 0 1px rgba(221, 170, 68, 0.3);
}
.player-card.disconnected {
    opacity: 0.5;
}
.player-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.player-color {
    flex: none;
    width: 16px;
    height: 16px;
    border: 1px solid #777;
    border-radius: 2px;
}
.player-name {
    font-size: 1rem;
    font-weight: 600;
    word-break: break-word;
}
.player-id {
    font-size: 0.7rem;
    color: #555;
    font-family: monospace;
}
.vip-badge {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    line-height: 1;
    color: #fc6;
    border: 1px solid #da4;
    border-radius: 50%;
    background: rgba(221, 170, 68, 0.15);
}
.vip-badge[hidden] {
    display: none;
}

/* Fixed-height "runway" for input visualization tokens (see visualizeInput()
   in lobby.js). Its width just follows the card's width - tokens travel
   using percentage-based `left`, so they always span the full runway
   edge-to-edge no matter how wide the card ends up in the responsive grid. */
.player-input-track {
    position: relative;
    height: 20px;
    margin-top: 2px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
}
.input-token {
    position: absolute;
    left: 0;
    top: 50%;
    font-size: 0.75rem;
    font-weight: bold;
    font-family: monospace;
    line-height: 1;
    transform: translateY(-50%);
    animation: input-token-travel 1.4s linear forwards;
}
.input-token-glyph {
    display: inline-block;
    transform: rotate(var(--rotate, 0deg));
}
@keyframes input-token-travel {
    from { left: 0%; opacity: 1; }
    to   { left: 100%; opacity: 0; }
}
.input-token.dir-n,
.input-token.dir-s,
.input-token.dir-e,
.input-token.dir-w,
.input-token.stop,
.input-token.ping,
.input-token.join,
.input-token.leave,
.input-token.rename,
.input-token.vip-take,
.input-token.vip-drop,
.input-token.joy {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    font-size: 0.65rem;
}
.input-token.dir-n { background: #fd4; color: #111; }
.input-token.dir-s { background: #4f8; color: #111; }
.input-token.dir-e { background: #f55; color: #fff; }
.input-token.dir-w { background: #48f; color: #fff; }
.input-token.stop  { background: #888; color: #111; }
.input-token.ping  { background: #555; color: #ccc; font-size: 0.55rem; }
.input-token.join      { background: #4f8; color: #111; }
.input-token.leave     { background: #a33; color: #fff; }
.input-token.rename    { background: #a6f; color: #fff; }
.input-token.vip-take  { background: #555; color: #ccc; font-size: 0.55rem; }
.input-token.vip-drop  { background: #555; color: #f55; font-size: 0.65rem; }
.input-token.joy   { background: #0ff2; border: 1px solid #0ff; color: #0ff; }

/* ── Menu ──────────────────────────────────────────────────────────────── */

#menu-section {
    width: 100%;
    max-width: 1000px;
}
/* ── Mouse VIP crown cursor ────────────────────────────────────────────────
   Follows the real cursor position (see lobby.js), replacing the hidden OS
    pointer. Visible while the mouse holds VIP, then fades out over
    MOUSE_VIP_FADE_MS in lobby.js, which must match the transition below. */
#mouse-vip-cursor {
    position: fixed;
    top: 0;
    left: 0;
    font-size: 28px;
    line-height: 1;
    transform: translate(-4px, -4px);
    pointer-events: none;
    user-select: none;
    z-index: 9999;
    opacity: 0;
}
#mouse-vip-cursor.visible {
    opacity: 1;
}
#mouse-vip-cursor.visible.fade-out {
    transition: opacity 2s linear;
    opacity: 0;
}

#menu-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #2a2a2a;
    margin-bottom: 20px;
    padding-bottom: 5px;
}
.menu-tab-btn {
    background: none;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    color: #999;
    font-size: 1rem;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.menu-tab-btn:hover { border-color: #444; color: #ccc; }
.menu-tab-btn.active {
    color: #fff;
    background: #1b1b2e;
    border-color: #4af;
}
.menu-tab-btn.focused {
    outline: 2px solid #0ff;
    outline-offset: 2px;
}
#hold-mouse-vip {
    margin-left: auto;
    background: #231d10;
    border: 1px solid #8b702e;
    border-radius: 6px;
    color: #fc6;
    font-size: 0.85rem;
    padding: 10px 20px;
    white-space: nowrap;
    cursor: pointer;
}
#hold-mouse-vip:hover { border-color: #fc6; }
#hold-mouse-vip:focus-visible { outline: 2px solid #0ff; outline-offset: 2px; }
#hold-mouse-vip[aria-pressed="true"] {
    background: #e8bc4c;
    border-color: #ffe18a;
    color: #201705;
    box-shadow: inset 0 2px 4px #73500e;
}
#vip-indicator {
    margin-left: auto;
    font-size: 0.85rem;
    color: #fc6;
}
#hold-mouse-vip:not([hidden]) + #vip-indicator { margin-left: 0; }

.tab-panel[hidden] { display: none; }

#games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.game-card {
    background: #161616;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    color: #e0e0e0;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.game-card:hover {
    background: #1e1e1e;
    border-color: #4af;
}
.game-card.focused {
    border-color: #0ff;
    outline: 2px solid #0ff;
    outline-offset: 2px;
}
.game-card-title {
    font-size: 1.1rem;
    font-weight: 600;
}
.game-card-desc {
    font-size: 0.8rem;
    color: #888;
}

.empty-hint {
    color: #555;
    font-size: 0.9rem;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    cursor: pointer;
    /* Resets needed since <button> (unlike <label>) doesn't inherit these from the body by default */
    width: 100%;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
}
.settings-row[hidden] {
    display: none;
}
.settings-row:not([hidden]) ~ .settings-row:not([hidden]) {
    margin-top: 10px;
}
.settings-ip-row {
    flex-wrap: wrap;
    justify-content: space-between;
}
.settings-ip-row input {
    width: min(100%, 210px);
    padding: 7px 9px;
    color: inherit;
    background: #161616;
    border: 1px solid #555;
    border-radius: 4px;
    font: inherit;
    cursor: text !important;
}
.settings-ip-row input:focus-visible {
    outline: 2px solid #0ff;
    outline-offset: 2px;
}
.settings-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #4af;
}
.settings-row.focused {
    border-color: #0ff;
    outline: 2px solid #0ff;
    outline-offset: 2px;
}
