:root {
  color-scheme: dark;
  --bg: #05060a;
  --fg: #e8ecf4;
  --muted: #8a93a6;
  --card: #11141c;
  --line: #262c3b;
  --blade: #2f9bff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.err { color: #ff6b6b; min-height: 1.4em; }
button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--blade); border-color: transparent; color: #000; font-weight: 700; }
button.big { padding: 20px; font-size: 20px; width: 100%; }

/* ---------- landing ---------- */
body.landing { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.landing main { max-width: 420px; width: 100%; display: grid; gap: 12px; }
.landing a.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px;
}
.landing a.card b { display: block; font-size: 18px; margin-bottom: 4px; }

/* ---------- display ---------- */
body.display { overflow: hidden; height: 100vh; user-select: none; }
body.display canvas { position: fixed; inset: 0; display: block; }
#lobby {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: top left;
  text-align: center;
  background: rgba(10, 12, 18, 0.82);
  border: 1px solid #222838;
  border-radius: 24px;
  padding: 24px 32px;
  backdrop-filter: blur(6px);
  transition: top 0.6s ease, left 0.6s ease, transform 0.6s ease;
}
#lobby h1 { letter-spacing: 0.35em; font-weight: 300; font-size: 24px; margin-bottom: 16px; }
#lobby p { margin: 8px 0 0; }
#qr { width: min(42vh, 320px); aspect-ratio: 1; margin: 0 auto; background: #fff; border-radius: 12px; padding: 8px; }
#qr svg { width: 100%; height: 100%; display: block; }
.scan { font-size: 18px; }
#code { font: 700 44px/1 ui-monospace, Consolas, monospace; letter-spacing: 0.3em; margin-top: 12px !important; }
body.has-players #lobby { top: 16px; left: 16px; transform: translate(0, 0) scale(0.38); }
body.clean #lobby, body.clean #hint, body.clean #prompt, body.clean #tip { display: none !important; }

#scores {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 12px; pointer-events: none;
}
#scores .card {
  min-width: 120px; padding: 8px 14px; border-radius: 14px; text-align: center;
  background: rgba(10, 12, 18, 0.7); border: 1px solid color-mix(in srgb, var(--c) 60%, transparent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--c) 30%, transparent);
}
#scores .who { color: var(--c); font-weight: 700; letter-spacing: 0.15em; font-size: 13px; }
#scores .pts { font: 800 30px/1.1 ui-monospace, Consolas, monospace; }
#scores .net { color: var(--muted); font: 10px ui-monospace, Consolas, monospace; }

#banner {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  font: 800 13vh/1 system-ui, sans-serif; letter-spacing: 0.08em; color: #fff;
  text-shadow: 0 0 30px rgba(120, 180, 255, 0.9);
  opacity: 0; transform: scale(1.15); transition: opacity 0.25s, transform 0.25s;
}
#banner.show { opacity: 1; transform: scale(1); }

#hurt { position: fixed; inset: 0; pointer-events: none; }
#hurt.flash { animation: hurt 0.45s ease-out; }
@keyframes hurt {
  from { background: radial-gradient(ellipse at var(--x, 50%) 100%, rgba(255, 20, 20, 0.55), transparent 60%); }
  to { background: radial-gradient(ellipse at var(--x, 50%) 100%, rgba(255, 20, 20, 0), transparent 60%); }
}

#tip {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  max-width: min(760px, 90vw); text-align: center; font-size: 18px; line-height: 1.4;
  padding: 10px 20px; border-radius: 16px; background: rgba(10, 12, 18, 0.78); border: 1px solid var(--line);
}
#prompt {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px; background: rgba(10, 12, 18, 0.75);
  border: 1px solid var(--line); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }

#results {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  min-width: min(640px, 90vw); padding: 28px 36px; border-radius: 24px; text-align: center;
  background: rgba(8, 10, 16, 0.88); border: 1px solid #262c3b; backdrop-filter: blur(8px);
}
#results h2 { font: 800 64px/1.1 system-ui, sans-serif; margin: 0 0 18px; letter-spacing: 0.05em; }
#results .row {
  display: grid; grid-template-columns: 50px 60px 100px 1fr; align-items: center; gap: 12px;
  text-align: left; padding: 8px 12px; border-radius: 12px; margin-bottom: 6px;
  border-left: 4px solid var(--c); background: rgba(255, 255, 255, 0.04);
}
#results .row:first-child { background: color-mix(in srgb, var(--c) 18%, transparent); }
#results .rank { color: var(--muted); }
#results .who { color: var(--c); font-weight: 800; }
#results .pts { font: 800 26px ui-monospace, Consolas, monospace; }

