:root {
  --bg: #121924;
  --panel: #121924;
  --ink: #e8f0ff;
  --muted: #e8f3ae;
  --accent: #5eb1ff;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

/* Start-Screen */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #1a2638, #112033);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.start-container {
  text-align: center;
  padding: 40px;
  background: rgba(18, 25, 36, 0.9);
  border-radius: 20px;
  border: 2px solid #2a374a;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}

.start-btn {
  font-size: 24px;
  padding: 20px 50px;
  cursor: pointer;
  transition: all 0.3s;
}

.start-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 24px rgba(94, 177, 255, 0.4);
}

/* Sidepanel als Modal (nur Einstellungen) */
aside {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 10001; /* Über dem Start-Screen (10000) */
  background: black;
  padding: 20px;
  overflow-y: auto;
  border: 2px solid #2a374a;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  max-width: 90vw;
  max-height: 90vh;
  width: 700px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

aside.modal-open {
  opacity: 1;
  pointer-events: all;
  transform: translate(-50%, -50%) scale(1);
}

/* Backdrop */
aside::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0);
  z-index: -1;
  transition: background 0.3s ease;
  pointer-events: none;
}

aside.modal-open::before {
  background: rgba(0, 0, 0, 0.7);
  pointer-events: all;
}

/* Close Button */
.modal-close {
  width: 100%;
  margin-bottom: 16px;
  background: linear-gradient(180deg, #2a374a, #1a2638);
  border-color: #3a475a;
  font-size: 14px;
  font-weight: bold;
}

.modal-close:hover {
  background: linear-gradient(180deg, #3a475a, #2a374a);
}

/* HUD Container für Punktestand und Protokoll */
.hud-container {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 100; /* Niedriger z-index damit Würfel darüber liegen */
  pointer-events: none;
  transition: left 0.3s ease, right 0.3s ease, top 0.3s ease, bottom 0.3s ease;
}

.hud-panel {
  background: rgba(18, 25, 36, 0.95);
  border: 1px solid #2a374a;
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(10px);
  min-width: 280px;
  max-width: 350px;
  pointer-events: all;
}

.hud-panel h3 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: bold;
}

.hud-scoreboard {
  border-left: 3px solid var(--accent);
}

.hud-log {
  border-left: 3px solid #ffd700;
}

/* Timer-Bar Styles */
.hud-timer {
  border-left: 3px solid #ef4444;
}

.timer-bar-container {
  width: 100%;
  height: 20px;
  background: rgba(15, 21, 32, 0.5);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px solid #2a374a;
}

.timer-bar-fill {
  height: 100%;
  background: #4ade80;
  transition: width 0.1s linear, background-color 0.3s ease;
  border-radius: 10px;
}

/* Timer-Warnung Animation (blinkt bei wenig Zeit) */
.timer-bar-fill.timer-warning {
  animation: timerBlink 0.5s ease-in-out infinite;
}

@keyframes timerBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.timer-text {
  text-align: center;
  font-size: 12px;
  font-weight: normal;
  color: var(--ink);
}

main {
  background-image: url("204849.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: crosshair;
}

#grid {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 200; /* Über dem HUD (100), aber unter Modals */
  transform: translate(-50%, -50%);
  transition: transform 0.3s ease;
  border: 1px groove #2a374a51;
}

h1 {
  font-size: 20px;
  margin-bottom: 16px;
  text-align: center;
  color: var(--accent);
}

fieldset {
  border: 1px solid #2a374a;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
  text-align: left;
}

legend {
  color: var(--muted);
  font-size: 13px;
  padding: 0 8px;
  font-weight: bold;
}

label {
  display: inline-block;
  margin: 8px 0 6px;
  font-size: 14px;
  min-width: 70px;
}

input[type="range"],
select,
input[type="color"],
input[type="number"] {
  width: 100%;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #2a374a;
  background: #0f1520;
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #2a374a;
  background: #0f1520;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
}

.btn.primary {
  background: linear-gradient(180deg, #1a2638, #112033);
  border-color: #294262;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(94, 177, 255, 0.2);
}

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

#currentPlayerDisplay {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--accent);
  font-weight: bold;
  text-align: center;
  padding: 12px 24px;
  background: rgba(15, 21, 32, 0.9);
  border: 1px solid currentColor;
  border-radius: 12px;
  z-index: 100; /* Niedriger z-index damit Würfel darüber liegen */
  font-size: 18px;
  backdrop-filter: blur(10px);
}

/* Hinweis für #-Taste - jetzt Teil des HUD-Containers */
.settings-hint {
  padding: 10px 16px;
  background: rgba(15, 21, 32, 0.95);
  border: 1px solid #2a374a;
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  backdrop-filter: blur(10px);
  transition: opacity 0.3s;
  pointer-events: all;
  text-align: center;
  border-left: 3px solid var(--accent);
}

.settings-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

.cube {
  position: absolute;
  border-radius: 4px;
  border: 1px solid #fff;
  transition: transform 0.2s, filter 0.2s;
  cursor: crosshair;
}

/* Deutlicheres Powerup-Design */
.cube.powerup {
  border: 1px solid gold;
  box-shadow: 0 0 30px 8px rgba(255, 215, 0, 0.15), 0 0 12px rgba(255, 200, 0, 0.25);
  animation: powerPulse 1.2s ease-in-out infinite;
  z-index: 50;
  transform-origin: center center;
  overflow: visible;
}

/* Icon-Overlay im Würfel (zentriert) */
.cube .power-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8em;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  opacity: 0.98;
  filter: drop-shadow(0 6px 12px rgba(255, 215, 0, 0.25));
}

