:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #111827;
    color: #f9fafb;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

button,
input {
    font: inherit;
}

input.hidden {
    display: none;
}

.arena-shell {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #111827;
}

#arena {
    display: block;
    width: 100vw;
    height: 100vh;
    cursor: crosshair;
    touch-action: none;
}

.topbar,
.scoreboard,
.feed,
.minimap,
.join-panel,
.touch-controls {
    position: absolute;
    z-index: 2;
}

.topbar {
    top: 16px;
    left: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    pointer-events: none;
}

.room-status,
.hud,
.scoreboard,
.feed,
.join-panel {
    border: 1px solid rgba(249, 250, 251, 0.16);
    background: rgba(17, 24, 39, 0.82);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(14px);
}

.room-status,
.hud {
    display: flex;
    align-items: center;
    min-height: 44px;
    border-radius: 8px;
    padding: 8px 12px;
}

.room-status {
    max-width: min(360px, 48vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #cbd5e1;
    font-size: 0.82rem;
    font-weight: 800;
}

.room-status.hidden {
    display: none;
}

.room-status.online {
    color: #86efac;
}

.room-status.connecting {
    color: #fde68a;
}

.room-status.offline {
    color: #fca5a5;
}

.hud {
    gap: 10px;
    pointer-events: auto;
}

#scoreText {
    min-width: 112px;
    color: #e5e7eb;
    font-size: 0.86rem;
    text-align: right;
}

.leave-button {
    min-height: 32px;
    border: 1px solid rgba(252, 165, 165, 0.42);
    border-radius: 8px;
    padding: 0 10px;
    background: rgba(127, 29, 29, 0.68);
    color: #fee2e2;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 800;
}

.leave-button:hover,
.leave-button:focus-visible {
    background: rgba(185, 28, 28, 0.82);
}

.leave-button.hidden {
    display: none;
}

.scoreboard,
.leaderboard {
    top: 76px;
    right: 16px;
    width: min(280px, calc(100vw - 32px));
    max-height: min(52vh, 410px);
    overflow: hidden;
    border-radius: 8px;
    padding: 12px;
}

.scoreboard {
    background: rgba(17, 24, 39, 0.58);
}

.leaderboard {
    position: static;
    width: auto;
    max-height: min(34vh, 260px);
    margin-top: 14px;
    padding: 0;
    overflow: hidden;
}

.scoreboard h2,
.leaderboard h2 {
    margin: 0 0 8px;
    color: #e5e7eb;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.scoreboard ol,
.leaderboard ol {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.leaderboard ol {
    max-height: min(28vh, 216px);
    padding-right: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.scoreboard li,
.leaderboard li {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    padding: 5px 7px;
    border-radius: 6px;
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.055);
    font-size: 0.86rem;
}

.scoreboard li {
    grid-template-columns: 12px minmax(0, 1fr) auto auto;
}

.leaderboard li {
    grid-template-columns: 20px minmax(0, 1fr) auto auto;
}

.scoreboard li.self,
.leaderboard li.self,
.leaderboard li.highlight {
    outline: 1px solid rgba(56, 189, 248, 0.75);
}

.leaderboard li:first-child {
    background: rgba(250, 204, 21, 0.18);
}

.scoreboard .swatch,
.leaderboard .badge {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.leaderboard .badge {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    color: #111827;
    background: #facc15;
    font-size: 0.68rem;
    font-weight: 900;
}

.scoreboard .name,
.leaderboard .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scoreboard .score,
.leaderboard .score {
    color: #cbd5e1;
    font-variant-numeric: tabular-nums;
}

.scoreboard .damage {
    color: #fca5a5;
    font-variant-numeric: tabular-nums;
}

.leaderboard .when {
    color: #94a3b8;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}

.powerup-tray {
    position: absolute;
    left: 16px;
    top: 76px;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: min(520px, calc(100vw - 32px));
    pointer-events: none;
}

.powerup-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 6px 10px;
    background: rgba(17, 24, 39, 0.84);
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(14px);
    color: #f8fafc;
    font-size: 0.8rem;
    font-weight: 800;
}

.powerup-pill .icon {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: #111827;
    font-size: 0.68rem;
}

.celebration {
    position: absolute;
    left: 50%;
    top: 18%;
    z-index: 3;
    display: none;
    transform: translateX(-50%);
    border-radius: 8px;
    padding: 12px 18px;
    background: rgba(250, 204, 21, 0.94);
    color: #111827;
    font-size: 1rem;
    font-weight: 900;
    box-shadow: 0 22px 70px rgba(250, 204, 21, 0.24);
}

.celebration.show {
    display: block;
    animation: pop-celebration 1.8s ease-out forwards;
}

@keyframes pop-celebration {
    0% { opacity: 0; transform: translate(-50%, 12px) scale(0.92); }
    16% { opacity: 1; transform: translate(-50%, 0) scale(1); }
    82% { opacity: 1; transform: translate(-50%, 0) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -10px) scale(0.98); }
}

.feed {
    left: 16px;
    bottom: 138px;
    display: grid;
    gap: 6px;
    width: min(390px, calc(100vw - 32px));
    border-radius: 8px;
    padding: 10px;
    pointer-events: none;
}

.feed:empty {
    display: none;
}

.feed p {
    margin: 0;
    color: #e5e7eb;
    font-size: 0.84rem;
    line-height: 1.35;
}

.minimap {
    left: 16px;
    bottom: 16px;
    width: 180px;
    aspect-ratio: 16 / 9;
    border: 1px solid rgba(249, 250, 251, 0.18);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.42);
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
    opacity: 0.74;
    overflow: hidden;
    pointer-events: none;
}

.minimap.hidden {
    display: none;
}

#minimap {
    display: block;
    width: 100%;
    height: 100%;
}

