html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: "Segoe UI", Roboto, sans-serif;
  color: #eee;
}

#game-canvas {
  display: block;
  position: fixed;
  inset: 0;
  background: #111;
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 16px;
  border-radius: 8px;
}

#score {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#controls-hint {
  margin-top: 4px;
  font-size: 12px;
  color: #b8b8c8;
}

.hud-btn {
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  background: #33334d;
  color: #eee;
}

.hud-btn:hover {
  background: #45456a;
}

#dash-label {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #9aa0c0;
}

#dash-key-hint {
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 4px;
  background: #33334d;
  color: #eee;
  font-weight: 600;
}

#dash-meter {
  margin-top: 4px;
  width: 160px;
  height: 10px;
  border-radius: 5px;
  background: #23233a;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#dash-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: #4b7bec;
  transition: width 0.08s linear, background-color 0.15s ease;
}

#dash-meter-fill.ready {
  background: #ffd700;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.7);
}

#dash-meter-fill.active {
  background: #ff5d5d;
  box-shadow: 0 0 8px rgba(255, 93, 93, 0.7);
}

#leaderboard {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(0, 0, 0, 0.55);
  padding: 10px 18px;
  border-radius: 8px;
  min-width: 170px;
}

#leaderboard h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: #ffd23f;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

#leaderboard-list {
  margin: 0;
  padding: 0 0 0 18px;
  font-size: 13px;
  line-height: 1.6;
}

#leaderboard-list li.me {
  color: #ffd700;
  font-weight: 700;
}

#connection-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #b33939;
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

#connection-banner.hidden {
  display: none;
}

#game-over-overlay,
#name-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 15, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease;
}

#game-over-overlay.hidden,
#name-modal.hidden {
  display: none;
}

.panel {
  background: linear-gradient(160deg, #1f1f3a, #14141f);
  padding: 36px 48px;
  border-radius: 16px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  min-width: 260px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 30px;
  color: #ff5d5d;
  letter-spacing: 1px;
}

#name-modal .panel h2 {
  color: #ffd23f;
}

.panel p {
  margin: 0 0 20px;
  font-size: 17px;
  color: #cfcfe0;
}

#name-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 20px;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #0f0f1a;
  color: #eee;
}

.panel button {
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  background: #ffd23f;
  color: #1a1a2e;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.panel button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(255, 210, 63, 0.4);
}

.panel button:active {
  transform: translateY(0);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Touch-Bedienelemente: Sichtbarkeit hängt an body.touch-device (main.js setzt die
   Klasse per Feature-Detection), nicht an der Viewport-Breite - ein Touchscreen-Laptop
   im Breitbild-Modus soll den Dash-Button trotzdem bekommen. */
#dash-btn {
  display: none;
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 72px;
  height: 72px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  margin-top: 0;
  touch-action: none;
  user-select: none;
  /* Ladestand als kreisförmige Füllung direkt im Button, per JS gesetzt
     (siehe updateDashMeter in main.js) - spart die separate Balken-Anzeige
     aus dem HUD, die auf Touch ohnehin weit vom Daumen entfernt wäre. */
  --dash-charge: 0%;
  background: conic-gradient(#4b7bec var(--dash-charge), #23233a var(--dash-charge));
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: #eee;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
}

#dash-btn.ready {
  background: #ffd700;
  color: #1a1a2e;
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.7);
}

#dash-btn.active {
  background: #ff5d5d;
  box-shadow: 0 0 14px rgba(255, 93, 93, 0.7);
}

body.touch-device #dash-btn {
  display: flex;
}

body.touch-device #dash-key-hint {
  display: none;
}

/* Touch steuert immer über den schwimmenden Joystick, unabhängig vom
   absolut/relativ-Tastaturmodus - der Umschalt-Button hat für Touch keine
   Funktion mehr. */
body.touch-device #control-toggle {
  display: none;
}

@media (max-width: 820px) {
  #hud {
    /* Muss neben #leaderboard (max-width 42vw) Platz lassen. */
    max-width: 54vw;
    box-sizing: border-box;
    padding: 6px 12px;
  }

  #leaderboard {
    min-width: 0;
    max-width: 42vw;
    padding: 8px 14px;
  }
}

@media (max-width: 480px) {
  #hud {
    /* Muss neben #leaderboard (max-width 38vw, siehe unten) Platz lassen,
       sonst überlappen sich beide Boxen auf schmalen Screens. */
    max-width: 55vw;
    box-sizing: border-box;
    padding: 6px 10px;
  }

  #score {
    font-size: 16px;
  }

  #controls-hint {
    font-size: 11px;
  }

  .hud-btn {
    padding: 10px 14px;
    min-height: 44px;
    box-sizing: border-box;
  }

  #dash-meter {
    width: min(160px, 40vw);
  }

  #leaderboard {
    max-width: 38vw;
    padding: 6px 10px;
  }

  #leaderboard h3 {
    font-size: 11px;
  }

  #leaderboard-list {
    font-size: 11px;
  }

  .panel {
    padding: 24px 20px;
    min-width: 0;
    width: min(320px, 92vw);
    box-sizing: border-box;
  }

  .panel h2 {
    font-size: 22px;
  }
}
