@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&display=swap');

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

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c28;
  --border: #2a2a3d;
  --accent: #7c3aed;
  --accent2: #a855f7;
  --green: #22c55e;
  --red: #ef4444;
  --text: #f1f5f9;
  --muted: #64748b;
  --radius: 16px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  overflow: hidden;
}

/* SCREENS */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active { display: flex; }

/* LOGO */
.logo {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 700;
  background: linear-gradient(135deg, #a855f7, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  text-align: center;
}
.tagline {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 32px;
}

/* CARD */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* INPUTS */
input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 16px;
  width: 100%;
  outline: none;
  transition: border-color .2s;
}
input[type="text"]:focus { border-color: var(--accent2); }
input[type="text"]::placeholder { color: var(--muted); }
#input-code { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; text-align: center; }

/* BUTTONS */
.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 13px 20px;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent2); }

/* JOIN ROW */
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }

/* DIVIDER */
.divider {
  text-align: center;
  color: var(--muted);
  position: relative;
  font-size: .875rem;
}
.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ERROR */
.error-msg { color: var(--red); font-size: .875rem; min-height: 20px; text-align: center; }

/* WAITING ROOM */
.waiting-card { max-width: 480px; text-align: center; }
.room-code-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 2px; }
.room-code {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 12px;
  color: var(--accent2);
  background: var(--surface2);
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background .15s;
}
.room-code:hover { background: var(--border); }
.players-title { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; }
.players-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 40px; }
.player-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: .9rem;
}
.player-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.player-chip.is-host { border-color: var(--accent2); }
.waiting-msg { color: var(--muted); font-size: .875rem; }

/* COUNTDOWN */
#screen-countdown { background: var(--bg); }
.countdown-number {
  font-size: 20vmin;
  font-weight: 700;
  background: linear-gradient(135deg, #a855f7, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pulse 1s ease-in-out;
}
@keyframes pulse {
  0% { transform: scale(1.4); opacity: 0; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.countdown-label { color: var(--muted); font-size: 1.2rem; margin-top: 12px; }

/* GAME */
#screen-game { padding: 0; }
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(10,10,15,.85);
  backdrop-filter: blur(8px);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}
#hud-players { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.hud-player {
  display: flex; align-items: center; gap: 5px;
  font-size: .8rem; font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
  transition: opacity .3s;
}
.hud-player.dead { opacity: .3; text-decoration: line-through; }
.hud-player .hud-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.zone-warning {
  color: #fbbf24;
  font-size: .8rem;
  font-weight: 600;
  animation: blink 1s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

#canvas {
  display: block;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

/* DEAD OVERLAY */
#dead-overlay {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  background: rgba(10,10,15,.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 40px;
  backdrop-filter: blur(12px);
  z-index: 20;
  pointer-events: none;
}
.dead-msg { font-size: 2rem; font-weight: 700; }
.dead-sub { color: var(--muted); margin-top: 6px; }

/* END SCREEN */
.end-card { max-width: 480px; text-align: center; }
.winner-display {
  font-size: 1.4rem;
  font-weight: 700;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface2);
}
.scoreboard { display: flex; flex-direction: column; gap: 8px; }
.score-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .95rem;
}
.score-row .rank { color: var(--muted); width: 24px; font-weight: 700; }
.score-row .sname { flex: 1; font-weight: 600; text-align: left; }
.score-row .pts { color: var(--accent2); font-weight: 700; }
.score-row.winner-row { border: 1px solid var(--accent2); }

/* Mobile controls */
#mobile-controls {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
}
.d-pad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; }
.d-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.d-btn:active { background: rgba(255,255,255,.18); }
.d-center { grid-column: 2; grid-row: 2; opacity: 0; pointer-events: none; }

@media (pointer: coarse) { #mobile-controls { display: block; } }
