:root {
  --bg: #14161b;
  --panel: #1f2229;
  --text: #f2f3f5;
  --muted: #9aa0ab;
  --accent: #3ddc84;
  --me: #3ddc84;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: #ff6b6b; min-height: 1.2em; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
.btn-primary, .btn-secondary {
  padding: 14px 28px; border-radius: 12px; font-weight: 700; font-size: 1.1rem;
}
.btn-primary { background: var(--accent); color: #0d2417; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: #343944; }

/* ---------- host ---------- */
.host { overflow: hidden; }
.host canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; }
.lobby {
  position: fixed; inset: 0; overflow: auto;
  display: flex; flex-direction: column; gap: 24px; align-items: center;
  padding: 32px 16px; text-align: center;
}
.lobby section { width: min(860px, 100%); }
.lobby h1 { font-size: clamp(2rem, 5vw, 3.4rem); }
.lobby h2 { font-size: 1.3rem; margin-bottom: 12px; }
.join-box {
  display: flex; gap: 28px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border-radius: 18px; padding: 24px;
}
.qr { width: 190px; height: 190px; background: #fff; border-radius: 12px; overflow: hidden; }
.qr svg { width: 100%; height: 100%; display: block; }
.code { font-size: clamp(3rem, 9vw, 5.5rem); font-weight: 900; letter-spacing: 0.15em; line-height: 1.1; }
.join-url { font-family: ui-monospace, monospace; font-size: 1.05rem; word-break: break-all; }
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.player {
  padding: 14px 10px; border-radius: 12px; font-weight: 700;
  background: color-mix(in srgb, var(--c) 30%, var(--panel)); border: 2px solid var(--c);
}
.player.empty { border: 2px dashed #3a3f4a; background: transparent; color: var(--muted); font-weight: 400; }
.player.offline { opacity: 0.5; }
.games { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.game-card {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; min-width: 180px;
  background: var(--panel); border: 2px solid transparent; border-radius: 12px; text-align: left;
}
.game-card span { color: var(--muted); font-size: 0.85rem; }
.game-card.selected { border-color: var(--accent); }
.game-card.disabled { opacity: 0.4; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #000c; padding: 12px 20px; border-radius: 10px; font-weight: 600;
}

/* ---------- phone controller ---------- */
.pad {
  overflow: hidden; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
  border-top: 6px solid var(--me);
}
.view { height: 100%; padding: 16px; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.join { display: flex; flex-direction: column; gap: 16px; justify-content: center; max-width: 380px; margin: 0 auto; touch-action: auto; }
.join label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.join input {
  font: inherit; font-size: 1.4rem; padding: 12px; border-radius: 10px;
  border: 2px solid #343944; background: var(--panel); color: var(--text);
}
.join input#code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 800; }
.badge { padding: 10px 22px; border-radius: 999px; background: var(--me); color: #111; font-weight: 800; font-size: 1.3rem; }

.kart { display: flex; flex-direction: column; gap: 10px; padding: 10px; position: relative; }
.kart-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 1.1rem; }
.k-big { font-size: 2rem; font-weight: 900; color: var(--me); }
.kart-pad { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 0; }
.steer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pedals { display: grid; grid-template-rows: 2fr 1fr; gap: 10px; }
.pad-btn {
  border-radius: 18px; background: #2a2e37; font-size: 2.4rem; font-weight: 900;
  touch-action: none; transition: transform 60ms, background 60ms;
}
.pad-btn.gas { background: #1f6b43; font-size: 1.6rem; }
.pad-btn.brake { background: #6b1f25; font-size: 1.2rem; }
.pad-btn.down { transform: scale(0.96); background: var(--me); color: #111; }
.k-results {
  position: absolute; inset: 0; background: #14161bf2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.k-results #k-leader { display: flex; gap: 12px; }
.conn {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  background: #ffd23d; color: #111; padding: 6px 14px; border-radius: 8px; font-weight: 700;
}
