/* ── Base ── */

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

body {
  background: #0a0a0a;
  margin: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: 'Courier New', Courier, monospace;
  color: #00ffff;
}

/* CRT scanlines overlay */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
  z-index: 50;
}

/* ── Canvas ── */

#game-canvas {
  display: block;
}

/* ── Shared overlay helpers ── */

.hidden {
  display: none !important;
}

/* ── Join Screen ── */

#join-screen {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  background: rgba(10, 10, 10, 0.92);
  border: 2px solid #00ffff;
  box-shadow: 0 0 10px #00ffff, inset 0 0 10px #00ffff;
  padding: 40px 48px;
  border-radius: 12px;
  text-align: center;
  min-width: 300px;
}

#join-screen .title {
  font-size: 2.4em;
  color: #00ffff;
  text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff, 0 0 40px #00ffff;
  margin-bottom: 28px;
  letter-spacing: 4px;
}

#join-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

#name-input {
  width: 100%;
  padding: 12px 16px;
  background: #111;
  border: 2px solid #00ffff;
  border-radius: 6px;
  color: #00ffff;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.1em;
  text-align: center;
  outline: none;
  transition: box-shadow 0.2s;
}

#name-input::placeholder {
  color: rgba(0, 255, 255, 0.35);
}

#name-input:focus {
  box-shadow: 0 0 10px #00ffff, inset 0 0 10px #00ffff;
}

#play-btn {
  padding: 12px 40px;
  background: #00ffff;
  color: #0a0a0a;
  border: none;
  border-radius: 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2em;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff;
  transition: box-shadow 0.2s, transform 0.1s;
}

#play-btn:hover {
  box-shadow: 0 0 20px #00ffff, 0 0 40px #00ffff;
  transform: scale(1.04);
}

/* ── Death Screen ── */

#death-screen {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  background: rgba(10, 10, 10, 0.92);
  border: 2px solid #ff00ff;
  box-shadow: 0 0 10px #ff00ff, inset 0 0 10px #ff00ff;
  padding: 40px 48px;
  border-radius: 12px;
  text-align: center;
  min-width: 300px;
}

.death-title {
  font-size: 2.8em;
  color: #ff00ff;
  text-shadow: 0 0 10px #ff00ff, 0 0 20px #ff00ff, 0 0 40px #ff00ff;
  margin-bottom: 16px;
  letter-spacing: 6px;
}

#death-cause {
  font-size: 1.1em;
  color: #ff6666;
  text-shadow: 0 0 10px #ff6666;
  margin-bottom: 8px;
}

#death-score {
  font-size: 1.4em;
  color: #FFD700;
  text-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700;
  margin-bottom: 24px;
}

#play-again-btn {
  padding: 12px 40px;
  background: #ff00ff;
  color: #0a0a0a;
  border: none;
  border-radius: 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2em;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 0 10px #ff00ff, 0 0 20px #ff00ff;
  transition: box-shadow 0.2s, transform 0.1s;
}

#play-again-btn:hover {
  box-shadow: 0 0 20px #ff00ff, 0 0 40px #ff00ff;
  transform: scale(1.04);
}

/* ── Leaderboard ── */

#leaderboard {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  background: rgba(10, 10, 10, 0.75);
  border: 1px solid #00ffff;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.3), inset 0 0 8px rgba(0, 255, 255, 0.1);
  padding: 12px 16px;
  border-radius: 8px;
  max-width: 200px;
  min-width: 160px;
  font-size: 0.8em;
}

#leaderboard h3 {
  text-align: center;
  font-size: 0.9em;
  letter-spacing: 2px;
  color: #00ffff;
  text-shadow: 0 0 10px currentColor, 0 0 20px currentColor;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(0, 255, 255, 0.3);
  padding-bottom: 6px;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: rgba(0, 255, 255, 0.6);
  font-size: 0.95em;
}

.leaderboard-entry .lb-rank {
  width: 24px;
  text-align: right;
  margin-right: 6px;
  flex-shrink: 0;
}

.leaderboard-entry .lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-entry .lb-score {
  flex-shrink: 0;
  margin-left: 8px;
  text-align: right;
}

.leaderboard-entry.self {
  color: #00ffff;
  text-shadow: 0 0 10px currentColor, 0 0 20px currentColor;
  font-weight: bold;
}

/* ── Score Display ── */

#score-display {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  font-size: 1.3em;
  letter-spacing: 2px;
  color: #00ffff;
  text-shadow: 0 0 10px currentColor, 0 0 20px currentColor;
}

/* ── Player Count ── */

#player-count {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 60;
  font-size: 0.85em;
  color: rgba(0, 255, 255, 0.5);
  letter-spacing: 1px;
}

/* ── Mobile Controls ── */

#mobile-controls {
  display: none;
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  width: 200px;
  height: 200px;

  /* Cross layout via grid */
  display: grid;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px 60px;
  gap: 6px;
  justify-content: center;
  align-content: center;
  /* Hidden by default -- JS adds .show-mobile */
  display: none;
}

#mobile-controls.show-mobile {
  display: grid;
}

.ctrl-btn {
  width: 60px;
  height: 60px;
  background: rgba(10, 10, 10, 0.8);
  border: 2px solid #00ffff;
  box-shadow: 0 0 6px rgba(0, 255, 255, 0.4);
  color: #00ffff;
  font-size: 1.6em;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ctrl-btn:active {
  background: rgba(0, 255, 255, 0.15);
  box-shadow: 0 0 12px #00ffff;
}

/* Place buttons in cross: up=top-center, left=mid-left, right=mid-right, down=bot-center */
.ctrl-btn[data-dir="UP"]    { grid-column: 2; grid-row: 1; }
.ctrl-btn[data-dir="LEFT"]  { grid-column: 1; grid-row: 2; }
.ctrl-btn[data-dir="RIGHT"] { grid-column: 3; grid-row: 2; }
.ctrl-btn[data-dir="DOWN"]  { grid-column: 2; grid-row: 3; }
