:root {
    color-scheme: dark;
    --bg: #080914;
    --panel: rgba(19, 24, 43, 0.84);
    --panel-strong: rgba(13, 17, 32, 0.94);
    --line: rgba(147, 197, 253, 0.2);
    --line-bright: rgba(125, 249, 255, 0.46);
    --text: #f8fbff;
    --muted: #a8b5d1;
    --cyan: #21d4fd;
    --pink: #ff4fd8;
    --lime: #b8ff5c;
    --orange: #ffb84d;
    --danger: #ff5468;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background: #111414;
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent 86%);
}

button,
input,
select {
    font: inherit;
}

button {
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    padding: 0.72rem 1rem;
    background: linear-gradient(135deg, rgba(33, 212, 253, 0.18), rgba(255, 79, 216, 0.14));
    color: var(--text);
    cursor: pointer;
    font-weight: 800;
    letter-spacing: 0;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: var(--line-bright);
    box-shadow: 0 10px 24px rgba(33, 212, 253, 0.14);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.46;
}

input,
select {
    width: 100%;
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    padding: 0.74rem 0.86rem;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 4px rgba(33, 212, 253, 0.14);
}

select option {
    color: #0b1020;
}

.lobby-shell {
    width: min(1180px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 6vh 0 40px;
    display: grid;
    align-content: center;
    gap: 1.5rem;
}

.lobby-hero {
    display: grid;
    gap: 1rem;
}

.eyebrow {
    margin: 0;
    color: var(--lime);
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    max-width: 820px;
    margin-bottom: 0;
    font-size: 3.5rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
    text-transform: uppercase;
    text-shadow: 0 0 28px rgba(33, 212, 253, 0.32);
}

h2,
h3 {
    margin-bottom: 0;
    line-height: 1.05;
}

.intro {
    max-width: 620px;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 1.08rem;
}

.player-card,
.panel {
    border-top: 1px solid var(--line);
    background: transparent;
}

.player-card {
    width: min(420px, 100%);
    padding: 1rem;
    display: grid;
    gap: 0.5rem;
}

.player-card label,
.settings-grid label {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 800;
}

.lobby-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 1rem;
    align-items: start;
}

.panel {
    padding: 1rem;
}

.panel-heading {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

#roomsList {
    min-height: 150px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.75rem;
    align-items: stretch;
    color: var(--muted);
}

.room {
    min-height: 82px;
    display: flex;
    gap: 0.8rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.095), rgba(255, 255, 255, 0.035));
    color: var(--text);
    font-weight: 900;
    overflow-wrap: anywhere;
}

.room button,
.primary-action {
    background: linear-gradient(135deg, rgba(184, 255, 92, 0.95), rgba(33, 212, 253, 0.88));
    color: #07101a;
}

.primary-action {
    width: 100%;
    margin-top: 1rem;
}

#globalScoreboardContainer {
    position: sticky;
    top: 1rem;
}

#globalScoreboard {
    min-height: 160px;
    margin-top: 1rem;
    padding: 0.8rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.26);
    color: var(--text);
}

#globalScoreboard > div {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.66rem 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#globalScoreboard > div:last-child {
    border-bottom: 0;
}

#gameContainer {
    display: none;
    width: min(1120px, calc(100% - 24px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 16px 0 28px;
    position: relative;
    align-content: start;
    gap: 0.9rem;
}

#gameContainer[style*="block"] {
    display: grid !important;
}

#headerBar,
#gameInfo {
    border-bottom: 1px solid var(--line);
    background: transparent;
}

#headerBar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem;
    position: relative;
    z-index: 20;
}

.game-brand {
    display: grid;
    gap: 0.12rem;
    font-weight: 950;
    text-transform: uppercase;
}

.game-brand small {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

#leaveRoomButton {
    border-color: rgba(255, 84, 104, 0.46);
    background: rgba(255, 84, 104, 0.16);
}

#gameInfo {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.65rem;
    padding: 0.75rem;
}

.status,
.score,
#roomScoreboard {
    min-height: 58px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.78rem;
    background: rgba(255, 255, 255, 0.065);
    color: var(--text);
    text-align: center;
    overflow-wrap: anywhere;
    font-weight: 850;
}