/* stärkere Puls-Animation (Skalierung + subtle rotate) */
@keyframes powerPulse {
  0% {
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.18));
  }
  50% {
    transform: scale(1.08) rotate(1deg);
    filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.28));
  }
  100% {
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.18));
  }
}

/* Bei getroffenen Würfeln weiterhin explode-Animation */
.cube.hit.powerup {
  animation: explode 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 20px gold, inset 0 0 10px rgba(255, 215, 0, 0.3);
  }
  50% {
    box-shadow: 0 0 30px gold, inset 0 0 20px rgba(255, 215, 0, 0.5);
  }
}

@keyframes explode {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.5) rotate(180deg);
    opacity: 0.7;
  }
  100% {
    transform: scale(0) rotate(360deg);
    opacity: 0;
  }
}

.cube.hit {
  animation: explode 0.5s ease-out forwards;
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFly 1s ease-out forwards;
}

@keyframes particleFly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

.scoreboard div {
  margin-bottom: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(15, 21, 32, 0.5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.scoreboard .combo {
  font-size: 11px;
  color: #ffd700;
  margin-left: 8px;
}

.scoreboard .accuracy {
  font-size: 11px;
  color: #5eb1ff;
  margin-left: 8px;
}

.log {
  height: 140px;
  overflow: auto;
  background: rgba(15, 21, 32, 0.3);
  border: 1px solid rgba(42, 55, 74, 0.5);
  border-radius: 8px;
  padding: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
}

.log .combo-msg {
  color: #ffd700;
  font-weight: bold;
}

.log .powerup-msg {
  color: #ffa500;
  font-weight: bold;
}

#resetButton {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #2a374a;
  background: #0f1520;
  color: var(--ink);
  cursor: pointer;
  width: 100%;
  justify-content: center;
}

#resetButton:hover {
  background-color: #e74c3c;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

#pointsOwn,
#pointsEnemy {
  width: 60px;
  min-width: 60px;
  display: inline-block;
  text-align: center;
  padding: 6px;
}

#players {
  width: 100%;
  font-size: 14px;
  padding: 6px;
}

#difficulty {
  width: 100%;
  padding: 6px;
}

#colorPickers {
  text-align: center;
  margin: 12px 0;
}

#colorPickers label {
  margin: 4px;
}

.game-over-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #1a2638, #112033);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 2px solid;
  z-index: 10000;
  min-width: 400px;
  animation: modalAppear 0.5s ease-out;
}

