* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #4A90D9;
    --secondary: #4AD94A;
    --accent: #D9A04A;
    --bg-dark: #1a1a2e;
    --bg-light: #16213e;
    --text: #fff;
    --text-muted: #888;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    color: var(--text);
}

button, input {
    touch-action: manipulation;
    font-family: inherit;
}

/* Screens */
.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* Logo */
.logo {
    font-size: 2.8rem;
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 30px rgba(74, 144, 217, 0.5);
    margin-bottom: 4px;
    letter-spacing: 4px;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* Inputs */
input[type="text"] {
    width: 100%;
    max-width: 320px;
    padding: 14px 18px;
    font-size: 1rem;
    border: 2px solid var(--secondary);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    text-align: center;
    margin-bottom: 12px;
    outline: none;
    transition: all 0.2s ease;
}

input[type="text"]::placeholder {
    color: #555;
}

input[type="text"]:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.12);
}

/* Buttons */
.btn-primary {
    width: 100%;
    max-width: 320px;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    background: linear-gradient(135deg, var(--primary) 0%, #3a7bc8 100%);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-respawn {
    position: absolute;
    bottom: calc(40px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 32px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    background: linear-gradient(135deg, var(--secondary) 0%, #3ac83a 100%);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    z-index: 20;
    animation: pulse-btn 2s infinite;
}

.btn-respawn:active {
    transform: translateX(-50%) scale(0.95);
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74, 144, 217, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(74, 144, 217, 0); }
}

/* Game Screen */
#game-screen {
    padding: 0;
}

#game-canvas {
    display: block;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Game HUD */
.game-hud {
    position: absolute;
    top: calc(8px + var(--safe-top));
    left: 8px;
    right: 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
}

.hud-stats {
    display: flex;
    gap: 6px;
}

.stat-item {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 10px;
    padding: 5px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.stat-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.hud-timer {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 10px;
    padding: 6px 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.hud-timer span {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.hud-players {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.hud-player-item {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 8px;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.hud-player-color {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
}

.hud-player-name {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-player-name.me {
    color: var(--text);
    font-weight: 600;
}

.hud-player-cells {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text);
    margin-left: auto;
}

/* Small phones (iPhone SE, etc) */
@media (max-height: 700px) {
    .logo {
        font-size: 2.4rem;
    }

    .tagline {
        margin-bottom: 16px;
    }
}

/* Large phones */
@media (min-height: 850px) {
    .logo {
        font-size: 3.2rem;
        margin-bottom: 8px;
    }

    .tagline {
        margin-bottom: 32px;
    }
}

/* Minimap */
.minimap {
    position: fixed;
    bottom: 20px;
    right: 10px;
    width: 160px;
    height: 60px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    background: #1a1a2e;
    z-index: 10;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Find me button */
.btn-find-me {
    position: fixed;
    bottom: 90px;
    right: 10px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(26, 26, 46, 0.85);
    color: #fff;
    font-size: 22px;
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
}

.btn-find-me:active {
    background: rgba(74, 144, 217, 0.5);
}