.status {
    justify-content: flex-start;
    color: var(--lime);
}

#canvasContainer {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    display: grid;
    place-items: center;
}

canvas {
    width: min(100%, 900px);
    height: auto;
    aspect-ratio: 4 / 3;
    display: block;
    border: 2px solid rgba(125, 249, 255, 0.62);
    border-radius: 8px;
    background: radial-gradient(circle at 50% 45%, #101a30, #03050d 68%);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 26px 80px rgba(33, 212, 253, 0.16);
}

#pauseButton {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255, 184, 77, 0.2);
}

#readyButton {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 10;
    min-width: min(280px, calc(100vw - 48px));
    transform: translate(-50%, -50%);
    padding: 1rem 1.4rem;
    background: linear-gradient(135deg, var(--lime), var(--cyan));
    color: #07101a;
    font-size: 1.15rem;
}

#mobileControls {
    display: none;
    position: relative;
    z-index: 20;
    gap: 0.65rem;
    justify-content: space-between;
}

#mobileControls button {
    touch-action: none;
    user-select: none;
    font-size: 2rem;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    padding: 0;
    background: rgba(33, 212, 253, 0.2);
    backdrop-filter: blur(12px);
}

#toastContainer {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 40;
    width: min(420px, calc(100% - 32px));
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    margin-top: 10px;
    padding: 0.85rem 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(9, 13, 25, 0.92);
    color: var(--text);
    box-shadow: var(--shadow);
    opacity: 0;
    animation: fadein 0.5s forwards, fadeout 0.5s 3s forwards;
}

@keyframes fadein {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeout {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(8px); }
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 30;
    overflow: hidden;
    background: rgba(3, 5, 13, 0.62);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    overflow-y: auto;
    width: min(420px, calc(100% - 24px));
    height: 100%;
    margin-left: auto;
    padding: 1rem;
    border-left: 1px solid var(--line);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 0.8rem;
}

.modal-content h3 {
    margin: 0;
    padding-right: 3rem;
}

.close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    min-height: 44px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    line-height: 1;
    background: rgba(255, 255, 255, 0.08);
}

#chatMessages {
    min-height: 220px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.24);
    color: var(--muted);
    font-size: 0.94rem;
}

#chatMessages > div {
    overflow-wrap: anywhere;
    padding: 0.55rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.chat-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.6rem;
}

.settings-grid {
    display: grid;
    gap: 0.85rem;
    align-content: start;
}

.settings-grid label {
    display: grid;
    gap: 0.42rem;
}

#updateSettings,
#sendChat {
    background: linear-gradient(135deg, rgba(33, 212, 253, 0.9), rgba(255, 79, 216, 0.78));
}

@media (max-width: 820px) {
    .lobby-shell {
        width: min(100% - 24px, 620px);
        padding-top: 28px;
        align-content: start;
    }

    .lobby-grid,
    #gameInfo {
        grid-template-columns: 1fr;
    }

    #globalScoreboardContainer {
        position: static;
    }

    #headerBar {
        align-items: stretch;
        flex-direction: column;
    }

    .header-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .header-actions button {
        padding-inline: 0.55rem;
        font-size: 0.88rem;
    }

    .status {
        justify-content: center;
    }

    #mobileControls {
        display: flex;
    }
}

@media (max-width: 600px) {
    h1 {
        font-size: 2.25rem;
    }

    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    #roomsList {
        grid-template-columns: 1fr;
    }

    #canvasContainer {
        margin-top: 0.25rem;
    }

    #pauseButton {
        top: 8px;
        right: 8px;
        min-height: 38px;
        padding: 0.42rem 0.7rem;
        font-size: 0.82rem;
    }

    .modal {
        display: none;
        align-items: end;
    }

    .modal[style*="block"] {
        display: flex !important;
    }

    .modal-content {
        width: 100%;
        height: min(78vh, 620px);
        margin: auto 0 0;
        border-left: 0;
        border-top: 1px solid var(--line);
        border-radius: 8px 8px 0 0;
    }

    #chatMessages {
        min-height: 180px;
    }

    #mobileControls {
        justify-content: space-between;
    }

    #mobileControls button {
        width: 68px;
        height: 68px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