@keyframes modalAppear {
  from {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.game-over-modal h2 {
  font-size: 32px;
  margin-bottom: 20px;
}

.game-over-modal .ranking {
  margin: 20px 0;
  text-align: left;
}

.game-over-modal .ranking-item {
  padding: 10px;
  margin: 5px 0;
  background: rgba(15, 21, 32, 0.5);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
}

.game-over-modal .ranking-item.winner {
  background: rgba(15, 21, 32, 0.5);
  border: 1px solid currentColor;
  font-weight: bold;
}

/* Powerup Effekt an Klickposition */
.powerup-effect {
  position: absolute;
  pointer-events: none;
  width: 160px;
  height: 160px;
  margin-left: -80px;
  margin-top: -80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0);
  opacity: 0;
  z-index: 2000;
  mix-blend-mode: screen;
  transition: none;
}

.powerup-effect .core {
  width: 60%;
  height: 60%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 30% 30%,
    rgba(255, 244, 200, 0.95),
    rgba(255, 200, 0, 0.9) 40%,
    rgba(255, 150, 0, 0.6) 70%,
    rgba(255, 150, 0, 0) 100%
  );
  box-shadow: 0 0 40px 12px rgba(255, 200, 0, 0.25), 0 0 10px 2px rgba(255, 220, 120, 0.15);
  transform: scale(0.6);
  filter: blur(0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #2b2b2b;
  font-weight: 700;
  font-size: 1.6em;
}

/* Keyframes: schnell aufpuffen, rotieren und ausblenden */
@keyframes powerupPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  25% {
    transform: scale(1.08);
    opacity: 1;
  }
  60% {
    transform: scale(0.95) rotate(6deg);
    opacity: 0.95;
  }
  100% {
    transform: scale(1.4) rotate(18deg);
    opacity: 0;
  }
}

/* Zusätzliche leichte Strahlen-Ringschicht */
.powerup-effect .ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 40px 8px rgba(255, 200, 0, 0.18), 0 0 80px 18px rgba(255, 160, 0, 0.12);
  opacity: 0.9;
  transform: scale(0.8);
}

/* Anwenden der Animation */
.powerup-effect.animate {
  animation: powerupPop 850ms cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
}

@media (max-width: 420px) {
  .powerup-effect {
    width: 110px;
    height: 110px;
    margin-left: -55px;
    margin-top: -55px;
  }
  .powerup-effect .core {
    font-size: 1.1em;
  }

  .hud-container {
    top: 10px;
    left: 10px;
  }

  .hud-panel {
    min-width: 200px;
    max-width: 250px;
    font-size: 12px;
  }
}

/* Combo-Animation: kurzes Pulsieren des currentPlayerDisplay */
.combo-flash {
  animation: comboPulse 520ms cubic-bezier(0.2, 0.9, 0.2, 1);
  box-shadow: 0 8px 30px rgba(255, 160, 0, 0.28);
  transform-origin: center center;
}

@keyframes comboPulse {
  0% {
    transform: scale(1);
    filter: drop-shadow(0 0 0 rgba(255, 160, 0, 0));
  }
  40% {
    transform: scale(1.18);
    filter: drop-shadow(0 18px 48px rgba(255, 160, 0, 0.24));
  }
  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 0 rgba(255, 160, 0, 0));
  }
}

/* Optional: sichtbare Combo-Badge am getroffenen Würfel */
.combo-badge {
  position: absolute;
  pointer-events: none;
  background: linear-gradient(90deg, #ffd66b, #ff9b2f);
  color: #222;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  transform: translate(-50%, -140%);
  opacity: 0;
  animation: badgePop 700ms ease-out forwards;
  z-index: 1000;
}

@keyframes badgePop {
  0% {
    transform: translate(-50%, -140%) scale(0.6);
    opacity: 0;
  }
  40% {
    transform: translate(-50%, -160%) scale(1.06);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -200%) scale(1);
    opacity: 0;
  }
}
