* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: Ubuntu, "Trebuchet MS", system-ui, sans-serif;
    background: #f2fbff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

body.dark {
    background: #111418;
}

#game {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    outline: none;
    display: block;
}

.hidden {
    display: none !important;
}

/* ---------- HUD ---------- */

#hud > * {
    position: fixed;
    z-index: 2;
}

#hud.menu-open #chat,
#hud.menu-open #score,
#hud.menu-open #touch-buttons {
    display: none;
}

.panel-dark {
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    border-radius: 8px;
}

#leaderboard {
    top: 12px;
    right: 12px;
    width: 220px;
    padding: 10px 14px;
    font-size: 15px;
}

#leaderboard h2 {
    margin: 0 0 6px;
    text-align: center;
    font-size: 20px;
}

#lb-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

#lb-list li {
    display: flex;
    gap: 6px;
    line-height: 1.5;
    white-space: nowrap;
}

#lb-list .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

#lb-list .mass {
    opacity: 0.6;
}

#lb-list li.me {
    color: #ffaaaa;
    font-weight: bold;
}

#feed {
    top: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.feed-line {
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 14px;
    transition: opacity 1s;
}

.feed-line.fade {
    opacity: 0;
}

#chat {
    left: 12px;
    bottom: 44px;
    width: 340px;
}

#chat-log {
    list-style: none;
    margin: 0 0 6px;
    padding: 0;
    color: #fff;
    font-size: 14px;
    text-shadow: 0 0 3px #000, 0 0 3px #000;
    word-wrap: break-word;
}

#chat-input {
    width: 100%;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font: inherit;
    outline: none;
}

#chat-input::placeholder {
    color: rgba(255, 255, 255, 0.55);
}

#score {
    left: 12px;
    bottom: 12px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 4px #000, 0 0 4px #000;
}

#minimap {
    right: 12px;
    bottom: 12px;
    width: 180px;
    height: 180px;
    border-radius: 6px;
}

#touch-buttons {
    display: none;
    right: 16px;
    bottom: 140px;
    flex-direction: column;
    gap: 14px;
}

body.touch #touch-buttons {
    display: flex;
}

body.touch #chat,
body.touch #minimap {
    display: none;
}

#touch-buttons button {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 18px;
    font-weight: bold;
}

/* ---------- menu ---------- */

#menu {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25);
}

.card {
    width: min(380px, 92vw);
    max-height: 96vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 14px;
    padding: 24px 26px 16px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    color: #222;
}

body.dark .card {
    background: #1d2228;
    color: #eee;
}

.logo-face {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 5px solid #ff4d4d;
    animation: wobble 2.4s ease-in-out infinite;
}

@keyframes wobble {
    0%, 100% { transform: rotate(-6deg) scale(1); }
    50% { transform: rotate(6deg) scale(1.06); }
}

.card h1 {
    margin: 6px 0 0;
    font-size: 44px;
    letter-spacing: -1px;
}

.card h1 span {
    color: #ff4d4d;
}

.tagline {
    margin: 2px 0 14px;
    opacity: 0.7;
}

#death h2 {
    margin: 4px 0 8px;
    color: #ff4d4d;
}

.stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 14px;
}

.stats div {
    display: flex;
    flex-direction: column;
}

.stats b {
    font-size: 18px;
}

.stats span {
    font-size: 11px;
    opacity: 0.65;
}

#name {
    width: 100%;
    padding: 12px;
    font: inherit;
    font-size: 17px;
    border: 2px solid #ddd;
    border-radius: 8px;
    outline: none;
    text-align: center;
}

#name:focus {
    border-color: #ff4d4d;
}

body.dark #name {
    background: #12161a;
    color: #fff;
    border-color: #333;
}

#play {
    width: 100%;
    margin-top: 10px;
    padding: 12px;
    font: inherit;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    background: #2ecc71;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#play:hover {
    background: #27ae60;
}

.settings {
    margin-top: 12px;
    text-align: left;
}

.settings summary {
    cursor: pointer;
    text-align: center;
    opacity: 0.75;
}

.settings label {
    display: block;
    padding: 3px 0;
    cursor: pointer;
}

.controls {
    font-size: 13px;
    opacity: 0.75;
}

#online {
    margin: 0;
    font-size: 13px;
    opacity: 0.6;
}

@media (max-width: 600px) {
    #leaderboard {
        width: 150px;
        font-size: 12px;
        padding: 6px 8px;
    }

    #leaderboard h2 {
        font-size: 14px;
    }

    .stats {
        grid-template-columns: repeat(3, 1fr);
    }
}
