:root {
  --bg: #0a0e17;
  --panel: rgba(12, 18, 32, 0.94);
  --accent: #00e5a0;
  --accent2: #7c5cff;
  --gold: #ffd54f;
  --text: #e8edf7;
  --muted: #8b95a8;
  --danger: #ff5c7a;
  --border: rgba(255, 255, 255, 0.08);
  --hud-bg: rgba(8, 12, 22, 0.72);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, #1a2844 0%, var(--bg) 55%);
  color: var(--text);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-container {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#game-container canvas {
  display: block;
}

/* —— Lobby —— */
.panel {
  position: relative;
  z-index: 10;
  max-width: 600px;
  margin: 1.5rem auto;
  padding: 1.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  box-shadow:
    0 0 0 1px rgba(0, 229, 160, 0.06),
    0 24px 80px rgba(0, 0, 0, 0.5);
}

.panel::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 20px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(0, 229, 160, 0.35), rgba(124, 92, 255, 0.2));
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.lobby-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-snake {
  --hex: polygon(100% 50%, 75% 93.3%, 25% 93.3%, 0% 50%, 25% 6.7%, 75% 6.7%);
  width: 48px;
  height: 48px;
  background: conic-gradient(from 200deg, #00e5a0, #7c5cff, #ffd54f, #00e5a0);
  clip-path: var(--hex);
  filter: drop-shadow(0 0 10px rgba(0, 229, 160, 0.35));
  flex-shrink: 0;
}

.logo-snake::after {
  content: '';
  display: block;
  width: 34px;
  height: 34px;
  margin: 7px;
  background: var(--panel);
  clip-path: var(--hex);
}

.lobby-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.wallet-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  flex-wrap: wrap;
}

.wallet-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.wallet-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.wallet-status.connected {
  color: var(--accent);
}
.wallet-status.connected::before {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(0, 229, 160, 0.7);
}

.wallet-status.disconnected {
  color: var(--danger);
}
.wallet-status.disconnected::before {
  background: var(--danger);
}

.wallet-status.checking {
  color: var(--gold);
}
.wallet-status.checking::before {
  background: var(--gold);
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.join-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.join-form input,
.join-form select {
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s;
}

.join-form input:focus,
.join-form select:focus {
  outline: none;
  border-color: rgba(0, 229, 160, 0.45);
}

.room-label {
  margin-bottom: -0.25rem;
}

.usdc-price-hint {
  font-size: 0.75rem;
  margin: 0;
}

.room-tiers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.room-tier {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    box-shadow 0.15s;
}

.room-tier:hover {
  border-color: rgba(0, 229, 160, 0.35);
}

.room-tier.selected {
  border-color: rgba(0, 229, 160, 0.65);
  background: rgba(0, 229, 160, 0.08);
  box-shadow: 0 0 0 1px rgba(0, 229, 160, 0.2);
}

.room-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  opacity: 0.92;
}

.room-entry {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.room-entry-free {
  color: #6ee7b7;
}

.room-sparkle-detail {
  font-size: 0.78rem;
  color: var(--gold);
}

.room-meta {
  font-size: 0.7rem;
  color: var(--muted);
}

.room-tier.locked {
  border-style: dashed;
}

.room-tier.locked .room-entry {
  color: var(--muted);
}

.room-lock {
  margin-top: 0.15rem;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--gold);
  background: rgba(255, 213, 79, 0.12);
  border: 1px solid rgba(255, 213, 79, 0.3);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
}

.entry-summary {
  font-size: 0.78rem;
  margin: 0;
}

.entry-summary.locked-hint {
  color: var(--gold);
}

.btn {
  padding: 0.7rem 1.15rem;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(135deg, #f6851b, #e2761b);
  color: #fff;
  box-shadow: 0 4px 20px rgba(246, 133, 27, 0.35);
}

.btn.accent {
  background: linear-gradient(135deg, var(--accent), #00b8d4);
  color: #041018;
  box-shadow: 0 4px 24px rgba(0, 229, 160, 0.3);
}

.btn.small {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text);
}

.muted {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.error.notice {
  color: var(--accent);
}

.saved-balance {
  font-size: 0.9rem;
  color: var(--gold);
  margin-bottom: 0.75rem;
}

.hidden {
  display: none !important;
}

.howto {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.howto h2 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.howto ul {
  padding-left: 1.1rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.6;
}

.howto strong {
  color: var(--gold);
}

.howto .note {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.85;
}

/* —— Skin picker —— */
.skin-picker {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.skin-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem;
  background: rgba(255,255,255,0.04);
  border: 1.5px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.72rem;
  font-family: inherit;
  transition: border-color 0.18s, background 0.18s;
}

.skin-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.22);
}

.skin-btn.active {
  border-color: var(--accent);
  background: rgba(0, 229, 160, 0.08);
  color: var(--accent);
}

.skin-btn.locked {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: rgba(255,255,255,0.06);
}

.skin-kills-count {
  font-size: 0.7rem;
  color: var(--muted);
  margin-left: 0.4rem;
}

.skin-preview {
  border-radius: 6px;
  display: block;
}

.panel.game-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
  transition: opacity 0.3s;
}

