/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
    font-family: 'Rajdhani', sans-serif;
    background: #0a0a0f;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
}

/* ===== SCREENS ===== */
.screen {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 100%);
}
.screen.hidden { display: none; }

/* ===== START / LOBBY CARD ===== */
.start-card {
    background: rgba(20, 20, 35, 0.92);
    border: 1px solid rgba(100, 200, 255, 0.2);
    border-radius: 20px;
    padding: 40px 50px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 0 60px rgba(0, 150, 255, 0.15), inset 0 0 30px rgba(0, 100, 200, 0.05);
    backdrop-filter: blur(10px);
}
.lobby-card { max-width: 540px; max-height: 90vh; overflow-y: auto; }
.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 48px; font-weight: 900;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #00e5ff, #7c4dff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}
.game-title .accent { color: #ff6b35; -webkit-text-fill-color: #ff6b35; }
.tagline {
    color: #8899aa; font-size: 14px; margin-bottom: 30px; letter-spacing: 1px;
}
.connecting {
    font-size: 18px; color: #667788; padding: 40px 0;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.connecting .dot {
    width: 10px; height: 10px; border-radius: 50%; background: #00e5ff;
    animation: blink 0.8s infinite;
}
@keyframes blink { 0%,100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ===== NAME INPUT ===== */
.name-input-group { text-align: left; margin-bottom: 24px; }
.name-input-group label {
    display: block; font-size: 13px; color: #667788; margin-bottom: 6px; font-weight: 600;
}
#playerName, #adminPw {
    width: 100%; padding: 12px 16px;
    background: rgba(0,0,0,0.4); border: 1px solid rgba(100,200,255,0.15);
    border-radius: 10px; color: #fff; font-size: 16px; font-family: 'Rajdhani', sans-serif;
    outline: none; transition: border-color .2s;
}
#playerName:focus, #adminPw:focus { border-color: #00e5ff; box-shadow: 0 0 12px rgba(0,229,255,0.2); }

/* ===== COLOR PICKER ===== */
.color-picker { margin-bottom: 28px; }
.color-label { font-size: 13px; color: #667788; margin-bottom: 10px; font-weight: 600; }
.color-options { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.color-dot {
    width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
    border: 3px solid transparent; transition: all .2s;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.selected { border-color: #fff; box-shadow: 0 0 12px currentColor; transform: scale(1.15); }

/* ===== BUTTONS ===== */
.btn-play {
    display: inline-block; padding: 14px 48px;
    font-family: 'Orbitron', sans-serif; font-size: 20px; font-weight: 700;
    letter-spacing: 2px; cursor: pointer; border: none;
    border-radius: 12px; color: #fff;
    background: linear-gradient(135deg, #00e5ff, #7c4dff);
    box-shadow: 0 4px 20px rgba(0, 200, 255, 0.3);
    transition: all .2s; text-transform: uppercase;
}
.btn-play:hover { transform: translateY(-2px); box-shadow: 0 6px 28px rgba(0, 200, 255, 0.45); }
.btn-play:active { transform: translateY(0); }

.btn-copy {
    display: inline-block; padding: 10px 24px;
    font-family: 'Rajdhani', sans-serif; font-size: 15px; font-weight: 600;
    cursor: pointer; border: 1px solid rgba(100,200,255,0.2);
    border-radius: 10px; color: #aabbcc;
    background: rgba(100,200,255,0.05); transition: all .2s;
}
.btn-copy:hover { background: rgba(100,200,255,0.12); color: #fff; }
.btn-copy.copied { background: rgba(0,230,118,0.15); color: #00e676; border-color: rgba(0,230,118,0.3); }

/* ===== LOBBY WAITING ===== */
.waiting-status {
    display: flex; flex-direction: column; align-items: center; gap: 12px;
    margin-bottom: 24px;
}
.pulse-dot {
    width: 14px; height: 14px; border-radius: 50%; background: #ff9100;
    animation: pulse 1.2s infinite;
}
@keyframes pulse {
    0%,100% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 16px rgba(255,145,0,0.6); }
}
.waiting-text { font-size: 16px; color: #ff9100; font-weight: 600; }

.lobby-players {
    background: rgba(0,0,0,0.3); border: 1px solid rgba(100,200,255,0.1);
    border-radius: 8px; overflow: hidden; margin-bottom: 20px; max-height: 200px; overflow-y: auto;
}
.lobby-players-body { padding: 6px 0; }
.lobby-player-row {
    display: flex; align-items: center; padding: 6px 14px; font-size: 15px;
}
.lobby-player-row .lb-color { margin-right: 10px; }
.lobby-player-row .lobby-player-name { font-weight: 600; }
.share-link { text-align: center; margin-bottom: 16px; }

/* ===== INSTRUCTIONS & LINKS ===== */
.instructions { margin-top: 24px; padding-top: 20px; border-top: 1px solid rgba(100,200,255,0.1); }
.instructions p { font-size: 14px; color: #778899; margin: 6px 0; }
.key {
    display: inline-block; padding: 2px 10px; border-radius: 6px;
    background: rgba(100,200,255,0.1); border: 1px solid rgba(100,200,255,0.2);
    color: #aabbcc; font-weight: 600; font-size: 13px;
}
.admin-link { margin-top: 20px; }
.admin-link a { color: #556677; font-size: 13px; text-decoration: none; }
.admin-link a:hover { color: #00e5ff; }

/* ===== GAME CANVAS ===== */
#gameCanvas { display: block; position: fixed; inset: 0; z-index: 1; }

/* ===== HUD ===== */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud.hidden { display: none; }

.hud-timer {
    position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
    font-family: 'Orbitron', sans-serif; font-size: 42px; font-weight: 900;
    color: #fff; text-shadow: 0 0 20px rgba(0, 229, 255, 0.6);
    letter-spacing: 4px; line-height: 1;
    background: rgba(10,10,20,0.5); padding: 6px 24px; border-radius: 14px;
    border: 1px solid rgba(100,200,255,0.15);
}
.hud-timer.warning { color: #ff6b35; text-shadow: 0 0 20px rgba(255, 107, 53, 0.8); }
.hud-timer.danger { color: #ff1744; text-shadow: 0 0 25px rgba(255, 23, 68, 0.9); animation: pulseDanger .5s infinite alternate; }
@keyframes pulseDanger { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.08); } }

.hud-stats {
    position: absolute; top: 20px; left: 20px;
    font-family: 'Orbitron', sans-serif; font-size: 22px; font-weight: 700;
    color: #00e5ff; text-shadow: 0 0 10px rgba(0,229,255,0.4);
}
.hud-stats #playerScore { font-size: 28px; }
.stats-label { font-size: 13px; color: #556677; margin-left: 4px; margin-right: 16px; font-weight: 600; }
.length-badge { font-size: 22px; color: #7c4dff; }
.length-badge::before { content: "🐍 "; }

.hud-spectator {
    position: absolute; top: 80px; left: 50%; transform: translateX(-50%);
    background: rgba(10,10,20,0.7); border: 1px solid rgba(255,145,0,0.3);
    border-radius: 8px; padding: 6px 20px; font-size: 14px; color: #ff9100;
    font-weight: 600; letter-spacing: 1px;
}

/* Leaderboard */
.hud-leaderboard {
    position: absolute; top: 16px; right: 16px;
    width: 220px; background: rgba(10,10,20,0.7);
    border: 1px solid rgba(100,200,255,0.12); border-radius: 12px;
    overflow: hidden;
}
.lb-header {
    padding: 8px 14px; font-family: 'Orbitron', sans-serif; font-size: 13px;
    font-weight: 700; letter-spacing: 2px; color: #fff;
    background: rgba(100,200,255,0.08); border-bottom: 1px solid rgba(100,200,255,0.1);
}
.lb-body { padding: 6px 0; max-height: 320px; overflow-y: auto; }
.lb-row {
    display: flex; align-items: center; padding: 4px 14px; font-size: 14px;
}
.lb-rank { width: 24px; font-weight: 700; font-size: 13px; color: #556677; text-align: center; }
.lb-rank.gold { color: #ffd700; } .lb-rank.silver { color: #c0c0c0; } .lb-rank.bronze { color: #cd7f32; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-color { width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.lb-score { font-weight: 700; font-size: 13px; color: #00e5ff; min-width: 40px; text-align: right; }
.lb-row.is-player { background: rgba(0,229,255,0.08); }
.lb-row.is-player .lb-name { color: #00e5ff; }
.lb-row.dead { opacity: 0.35; text-decoration: line-through; }
.lb-row.is-bot .lb-name::after { content: " 🤖"; font-size: 11px; }

/* Minimap */
.hud-minimap {
    position: absolute; bottom: 16px; right: 16px;
    border-radius: 12px; border: 1px solid rgba(100,200,255,0.15);
    background: rgba(10,10,20,0.7); opacity: 0.85;
}

/* Boost bar */
.hud-boost { position: absolute; bottom: 20px; left: 20px; width: 200px; }
.boost-label { font-family: 'Orbitron', sans-serif; font-size: 11px; letter-spacing: 2px; color: #556677; margin-bottom: 4px; }
.boost-track { height: 8px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.boost-fill { height: 100%; width: 100%; border-radius: 4px; background: linear-gradient(90deg, #ff6b35, #ff1744); transition: width .1s; }
.boost-fill.disabled { background: #333; }

/* ===== END SCREEN ===== */
.end-card {
    background: rgba(20, 20, 35, 0.95);
    border: 1px solid rgba(100,200,255,0.2); border-radius: 20px;
    padding: 40px 50px; text-align: center; max-width: 500px;
    box-shadow: 0 0 80px rgba(0,150,255,0.2); backdrop-filter: blur(10px);
    max-height: 90vh; overflow-y: auto;
}
.end-title {
    font-family: 'Orbitron', sans-serif; font-size: 32px; font-weight: 900;
    letter-spacing: 3px; margin-bottom: 24px; color: #fff;
}
.winner-section { margin-bottom: 30px; }
.crown { font-size: 64px; margin-bottom: 8px; }
.winner-name {
    font-family: 'Orbitron', sans-serif; font-size: 28px; font-weight: 700;
    background: linear-gradient(135deg, #ffd700, #ff6b35);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.winner-score { font-size: 18px; color: #ffd700; margin-top: 4px; font-weight: 600; }
.final-ranking { margin: 20px 0; text-align: left; }
.fr-header {
    font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 2px;
    color: #667788; margin-bottom: 10px; text-align: center;
}
.fr-body { max-height: 280px; overflow-y: auto; }
.fr-row {
    display: flex; align-items: center; padding: 8px 16px; margin: 4px 0;
    background: rgba(255,255,255,0.03); border-radius: 8px; font-size: 15px;
}
.fr-row.is-player { background: rgba(0,229,255,0.1); border: 1px solid rgba(0,229,255,0.2); }
.fr-rank { width: 28px; font-weight: 700; font-size: 16px; text-align: center; }
.fr-rank.gold { color: #ffd700; } .fr-rank.silver { color: #c0c0c0; } .fr-rank.bronze { color: #cd7f32; }
.fr-name { flex: 1; font-weight: 600; }
.fr-color { width: 10px; height: 10px; border-radius: 50%; margin-right: 10px; flex-shrink: 0; }
.fr-score { font-weight: 700; color: #00e5ff; }
.player-result { margin: 16px 0; font-size: 16px; color: #8899aa; }
.player-result .highlight { color: #00e5ff; font-weight: 700; font-size: 22px; }
.back-to-lobby { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; color: #556677; font-size: 14px; }

/* ===== DEATH OVERLAY ===== */
#deathOverlay { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: flex; align-items: center; justify-content: center; }
#deathOverlay.hidden { display: none; }
.death-card {
    background: rgba(20,10,10,0.92); border: 1px solid rgba(255,50,50,0.2);
    border-radius: 16px; padding: 30px 40px; text-align: center;
    box-shadow: 0 0 40px rgba(255,50,50,0.15); backdrop-filter: blur(8px);
    animation: deathAppear .4s ease;
}
@keyframes deathAppear { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.death-icon { font-size: 48px; }
.death-text { font-family: 'Orbitron', sans-serif; font-size: 22px; font-weight: 700; color: #ff6b6b; margin: 12px 0 8px; }
.death-rank { font-size: 16px; color: #8899aa; }
.death-hint { font-size: 13px; color: #556677; margin-top: 10px; }

/* ===== ADMIN PANEL ===== */
.admin-body { display: flex; justify-content: center; align-items: flex-start; padding: 20px; overflow-y: auto; }
.admin-error { color: #ff5252; font-size: 14px; margin-top: 16px; }
.admin-panel { width: 100%; max-width: 600px; padding: 20px; }
.admin-header { text-align: center; margin-bottom: 24px; }
.admin-title {
    font-family: 'Orbitron', sans-serif; font-size: 24px; font-weight: 900;
    letter-spacing: 2px; margin-bottom: 16px;
    background: linear-gradient(135deg, #00e5ff, #7c4dff);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.admin-status-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.phase-badge {
    padding: 6px 20px; border-radius: 20px; font-family: 'Orbitron', sans-serif;
    font-size: 13px; font-weight: 700; letter-spacing: 2px;
}
.phase-lobby { background: rgba(0,230,118,0.15); color: #00e676; border: 1px solid rgba(0,230,118,0.3); }
.phase-playing { background: rgba(0,229,255,0.15); color: #00e5ff; border: 1px solid rgba(0,229,255,0.3); }
.phase-ended { background: rgba(255,145,0,0.15); color: #ff9100; border: 1px solid rgba(255,145,0,0.3); }
.admin-timer { font-family: 'Orbitron', sans-serif; font-size: 18px; font-weight: 700; color: #fff; }
.admin-stat { font-size: 16px; font-weight: 600; color: #00e676; }

.admin-controls { text-align: center; margin-bottom: 24px; display: flex; gap: 12px; justify-content: center; }
.btn-admin {
    padding: 12px 32px; font-family: 'Orbitron', sans-serif; font-size: 16px;
    font-weight: 700; letter-spacing: 1px; cursor: pointer; border: none;
    border-radius: 10px; transition: all .2s;
}
.btn-start { background: linear-gradient(135deg, #00e676, #00b0ff); color: #fff; box-shadow: 0 4px 16px rgba(0,230,118,0.3); }
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,230,118,0.45); }
.btn-reset { background: linear-gradient(135deg, #ff6b35, #ff1744); color: #fff; box-shadow: 0 4px 16px rgba(255,107,53,0.3); }
.btn-reset:hover { transform: translateY(-2px); }
.btn-admin.disabled { opacity: 0.4; cursor: not-allowed; }

.admin-players-section, .admin-snakes-section { margin-bottom: 24px; }
.admin-section-title {
    font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 1px;
    color: #667788; margin-bottom: 10px;
}
.admin-player-list { display: flex; flex-direction: column; gap: 4px; }
.admin-player-row {
    display: flex; align-items: center; padding: 8px 16px;
    background: rgba(255,255,255,0.03); border-radius: 8px; font-size: 15px;
}
.admin-player-name { font-weight: 600; }
.admin-empty { text-align: center; color: #556677; font-size: 14px; padding: 20px; }
.snake-stats-list { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }

.admin-footer { margin-top: 32px; padding-top: 20px; border-top: 1px solid rgba(100,200,255,0.1); }
.admin-info p { font-size: 13px; color: #556677; margin: 4px 0; }
.hidden { display: none !important; }

/* ===== READY BUTTON ===== */
.btn-ready {
    display: inline-block; padding: 16px 48px;
    font-family: 'Orbitron', sans-serif; font-size: 20px; font-weight: 700;
    letter-spacing: 2px; cursor: pointer; border: none;
    border-radius: 12px; color: #fff; margin-bottom: 20px;
    background: linear-gradient(135deg, #00e676, #00b0ff);
    box-shadow: 0 4px 20px rgba(0, 230, 118, 0.3);
    transition: all .2s; text-transform: uppercase;
}
.btn-ready:hover { transform: translateY(-2px); box-shadow: 0 6px 28px rgba(0, 230, 118, 0.45); }
.btn-ready:active { transform: translateY(0); }
.btn-ready.is-ready-btn {
    background: linear-gradient(135deg, #ff6b35, #ff1744);
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.3);
}

/* ===== READY PROGRESS ===== */
.ready-progress { margin-bottom: 20px; }
.ready-label { font-size: 16px; font-weight: 600; color: #aabbcc; margin-bottom: 6px; }
.ready-label span { color: #00e676; font-weight: 700; }
.ready-bar-track {
    height: 10px; background: rgba(255,255,255,0.06); border-radius: 5px; overflow: hidden; margin-bottom: 6px;
}
.ready-bar-fill {
    height: 100%; width: 0%; border-radius: 5px;
    background: linear-gradient(90deg, #00e676, #00b0ff);
    transition: width .3s;
}
.ready-threshold { font-size: 13px; color: #556677; text-align: center; }

/* ===== COUNTDOWN BANNER ===== */
.countdown-banner {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    margin-bottom: 24px; padding: 20px;
    background: rgba(0, 229, 255, 0.08); border: 1px solid rgba(0, 229, 255, 0.2);
    border-radius: 16px; animation: countdownPulse .5s infinite alternate;
}
@keyframes countdownPulse {
    from { box-shadow: 0 0 20px rgba(0, 229, 255, 0.2); }
    to { box-shadow: 0 0 40px rgba(0, 229, 255, 0.5); }
}
.countdown-number {
    font-family: 'Orbitron', sans-serif; font-size: 56px; font-weight: 900;
    color: #00e5ff; text-shadow: 0 0 30px rgba(0, 229, 255, 0.8);
    line-height: 1;
}
.countdown-text {
    font-family: 'Orbitron', sans-serif; font-size: 14px; letter-spacing: 3px;
    color: #aabbcc; font-weight: 700;
}

/* ===== READY BADGE IN PLAYER LIST ===== */
.ready-badge { margin-left: auto; font-size: 16px; }
.ready-yes { opacity: 1; }
.ready-no { opacity: 0.4; }
.lb-row.is-ready { background: rgba(0, 230, 118, 0.06); }

/* ===== SPECTATOR MODE ===== */
.hud-spectator {
    position: absolute; top: 80px; left: 50%; transform: translateX(-50%);
    background: rgba(10,10,20,0.7); border: 1px solid rgba(255,145,0,0.3);
    border-radius: 8px; padding: 6px 20px; font-size: 13px; color: #ff9100;
    font-weight: 600; letter-spacing: 1px; white-space: nowrap;
}

/* Optional performance meter, available on desktop and touch */
.diagnostic-toggle {
  position: absolute; bottom: 16px; left: 225px; z-index: 35;
  pointer-events: auto; cursor: pointer; border-radius: 7px;
  border: 1px solid rgba(0,229,255,.3); padding: 6px 9px;
  color: #00e5ff; background: rgba(10,10,20,.8);
  font: 600 12px monospace;
}
