:root {
    --bg: #0a0a0a;
    --panel: #141414;
    --border: #2a2a2a;
    --fg: #e0e0e0;
    --muted: #888;
    --accent: #7cff7c;
    --error: #ff7c7c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    overflow: hidden;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    gap: 1.5rem;
}

h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    letter-spacing: 0.05em;
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 28rem;
}

#game-screen {
    max-width: 100%;
    gap: 0.5rem;
}

form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: var(--muted);
}

input, select, button {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--fg);
    border-radius: 6px;
    font: inherit;
    min-height: 44px;
}

input:focus, select:focus, button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

button {
    background: var(--accent);
    color: #000;
    font-weight: 600;
    cursor: pointer;
    border-color: transparent;
}

button:hover {
    filter: brightness(1.1);
}

button[type="button"] {
    background: var(--panel);
    color: var(--fg);
    border-color: var(--border);
}

#share-link-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

#share-link-box input {
    flex: 1 1 100%;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.8rem;
}

#share-link-box button {
    flex: 1 1 auto;
}

.divider {
    display: flex;
    align-items: center;
    width: 100%;
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    gap: 0.75rem;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

#manual-join-code {
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

#player-list {
    list-style: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#player-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.color-dot {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.player-name {
    flex: 1;
}

.host-tag {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--accent);
}

#lobby-game-id {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    color: var(--accent);
    letter-spacing: 0.15em;
}

#status {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: auto;
}

#status[data-state="error"] {
    color: var(--error);
}

/* ----- Countdown ----- */

#countdown-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    z-index: 100;
    pointer-events: none;
}

#countdown-number {
    font-size: clamp(6rem, 30vw, 16rem);
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 0 40px rgba(124, 255, 124, 0.5);
}

/* ----- Game canvas + HUD ----- */

#canvas-wrap {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

canvas#game-canvas {
    display: block;
    width: 100%;
    max-width: 100vw;
    max-height: 80vh;
    aspect-ratio: 1280 / 720;
    background: #000;
    border: 1px solid var(--border);
    image-rendering: pixelated;
    touch-action: none;
}

/* ----- Virtual joysticks (touch devices only) ----- */

.joystick {
    display: none;  /* shown on touch devices via the media query below */
    position: absolute;
    /* Lifted off the bottom edge so phone-case bezels / home-bar gestures
       don't intercept the downward swing. env(safe-area-inset-bottom)
       respects the iPhone notch / Android gesture bar. */
    bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    width: 7rem;
    height: 7rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    touch-action: none;
    z-index: 10;
    pointer-events: auto;
}

#joystick-left { left: 1.5rem; }
#joystick-right { right: 1.5rem; }

.joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 3rem;
    height: 3rem;
    margin-top: -1.5rem;
    margin-left: -1.5rem;
    border-radius: 50%;
    background: rgba(124, 255, 124, 0.6);
    transition: transform 0.05s linear;
    pointer-events: none;
}

/* Touch device class is added by client.js (more reliable than @media
   (pointer: coarse), which Chrome DevTools mobile emulation often misses).
   Both selectors below to keep media-query users happy too. */
@media (pointer: coarse) {
    .joystick { display: block; }
    canvas#game-canvas { max-height: 100vh; }
}
body.touch .joystick { display: block; }
body.touch canvas#game-canvas { max-height: 100vh; }

/* ----- Portrait rotation hint (touch + portrait only) ----- */

#rotate-hint {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 300;
    font-size: 1.1rem;
    color: var(--fg);
}

@media (pointer: coarse) and (orientation: portrait) {
    body[data-in-game="true"] #rotate-hint:not(.dismissed) {
        display: flex !important;
    }
}
@media (orientation: portrait) {
    body.touch[data-in-game="true"] #rotate-hint:not(.dismissed) {
        display: flex !important;
    }
}

#hud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
    max-width: 1280px;
    padding: 0.25rem 0.5rem;
}

.hud-player {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}

.hud-player[data-dead="true"] {
    opacity: 0.4;
    text-decoration: line-through;
}

#game-message {
    text-align: center;
}

/* ----- Results overlay ----- */

#results-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    padding: 1rem;
}

#results-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    max-width: 30rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

#results-title {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    text-align: center;
    color: var(--accent);
}

#results-list {
    list-style: none;
    counter-reset: place;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#results-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

.place-num {
    font-family: ui-monospace, monospace;
    font-weight: 700;
    color: var(--accent);
    min-width: 2rem;
}