.popup {
  position: fixed; pointer-events: none; transform: translate(-50%, -50%);
  font: 800 28px system-ui, sans-serif; text-shadow: 0 0 12px currentColor;
  animation: popup 1.1s ease-out forwards;
}
@keyframes popup {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.6); }
  20% { transform: translate(-50%, -90%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -240%) scale(1); }
}
#hint { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- controller ---------- */
body.controller {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}
.controller header { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { font: 12px ui-monospace, Consolas, monospace; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.pill[data-state="p2p"] { color: #6dffa0; border-color: #1f5a35; }
.pill[data-state="relay"] { color: #ffd26d; border-color: #5a4a1f; }
.pill[data-state="error"] { color: #ff6b6b; }
.controller main { flex: 1; display: flex; flex-direction: column; }
.controller section { flex: 1; display: flex; flex-direction: column; gap: 12px; justify-content: center; }
#join input {
  font: 700 40px/1 ui-monospace, Consolas, monospace; letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
  background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: 100%;
}
#play { justify-content: stretch; }
#me { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#meTag { color: var(--blade); font: 800 28px ui-monospace, Consolas, monospace; text-shadow: 0 0 12px var(--blade); }
#gameInfo { color: var(--fg); font-weight: 600; text-align: right; }
.pad {
  flex: 1;
  min-height: 28vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 24px;
  border: 2px solid var(--blade);
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--blade) 18%, transparent), transparent 70%), var(--card);
}
.pad.on {
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--blade) 55%, transparent), transparent 75%), var(--card);
  box-shadow: 0 0 40px color-mix(in srgb, var(--blade) 60%, transparent);
}
.pad-title { font-size: 32px; font-weight: 800; letter-spacing: 0.2em; }
.pad-sub { color: var(--muted); font-size: 14px; }
#colors { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
#colors button { aspect-ratio: 1; padding: 0; border-radius: 50%; background: var(--c); border: 3px solid transparent; }
#colors button.sel { border-color: #fff; box-shadow: 0 0 14px var(--c); }

/* ---------- display: force, combo, boss, slow-mo, hall of fame ---------- */
#scores .mult { color: #ffd84a; text-shadow: 0 0 8px #ffb000; }
#scores .force { height: 5px; margin: 4px 0 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
#scores .force i { display: block; height: 100%; background: var(--c); transition: width 0.25s; }
#scores .force.full i { background: #fff; box-shadow: 0 0 10px var(--c); animation: pulse 0.8s ease-in-out infinite; }

#bossbar {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); width: min(620px, 70vw);
  text-align: center; font: 700 13px/1 system-ui, sans-serif; letter-spacing: 0.35em; color: #ffb3c8;
}
#bossbar > div { margin-top: 6px; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); border: 1px solid #5a2a3a; overflow: hidden; }
#bossbar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff2a6a, #ff8a4a); box-shadow: 0 0 14px #ff2a6a; transition: width 0.2s; }

#slowfx { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.4s;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(60, 120, 255, 0.35)); }
body.slowmo #slowfx { opacity: 1; }

#hof {
  position: fixed; right: 16px; top: 16px; width: 240px; padding: 14px 18px; border-radius: 18px;
  background: rgba(10, 12, 18, 0.8); border: 1px solid var(--line);
}
#hof h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.3em; color: #ffd84a; font-weight: 700; }
#hof ol { margin: 0; padding-left: 22px; }
#hof li { padding: 2px 0; }
#hof li span { display: inline-block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
#hof li b { float: right; font-family: ui-monospace, Consolas, monospace; }
#awards { margin: 12px 0 0; font-weight: 700; }
body.clean #hof { display: none !important; }

/* ---------- controller: name, force, powers ---------- */
#name { font: inherit; font-size: 18px; background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; padding: 14px; width: 100%; }
#forceWrap { display: grid; gap: 8px; }
#forceWrap p { margin: 0; }
#forceBar { height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); overflow: hidden; }
#forceBar i { display: block; height: 100%; width: 0; background: var(--blade); transition: width 0.25s; }
#forceBar.full i { background: #fff; box-shadow: 0 0 12px var(--blade); }
#powers, #row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#powers button { font-weight: 800; font-size: 18px; }
#powers button:not(:disabled) { background: var(--blade); color: #000; border-color: transparent; box-shadow: 0 0 18px var(--blade); animation: pulse 0.9s ease-in-out infinite; }
#powers button:disabled { opacity: 0.4; }
#teamBtn { font-weight: 900; font-size: 20px; padding: 18px; background: #fff; animation: pulse 0.7s ease-in-out infinite; }
#teamBtn.voted { animation: none; opacity: 0.6; }
#gameInfo .mult { color: #ffd84a; }
