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

body {
  background: #0f172a;
  color: #e2e8f0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── Login Screen ── */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 48px 36px;
  width: 380px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

.login-card h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, #22d3ee, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.login-card .subtitle {
  margin-bottom: 28px;
}

/* ── Lobby Overlay (inside game) ── */
#lobbyOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.85);
  z-index: 10;
  overflow-y: auto;
  padding: 24px;
}

.lobby-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  z-index: 1;
  max-width: 820px;
  width: 100%;
  padding: 0 24px;
}

.lobby-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 36px;
  width: 380px;
  flex-shrink: 0;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

.lobby-card h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, #22d3ee, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.subtitle {
  color: #94a3b8;
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #22d3ee;
}

/* X Login */
.x-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: #000;
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s;
}
.x-login-btn:hover { background: #1a1a1a; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  margin-bottom: 14px;
}
.user-badge img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}
.user-badge .user-info {
  flex: 1;
  text-align: left;
}
.user-badge .user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
}
.user-badge .user-handle {
  font-size: 0.75rem;
  color: #64748b;
}

.follower-display {
  padding: 12px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  text-align: center;
  margin-bottom: 12px;
}
.follower-display .follower-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #34d399;
}
.follower-display .follower-label {
  font-size: 0.75rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.account-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.link-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: #94a3b8; }
.link-btn.danger:hover { color: #ef4444; }

/* Join */
.join-error {
  color: #ef4444;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

/* Rankings panel (inline, beside lobby card) */
.rankings-panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  flex: 1;
  min-width: 0;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
}

.rankings-panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 16px 20px 10px;
  border-bottom: 1px solid #334155;
  color: #64748b;
  flex-shrink: 0;
}

.rankings-body {
  padding: 8px 12px 16px;
  overflow-y: auto;
  flex: 1;
}

.rankings-loading {
  text-align: center;
  color: #64748b;
  padding: 24px;
}

a.rank-row,
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.rank-row:hover { background: rgba(51, 65, 85, 0.3); }

.rank-pos {
  font-size: 0.8rem;
  font-weight: 700;
  color: #64748b;
  min-width: 22px;
  text-align: right;
}
.rank-row:nth-child(1) .rank-pos { color: #fbbf24; }
.rank-row:nth-child(2) .rank-pos { color: #94a3b8; }
.rank-row:nth-child(3) .rank-pos { color: #cd7f32; }

.rank-avatar-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.rank-avatar-wrap .rank-initials {
  position: absolute;
  inset: 0;
}
.rank-logo {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #0f172a;
  border: 1px solid #334155;
  object-fit: contain;
}

.rank-initials {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, #334155, #475569);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #e2e8f0;
  flex-shrink: 0;
}

.rank-info {
  flex: 1;
  min-width: 0;
}

.rank-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-meta {
  font-size: 0.7rem;
  color: #64748b;
}

.rank-stats {
  text-align: right;
  flex-shrink: 0;
}

.rank-score {
  font-size: 0.85rem;
  font-weight: 700;
  color: #34d399;
}

.rank-followers {
  font-size: 0.7rem;
  color: #a78bfa;
}

.rank-empty {
  text-align: center;
  color: #475569;
  padding: 32px 0;
  font-size: 0.9rem;
}

/* Death rank */
.death-rank {
  font-size: 1rem;
  color: #fbbf24;
  font-weight: 600;
}

.death-best {
  font-size: 0.85rem;
  color: #64748b;
}

#joinBtn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #22d3ee, #818cf8);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}

#joinBtn:hover { opacity: 0.9; }
#joinBtn:disabled { opacity: 0.5; cursor: not-allowed; }

.online-count {
  margin-top: 16px;
  font-size: 0.85rem;
  color: #64748b;
}


.how-to-play {
  margin-top: 20px;
  text-align: left;
  border-top: 1px solid #334155;
  padding-top: 16px;
}

.how-to-play h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  margin-bottom: 8px;
}

.how-to-play ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.how-to-play li {
  font-size: 0.82rem;
  color: #94a3b8;
  line-height: 1.4;
}

.how-to-play kbd {
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.75rem;
  font-family: inherit;
  color: #e2e8f0;
}

.how-to-play .text-green {
  color: #34d399;
  font-weight: 600;
}

/* Food legend */
.food-legend {
  margin-top: 6px;
}

.food-icon {
  display: inline-block;
  width: 20px;
  text-align: center;
  font-size: 0.9rem;
}
.food-speed { color: #fbbf24; }
.food-shield { color: #818cf8; }
.food-ghost { color: #e879f9; }
.food-jackpot { color: #34d399; }

/* Death buttons */
.death-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.death-buttons button {
  padding: 10px 32px;
  background: linear-gradient(135deg, #22d3ee, #818cf8);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.death-buttons button:hover { opacity: 0.9; }

.death-buttons .btn-secondary {
  background: #334155;
}

.death-buttons .btn-secondary:hover {
  background: #475569;
}

/* ── Game ── */
#game {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #0f172a;
}

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.9) 0%, transparent 100%);
  pointer-events: none;
}

#hudLeft, #hudRight, #hudCenter {
  display: flex;
  gap: 10px;
}

#hud span {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 10px;
  background: rgba(30, 41, 59, 0.8);
  border-radius: 5px;
  border: 1px solid #334155;
}

#hudName { color: #22d3ee; }
#hudFollowers { color: #a78bfa; }
#hudScore { color: #34d399; }
#hudKills { color: #f472b6; }
#hudPlayers { color: #fbbf24; }

/* ── Leaderboard ── */
#leaderboard {
  position: absolute;
  top: 52px;
  right: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 170px;
  pointer-events: none;
}

#leaderboard h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  margin-bottom: 6px;
}

#leaderList {
  list-style: none;
  padding: 0;
}

#leaderList li {
  font-size: 0.75rem;
  padding: 2px 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

#leaderList li .leader-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}

#leaderList li .leader-score {
  color: #34d399;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Death ── */
#deathScreen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.85);
  z-index: 10;
}

.death-card {
  background: #1e293b;
  border: 1px solid #ef4444;
  border-radius: 16px;
  padding: 40px;
  text-align: center;
}

.death-card h2 {
  color: #ef4444;
  font-size: 2rem;
  margin-bottom: 16px;
}

.death-card p {
  font-size: 1.1rem;
  margin-bottom: 8px;
}


/* ── Mobile Controls ── */
#mobileControls {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
  pointer-events: auto;
}

.ctrl-row {
  display: flex;
  gap: 4px;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid #475569;
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ctrl-btn:active {
  background: rgba(34, 211, 238, 0.3);
}

@media (max-width: 740px) {
  .lobby-layout {
    flex-direction: column;
    align-items: center;
  }
  .lobby-card { width: 100%; max-width: 380px; }
  .rankings-panel { width: 100%; max-width: 380px; max-height: 300px; }
}

@media (pointer: coarse) {
  #mobileControls { display: flex; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
