:root {
  --bg: #0a0a12;
  --bg-card: #12121e;
  --bg-elevated: #1a1a2e;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --primary: #00f0ff;
  --primary-dim: #00a0b0;
  --secondary: #ff00aa;
  --accent: #ffe600;
  --success: #00ff88;
  --danger: #ff3366;
  --border: #2a2a40;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
}

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

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

/* ===== MENU ===== */
.menu-content {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.logo {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.logo span {
  font-weight: 300;
}

.tagline {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.player-setup {
  margin-bottom: 24px;
  text-align: left;
}

.player-setup label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.player-setup input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s;
}

.player-setup input:focus {
  border-color: var(--primary);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.2s;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #00c0d0);
  color: #001018;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 2px solid transparent;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  opacity: 0.8;
}

.high-scores {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  text-align: left;
}

.high-scores h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

#high-score-list {
  list-style: none;
  font-size: 0.9rem;
}

#high-score-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

#high-score-list li:last-child {
  border-bottom: none;
}

.footer-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* ===== LOBBY ===== */
.lobby-content {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.lobby-content h2 {
  margin-bottom: 20px;
  font-size: 1.6rem;
}

.room-code-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.room-code-box .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.room-code-box .code {
  font-family: var(--mono);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--primary);
  margin-bottom: 12px;
}

.players-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  text-align: left;
}

.players-list h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

#lobby-players {
  list-style: none;
}

#lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

#lobby-players li:last-child {
  border-bottom: none;
}

.player-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.status-text {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.modal-content h3 {
  margin-bottom: 16px;
}

.code-input {
  width: 100%;
  padding: 14px;
  font-family: var(--mono);
  font-size: 1.6rem;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--primary);
  outline: none;
  margin-bottom: 16px;
}

.code-input:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1.2em;
}

/* ===== GAME ===== */
#game-screen {
  padding: 0;
  background: #05050a;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
}

#scoreboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.score-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  text-shadow: 0 1px 3px #000;
}

.score-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

#timer {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255,230,0,0.4);
}

#round-info {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.pause-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  background: rgba(0,0,0,0.4);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Touch Controls */
#touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 180px;
  pointer-events: none;
  z-index: 15;
}

#touch-controls.hidden {
  display: none;
}

#joystick-zone {
  position: absolute;
  left: 20px;
  bottom: 30px;
  width: 120px;
  height: 120px;
  pointer-events: auto;
}

#joystick-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  position: relative;
}

#joystick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0,240,255,0.5);
  border: 2px solid var(--primary);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.1s;
}

#btn-dash {
  position: absolute;
  right: 24px;
  bottom: 50px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(255,0,170,0.3);
  border: 2px solid var(--secondary);
  color: var(--text);
  font-weight: 700;
  font-size: 0.75rem;
  pointer-events: auto;
  cursor: pointer;
}

#btn-dash:active {
  background: rgba(255,0,170,0.6);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.overlay-content h2 {
  margin-bottom: 20px;
  font-size: 1.8rem;
}

#final-scores {
  margin-bottom: 24px;
  text-align: left;
}

#final-scores .place {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

#final-scores .place:first-child {
  color: var(--accent);
  font-size: 1.1rem;
}

.overlay-content .btn {
  width: 100%;
  margin-bottom: 10px;
}

/* Responsive */
@media (max-width: 480px) {
  .logo {
    font-size: 2.2rem;
  }
  
  .room-code-box .code {
    font-size: 1.8rem;
    letter-spacing: 4px;
  }
}

@media (min-width: 768px) {
  #touch-controls {
    display: none !important;
  }
}
