* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  font-family: 'Fredoka', 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #070b14;
  color: #fff;
  touch-action: none;
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ==================== HUD STYLES ==================== */
.hud-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  padding: 16px;
}

.hud-container.hidden {
  display: none;
}

.hud-card {
  pointer-events: auto;
  background: rgba(16, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 12px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Top Left Stats */
.hud-stats {
  position: absolute;
  top: 16px;
  left: 16px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
}

.stat-icon {
  font-size: 20px;
}

.stat-label {
  color: #94a3b8;
}

.stat-val {
  font-weight: 700;
  color: #38bdf8;
  margin-left: auto;
}

/* Turbo Stamina Bar */
.turbo-bar-container {
  margin-top: 4px;
}

.turbo-label {
  font-size: 11px;
  font-weight: 700;
  color: #facc15;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.turbo-bar-bg {
  width: 100%;
  height: 9px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  overflow: hidden;
}

.turbo-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #eab308, #f59e0b, #ef4444);
  border-radius: 10px;
  transition: width 0.08s ease-out;
}

/* Top Center Alive Card */
.hud-alive {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px;
  border-color: rgba(56, 189, 248, 0.35);
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.25) 0%, rgba(15, 23, 42, 0.85) 100%);
  white-space: nowrap;
}

.alive-icon {
  font-size: 28px;
  animation: pulse-alive 2s infinite ease-in-out;
}

@keyframes pulse-alive {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.alive-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #38bdf8;
}

.alive-counter {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

.alive-counter .highlight {
  color: #4ade80;
  font-size: 28px;
}

/* Top Right Leaderboard */
.hud-leaderboard {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 220px;
  padding: 12px 14px;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
}

.header-controls {
  display: flex;
  gap: 5px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-width: 34px;
  min-height: 34px;
  padding: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.08);
}

.mobile-lb-btn {
  display: none;
}

#leaderboardList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#leaderboardList li {
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

#leaderboardList li.is-player {
  background: rgba(56, 189, 248, 0.25);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #38bdf8;
  font-weight: 700;
}

#leaderboardList li .lb-rank {
  width: 18px;
  color: #94a3b8;
  font-size: 12px;
}

#leaderboardList li .lb-name {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}

#leaderboardList li .lb-score {
  font-size: 12px;
  color: #facc15;
}

/* Kill Feed */
.kill-feed {
  position: absolute;
  top: 155px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  max-width: 320px;
}

.kill-msg {
  background: rgba(15, 23, 42, 0.85);
  border-left: 4px solid #ef4444;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: slide-in 0.3s ease-out forwards;
}

.kill-msg.player-kill {
  border-left-color: #22c55e;
  background: rgba(21, 128, 61, 0.85);
  font-weight: 700;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Mini-Map */
.minimap-container {
  pointer-events: auto;
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.3s ease;
}

#minimapCanvas {
  display: block;
  border-radius: 8px;
  background: #0f172a;
}

.minimap-label {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Mobile Boost Button */
.mobile-boost-btn {
  display: none;
  pointer-events: auto;
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  border: 4px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 10px 25px rgba(239, 68, 68, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  z-index: 50;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.mobile-boost-btn.active,
.mobile-boost-btn:active {
  transform: scale(0.92);
  background: linear-gradient(135deg, #fbbf24, #f97316);
  box-shadow: 0 0 35px rgba(251, 191, 36, 0.9), inset 0 2px 6px rgba(255, 255, 255, 0.6);
}

/* ==================== OVERLAYS & MODALS ==================== */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 11, 25, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 16px;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 28px;
  padding: 30px 34px;
  max-width: 520px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(56, 189, 248, 0.2);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: pop-modal 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-modal {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.banner-title h1 {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #38bdf8, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 6px 0;
}

.subtitle {
  color: #cbd5e1;
  font-size: 15px;
  font-weight: 500;
}

.bubble-tag {
  display: inline-block;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Settings Form */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-group label {
  font-size: 14px;
  font-weight: 700;
  color: #e2e8f0;
}

.setting-group input, .setting-group select {
  background: rgba(15, 23, 42, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  outline: none;
  transition: all 0.2s;
  touch-action: manipulation;
}

.setting-group input:focus, .setting-group select:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* Color Picker */
.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  touch-action: manipulation;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: #ffffff;
  transform: scale(1.18);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.8);
}

/* Instructions Box */
.instructions-box {
  background: rgba(15, 23, 42, 0.6);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 14px 16px;
  text-align: left;
}

.instructions-box h3 {
  font-size: 14px;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 6px;
}

.instructions-box ul {
  list-style: none;
  font-size: 13px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.4;
}

.instructions-box kbd {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  color: #facc15;
}

/* Primary Button */
.btn-primary {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff;
  border: none;
  border-radius: 16px;
  padding: 16px 28px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.6);
}

.btn-primary:active {
  transform: translateY(1px) scale(0.98);
}

/* Game Over Modal */
.modal-danger {
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(239, 68, 68, 0.25);
}

.modal-danger h2 {
  font-size: 30px;
  font-weight: 900;
  color: #ef4444;
}

.eaten-info {
  font-size: 15px;
  color: #cbd5e1;
}

/* Victory Modal */
.modal-victory {
  border-color: rgba(250, 204, 21, 0.5);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.7), 0 0 50px rgba(250, 204, 21, 0.35);
}

.modal-victory h2 {
  font-size: 32px;
  font-weight: 900;
  color: #facc15;
  text-shadow: 0 0 20px rgba(250, 204, 21, 0.5);
}

.victory-bounce {
  font-size: 58px;
  animation: bounce-crown 1.5s infinite ease-in-out;
}

@keyframes bounce-crown {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-12px) rotate(5deg); }
}

.victory-tag {
  background: rgba(250, 204, 21, 0.2);
  border-color: rgba(250, 204, 21, 0.6);
  color: #fde047;
  align-self: center;
}

.btn-gold {
  background: linear-gradient(135deg, #d97706 0%, #f59e0b 50%, #eab308 100%);
  color: #1e1b4b;
  font-weight: 900;
  box-shadow: 0 10px 25px rgba(245, 158, 11, 0.5);
}

.btn-gold:hover {
  box-shadow: 0 14px 35px rgba(245, 158, 11, 0.8);
}

/* Results Grid */
.game-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 6px 0;
}

.result-box {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px 6px;
}

.res-label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 4px;
}