.touch-controls {
    inset: auto 0 0;
    z-index: 4;
    display: none;
    justify-content: space-between;
    align-items: end;
    padding: 0 max(18px, env(safe-area-inset-left)) max(18px, env(safe-area-inset-bottom));
    pointer-events: none;
}

.touch-stick {
    --stick-x: 0px;
    --stick-y: 0px;
    position: relative;
    width: 128px;
    height: 128px;
    border: 1px solid rgba(249, 250, 251, 0.2);
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.52);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(14px);
    pointer-events: auto;
    touch-action: none;
    user-select: none;
}

.touch-stick::before {
    content: '';
    position: absolute;
    inset: 28px;
    border: 1px solid rgba(249, 250, 251, 0.14);
    border-radius: 50%;
}

.touch-stick::after {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    color: rgba(226, 232, 240, 0.78);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.touch-stick-move::after {
    content: 'Move';
}

.touch-stick-aim::after {
    content: 'Aim';
}

.touch-stick span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: #e5e7eb;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
}

.touch-stick-aim span {
    background: #f97316;
}

.join-panel {
    top: 50%;
    left: 50%;
    width: min(420px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    border-radius: 8px;
    padding: 18px;
}

.join-panel.hidden {
    display: none;
}

.join-panel form {
    display: grid;
    gap: 10px;
}

.join-panel label {
    color: #d1d5db;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

.join-panel input,
.join-panel button,
.lobby-tabs button {
    min-height: 44px;
    border-radius: 8px;
}

.join-panel input {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 0 12px;
    background: rgba(15, 23, 42, 0.94);
    color: #f8fafc;
    outline: none;
}

.join-panel input:focus {
    border-color: #38bdf8;
}

.lobby-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.lobby-tabs button {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
    cursor: pointer;
    font-weight: 800;
}

.lobby-tabs button.active,
.lobby-tabs button:focus-visible {
    border-color: rgba(56, 189, 248, 0.72);
    color: #f8fafc;
    background: rgba(56, 189, 248, 0.16);
}

.lobby-pane {
    display: grid;
    gap: 8px;
}

.lobby-pane.hidden {
    display: none;
}

.game-list {
    display: grid;
    gap: 6px;
    max-height: 166px;
    margin: 0;
    padding: 0;
    overflow: auto;
    list-style: none;
}

.game-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 7px 9px;
    background: rgba(255, 255, 255, 0.055);
    color: #f8fafc;
    cursor: pointer;
}

.game-list li.selected {
    border-color: rgba(56, 189, 248, 0.72);
    background: rgba(56, 189, 248, 0.14);
}

.game-list li.empty-games {
    display: block;
    cursor: default;
}

.game-list .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.game-list .meta {
    color: #cbd5e1;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}

.empty-games,
.lobby-message {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.78rem;
    line-height: 1.35;
}

.lobby-message.error {
    color: #fca5a5;
}

.join-panel button {
    border: 0;
    padding: 0 18px;
    background: #f97316;
    color: #111827;
    cursor: pointer;
    font-weight: 800;
}

.join-panel button:hover,
.join-panel button:focus-visible {
    background: #fb923c;
}

@media (max-width: 760px) {
    .topbar {
        top: 10px;
        left: 10px;
        right: 10px;
        gap: 8px;
    }

    .room-status,
    .hud {
        justify-content: space-between;
        min-height: 38px;
        padding: 7px 10px;
    }

    .room-status,
    #scoreText {
        min-width: auto;
        font-size: 0.76rem;
    }

    .leave-button {
        min-height: 30px;
        padding: 0 8px;
        font-size: 0.72rem;
    }

    .scoreboard {
        top: 58px;
        left: 10px;
        right: 10px;
        width: auto;
        max-height: min(28vh, 190px);
        padding: 9px;
    }

    .leaderboard {
        width: auto;
        max-height: min(28vh, 190px);
        padding: 0;
    }

    .leaderboard ol {
        max-height: min(22vh, 150px);
    }

    .scoreboard h2,
    .leaderboard h2 {
        margin-bottom: 6px;
        font-size: 0.68rem;
    }

    .scoreboard ol,
    .leaderboard ol {
        gap: 4px;
    }

    .scoreboard li,
    .leaderboard li {
        min-height: 26px;
        gap: 6px;
        padding: 4px 6px;
        font-size: 0.76rem;
    }

    .scoreboard li:nth-child(n + 6) {
        display: none;
    }

    .powerup-tray {
        left: 10px;
        top: min(230px, 36vh);
        max-width: calc(100vw - 20px);
        gap: 6px;
    }

    .powerup-pill {
        min-height: 30px;
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .powerup-pill .icon {
        width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }

    .feed {
        display: none;
    }

    .minimap {
        left: 50%;
        bottom: calc(24px + env(safe-area-inset-bottom));
        width: clamp(92px, 24vw, 150px);
        transform: translateX(-50%);
    }

    .join-panel {
        width: min(380px, calc(100vw - 20px));
        padding: 14px;
    }

    .touch-controls {
        display: flex;
    }
}

@media (pointer: coarse) {
    .touch-controls {
        display: flex;
    }

    .minimap {
        left: 50%;
        bottom: calc(24px + env(safe-area-inset-bottom));
        width: clamp(92px, 24vw, 150px);
        transform: translateX(-50%);
    }

    .feed {
        bottom: 176px;
    }
}

@media (max-width: 760px) and (max-height: 560px) {
    .leaderboard {
        display: none;
    }

    .scoreboard {
        max-height: 118px;
    }

    .powerup-tray {
        display: none;
    }

    .minimap {
        width: 92px;
        bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .touch-stick {
        width: 112px;
        height: 112px;
    }

    .touch-stick span {
        width: 48px;
        height: 48px;
    }
}