/* —— In-game HUD —— */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hud-player-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.55rem 0.85rem;
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  max-width: 200px;
}

#hud-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.balance-pill {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 213, 79, 0.4);
  letter-spacing: 0.02em;
}

.boost-bar-wrap {
  padding: 0.45rem 0.75rem;
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  max-width: 200px;
}

.boost-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.boost-track {
  height: 6px;
  margin: 0.35rem 0 0.25rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}

.boost-fill {
  height: 100%;
  width: 30%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #00b8d4);
  transition: width 0.15s, opacity 0.15s;
  opacity: 0.45;
}

.boost-fill.active {
  width: 100%;
  opacity: 1;
  box-shadow: 0 0 12px rgba(0, 229, 160, 0.6);
}

.boost-fill.no-fuel {
  opacity: 0.25;
  background: linear-gradient(90deg, #666, #888);
}

.boost-hint {
  font-size: 0.65rem;
  color: var(--muted);
}

.hud-center {
  justify-self: center;
}

.leaderboard {
  list-style: none;
  padding: 0.5rem 0.75rem;
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  min-width: 180px;
  font-size: 0.78rem;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0;
  color: var(--muted);
}

.leaderboard li.me {
  color: var(--accent);
  font-weight: 600;
}

.leaderboard .rank {
  width: 1rem;
  color: var(--muted);
  opacity: 0.7;
}

.leaderboard .pts {
  margin-left: auto;
  color: var(--gold);
  font-weight: 600;
}

.hud-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.players-pill {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  backdrop-filter: blur(8px);
}

/* —— Death overlay —— */
.death-screen {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(4, 8, 16, 0.22);
  backdrop-filter: none;
  pointer-events: none;
}

.death-screen__panel {
  width: 100%;
  max-width: 360px;
  padding: 1.5rem 1.75rem;
  text-align: center;
  background: rgba(8, 12, 22, 0.35);
  border: 1px solid rgba(255, 92, 122, 0.18);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.15);
  animation: death-screen-in 0.22s ease-out both;
}

.death-screen__eyebrow {
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.death-screen__title {
  margin-bottom: 0.45rem;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--text);
}

.death-screen__text {
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}

.death-screen__countdown {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold);
}

@keyframes death-screen-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, 0.82);
  backdrop-filter: blur(8px);
}

.overlay-card {
  text-align: center;
  padding: 2.25rem;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid rgba(255, 92, 122, 0.25);
  max-width: 380px;
  box-shadow: 0 0 60px rgba(255, 92, 122, 0.15);
}

.overlay-card h2 {
  font-size: 1.75rem;
  color: var(--danger);
  margin-bottom: 0.5rem;
}

.overlay-card p {
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* —— Debug overlay (dev mode) —— */
.debug-overlay {
  position: fixed;
  bottom: 0.75rem;
  right: 0.75rem;
  z-index: 50;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid rgba(0, 229, 160, 0.18);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-family: 'Space Mono', 'Courier New', monospace;
  font-size: 0.67rem;
  color: #8b95a8;
  line-height: 1.7;
  pointer-events: none;
  user-select: none;
  min-width: 170px;
}

.dbg-title {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(0, 229, 160, 0.5);
  margin-bottom: 0.2rem;
}

.dbg-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.dbg-row span:last-child {
  color: #00e5a0;
  font-weight: 600;
  min-width: 58px;
  text-align: right;
}

.dbg-row span:last-child.warn { color: #ffd54f; }
.dbg-row span:last-child.bad  { color: #ff5c7a; }

@media (max-width: 720px) {
  .hud {
    grid-template-columns: 1fr 1fr;
  }
  .hud-center {
    grid-column: 1 / -1;
    order: 3;
    justify-self: stretch;
  }
  .leaderboard {
    width: 100%;
  }
}