.res-num {
  font-size: 24px;
  font-weight: 800;
  color: #38bdf8;
}

.res-num.gold-text {
  color: #facc15;
}

.hint-text {
  font-size: 13px;
  color: #fbbf24;
  line-height: 1.4;
}

/* ==================== TOUCH & TABLET / MOBILE OPTIMISIERUNG ==================== */

/* Touch-Geräte & Tablets (bis zu iPad Pro 12.9" 1366px): Turbo-Knopf anzeigen & Minimap links unten */
@media (pointer: coarse), (max-width: 1366px) {
  .mobile-boost-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .minimap-container {
    bottom: 20px;
    left: 16px;
    right: auto;
    padding: 4px;
  }

  #minimapCanvas {
    width: 110px;
    height: 110px;
  }
}

/* Wenn Touch erkannt wurde (Klassen-Fallback für alle Touchscreens) */
.touch-device .mobile-boost-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.touch-device .minimap-container {
  bottom: 20px !important;
  left: 16px !important;
  right: auto !important;
  padding: 4px;
}

/* Kleine Bildschirme & Smartphones (<= 768px) */
@media (max-width: 768px) {
  .hud-container {
    padding: 8px;
  }

  /* Kompakte Spieler-Stats oben links */
  .hud-stats {
    top: 8px;
    left: 8px;
    min-width: 115px;
    padding: 6px 10px;
    gap: 3px;
    border-radius: 12px;
  }

  .stat-item {
    font-size: 12px;
    gap: 4px;
  }

  .stat-icon {
    font-size: 14px;
  }

  .turbo-label {
    font-size: 8px;
    margin-bottom: 2px;
  }

  .turbo-bar-bg {
    height: 5px;
  }

  /* Kompaktes "Übrige Schlangen" mittig - garantiert kollisionsfrei! */
  .hud-alive {
    top: 8px;
    padding: 4px 8px;
    gap: 5px;
    border-radius: 12px;
  }

  .alive-icon {
    font-size: 16px;
  }

  .alive-title {
    display: none;
  }

  .alive-counter {
    font-size: 14px;
  }

  .alive-counter .highlight {
    font-size: 16px;
  }

  /* Steuerungs-Knöpfe oben rechts mit aufklappbarer Rangliste */
  .hud-leaderboard {
    top: 8px;
    right: 8px;
    width: auto;
    min-width: 0;
    padding: 5px 6px;
    border-radius: 12px;
  }

  .leaderboard-header {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
    gap: 3px;
  }

  .lb-title {
    display: none;
  }

  .mobile-lb-btn {
    display: flex;
  }

  #fullscreenToggleBtn {
    display: none; /* Auf Smartphones nicht benötigt */
  }

  .header-controls {
    gap: 3px;
  }

  .icon-btn {
    min-width: 28px;
    min-height: 28px;
    font-size: 12px;
    padding: 2px;
  }

  /* Rangliste auf mobilen Geräten als Dropdown-Menü */
  #leaderboardList {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 190px;
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid rgba(56, 189, 248, 0.4);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7);
    z-index: 40;
  }

  #leaderboardList.open {
    display: flex;
  }

  .kill-feed {
    top: 90px;
    left: 8px;
    max-width: 220px;
  }

  .kill-msg {
    font-size: 10px;
    padding: 3px 6px;
  }

  /* Modal-Anpassung für Handys */
  .modal {
    padding: 18px 16px;
    border-radius: 20px;
    gap: 12px;
  }

  .banner-title h1 {
    font-size: 24px;
  }

  .subtitle {
    font-size: 12px;
  }

  .color-dot {
    width: 36px;
    height: 36px;
  }

  .btn-primary {
    padding: 12px 20px;
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  .mobile-boost-btn {
    bottom: 18px;
    right: 18px;
    width: 76px;
    height: 76px;
    font-size: 13px;
  }

  .minimap-container {
    bottom: 16px;
    left: 12px;
  }

  #minimapCanvas {
    width: 90px;
    height: 90px;
  }

  .game-results {
    gap: 8px;
  }

  .res-num {
    font-size: 20px;
  }
}

/* ==================== PWA INSTALLATION BANNER ==================== */
.pwa-install-box {
  background: rgba(14, 165, 233, 0.12);
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  margin-top: 4px;
}

.pwa-install-box.hidden {
  display: none !important;
}

.pwa-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pwa-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.pwa-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  color: #e2e8f0;
}

.pwa-text strong {
  color: #38bdf8;
  font-size: 14px;
}

.pwa-text span {
  font-size: 12px;
  color: #94a3b8;
}

.btn-install {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: transform 0.2s, background 0.2s;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-install:hover {
  transform: scale(1.04);
}

@media (max-width: 480px) {
  .pwa-install-box {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .btn-install {
    width: 100%;
    text-align: center;
  }
}
