:root {
  --bg: #0c0e14;
  --fg: #e6e8ee;
  --muted: #8a93a6;
  --red: #ef4444;
  --blue: #3b82f6;
  --accent: #22d3ee;
  --card: #161a23;
  --error: #fca5a5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}
.screen.hidden { display: none; }

h1 { font-size: 48px; margin: 0; letter-spacing: 4px; }
h2 { font-size: 28px; margin: 0; }
h3 { margin: 0 0 8px 0; }

.muted { color: var(--muted); font-size: 13px; }

.menu-card {
  background: var(--card);
  padding: 24px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(360px, 90vw);
}
.menu-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.menu-card .row { display: flex; gap: 8px; }
.menu-card .row label { flex: 1; }
.menu-card input,
.menu-card select { font-size: 18px; padding: 10px; border-radius: 6px; border: 1px solid #2a3144; background: #0e1119; color: var(--fg); }
.menu-card button { font-size: 16px; padding: 12px; border-radius: 6px; border: 0; background: var(--accent); color: #001318; cursor: pointer; font-weight: 600; }
.menu-card button:hover { filter: brightness(1.1); }
.divider { text-align: center; color: var(--muted); font-size: 12px; }
.error { color: var(--error); font-size: 13px; min-height: 16px; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: min(720px, 95vw);
}
.team {
  background: var(--card);
  padding: 16px;
  border-radius: 12px;
  border-top: 4px solid var(--muted);
}
.team-red { border-top-color: var(--red); }
.team-blue { border-top-color: var(--blue); }
.team ul { list-style: none; padding: 0; margin: 0 0 12px 0; min-height: 80px; }
.team li { padding: 6px 0; }
.team li.ready::after { content: " ✓"; color: var(--accent); }
.btn-join-team { width: 100%; padding: 10px; border-radius: 6px; border: 0; background: #1f2535; color: var(--fg); cursor: pointer; }

.lobby-settings {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--card);
  padding: 12px 16px;
  border-radius: 10px;
}
.lobby-settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.lobby-settings select {
  padding: 8px;
  background: #0e1119;
  color: var(--fg);
  border: 1px solid #2a3144;
  border-radius: 6px;
  font-size: 14px;
}
.lobby-settings select:disabled { opacity: 0.55; }

.lobby-controls { display: flex; gap: 12px; align-items: center; justify-content: center; }
.lobby-controls button { padding: 12px 20px; border-radius: 6px; border: 0; background: var(--accent); color: #001318; font-weight: 600; cursor: pointer; }
.lobby-controls button.hidden { display: none; }

#screen-game {
  padding: 8px;
  gap: 8px;
}
#hud {
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 12px;
}
#rally {
  font-size: 14px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(34,211,238,0.5);
  min-height: 16px;
}
#rally.hidden { visibility: hidden; }
#rally[data-mult="3"] { color: #facc15; text-shadow: 0 0 10px rgba(250,204,21,0.6); }
#rally[data-mult="4"] { color: #f97316; text-shadow: 0 0 12px rgba(249,115,22,0.7); }
#score-red { color: var(--red); }
#score-blue { color: var(--blue); }
.hud-sep { color: var(--muted); }

#canvas-wrap {
  position: relative;
  width: min(100vw - 16px, calc((100vh - 120px) * 1000 / 600));
}
#canvas {
  background: #050810;
  width: 100%;
  height: auto;
  aspect-ratio: 1000 / 600;
  border-radius: 6px;
  display: block;
  touch-action: none;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  color: var(--accent);
  pointer-events: none;
  text-shadow: 0 0 18px rgba(34,211,238,0.55);
  letter-spacing: 4px;
  font-weight: 700;
}
#overlay.hidden { display: none; }

#touch-controls.hidden { display: none !important; }
#touch-controls {
  display: block;
  position: fixed;
  inset: 0;
  pointer-events: none;
}
#touch-pad-area {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}
#touch-smash {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #001318;
  font-weight: 700;
  font-size: 14px;
  pointer-events: auto;
  user-select: none;
}

#screen-end button { margin: 6px; padding: 12px 20px; border-radius: 6px; border: 0; cursor: pointer; }
#btn-rematch { background: var(--accent); color: #001318; font-weight: 600; }
#btn-leave { background: #1f2535; color: var(--fg); }
