* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #0a0a1a;
  color: #e0e0f0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}
.hidden { display: none !important; }
.screen { display: none; }
.screen.active { display: flex; }

/* Lobby */
#lobby {
  justify-content: center; align-items: center;
  width: 100%; min-height: 100vh;
}
.lobby-content {
  background: #111128;
  border: 2px solid #333;
  border-radius: 16px;
  padding: 32px 40px;
  max-width: 420px; width: 90%;
  text-align: center;
  box-shadow: 0 0 40px rgba(80,60,200,0.15);
}
.lobby-content h1 { font-size: 28px; margin-bottom: 24px; letter-spacing: 2px; }
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; color: #888; margin-bottom: 6px; }
input[type="text"] {
  width: 100%; padding: 10px 14px;
  background: #1a1a35; border: 1px solid #444; border-radius: 8px;
  color: #e0e0f0; font-size: 16px; text-align: center;
  outline: none; transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: #6688ff; }

.mode-selector { display: flex; gap: 8px; margin: 16px 0; }
.mode-selector .mc-btn { flex: 1; }
.diff-selector { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.diff-selector .mc-btn { font-size: 13px; padding: 8px 16px; }

.mc-btn {
  background: #222244; border: 1px solid #444;
  color: #bbb; cursor: pointer; font-size: 15px;
  padding: 10px 20px; border-radius: 8px;
  transition: all 0.15s; user-select: none;
}
.mc-btn:hover { background: #333366; color: #fff; }
.mc-btn.active { background: #4466aa; border-color: #6688ff; color: #fff; font-weight: 600; }
.mc-btn.active.easy { background: #446644; border-color: #66aa44; }
.mc-btn.active.normal { background: #4466aa; border-color: #6688ff; }
.mc-btn.active.hard { background: #aa4444; border-color: #ff6644; }
.mc-btn.primary { background: #4466cc; border-color: #6688ff; color: #fff; font-weight: 600; }
.mc-btn.primary:hover { background: #5577dd; }
.mc-btn.small { font-size: 13px; padding: 7px 14px; }

.join-row { margin: 12px 0; }
#joinRow { display: flex; gap: 8px; margin-top: 8px; }
#joinRow input { flex: 1; }
.error { color: #ff6644; font-size: 13px; margin-top: 8px; padding: 8px; background: #331122; border-radius: 6px; }

/* Room */
#room { justify-content: center; align-items: center; width: 100%; min-height: 100vh; }
.room-content {
  background: #111128; border: 2px solid #333; border-radius: 16px;
  padding: 28px 36px; max-width: 400px; width: 90%; text-align: center;
  box-shadow: 0 0 40px rgba(80,60,200,0.15);
}
.room-content h2 { margin-bottom: 16px; }
.room-info { display: flex; gap: 20px; justify-content: center; font-size: 14px; color: #aaa; margin-bottom: 12px; }
.player-count { font-size: 14px; color: #888; margin-bottom: 12px; }
.player-list { margin: 12px auto; max-width: 280px; }
.player-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #1a1a35; border-radius: 8px; margin-bottom: 6px; }
.player-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.room-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* Game */
#game { flex-direction: column; align-items: center; width: 100%; padding: 8px; }
.game-wrapper { max-width: 100%; width: 100%; }
.game-message {
  background: rgba(0,0,0,0.7); padding: 4px 16px; border-radius: 4px;
  font-size: 14px; font-weight: 600; display: inline-block;
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 10; pointer-events: none;
  animation: flashIn 0.3s ease;
  color: #fff;
}
@keyframes flashIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

.canvas-wrap {
  background: #111; border: 2px solid #333; border-top: none;
  line-height: 0; position: relative;
  overflow: hidden; border-radius: 8px;
  display: inline-block;
}
#gameCanvas {
  width: 100%; max-width: 100%; height: auto;
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  max-height: 85vh;
  margin: 0 auto;
}

/* Mobile Controls */
.mobile-controls {
  display: none; justify-content: space-between; align-items: center;
  padding: 10px 16px; max-width: 500px; margin: 0 auto; gap: 16px;
}
.mc-dpad { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mc-dpad-mid { display: flex; gap: 4px; }
.mc-btn-dir {
  width: 52px; height: 52px; font-size: 18px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; background: #1a1a35;
  touch-action: none;
}
.mc-btn-shoot {
  width: 80px; height: 80px; font-size: 14px; font-weight: 700;
  border-radius: 50%; background: #cc3333; border-color: #ff4444; color: #fff;
  touch-action: none;
}
.mc-btn-shoot:hover { background: #dd4444; }
.mc-btn-shoot:active { background: #ff4444; transform: scale(0.95); }

@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .mobile-controls { display: flex; }
  .hud-right { display: none; }
  .game-header { font-size: 12px; min-height: 30px; }
    #gameCanvas { max-height: 60vh; }
}

/* Overlays */
.overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.75); display: flex;
  justify-content: center; align-items: center; z-index: 100;
}
.overlay-content {
  background: #111128; border: 2px solid #444; border-radius: 16px;
  padding: 32px; text-align: center; max-width: 400px; width: 90%;
  box-shadow: 0 0 50px rgba(0,0,0,0.5);
}
.overlay-content h2 { margin-bottom: 12px; font-size: 24px; }
.overlay-content p { color: #aaa; margin-bottom: 16px; }
.score-list { margin: 12px 0; text-align: left; }
.overlay-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a1a; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }