:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1f2733;
  --ink: #e8edf4;
  --muted: #8a97a8;
  --accent: #4ade80;
  --accent-2: #38bdf8;
  --danger: #f87171;
  --arena: #223042;
  --grid: rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

.center {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1.5rem;
  text-align: center;
}

h1 { font-size: 1.6rem; margin: 0; letter-spacing: 0.5px; }
.brand { color: var(--accent); }
.muted { color: var(--muted); }
small.muted { font-size: 0.8rem; }

/* ---- Pairing code ---- */
.code {
  font-size: clamp(3rem, 16vw, 9rem);
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: var(--panel);
  padding: 0.4em 0.6em;
  border-radius: 18px;
  border: 1px solid var(--panel-2);
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 16px;
  padding: 1.5rem;
  width: min(420px, 100%);
}

input[type="text"] {
  width: 100%;
  font-size: 2rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  padding: 0.6rem;
  border-radius: 12px;
  border: 1px solid var(--panel-2);
  background: var(--panel-2);
  color: var(--ink);
}

button {
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #06210f;
  cursor: pointer;
}
button.secondary { background: var(--panel-2); color: var(--ink); }
button:active { transform: translateY(1px); }

.hidden { display: none !important; }

/* ---- Screen arena layout ---- */
#arenaView {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
#arenaWrap {
  flex: 1;
  position: relative;
  min-height: 0;
}
canvas#arena {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#board {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 260px;
  max-height: calc(100% - 28px);
  overflow: hidden;
  background: rgba(10, 14, 20, 0.62);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px 14px;
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
}
#boardHead { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
#boardHead b { color: var(--accent); letter-spacing: 0.1em; }
.boardTitle {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  margin: 10px 0 4px;
  opacity: 0.9;
}
#lb { list-style: none; margin: 0; padding: 0; }
#lb li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.9rem;
}
#lb .rank { color: var(--muted); width: 18px; text-align: right; }
#lb .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lb .sc { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
#lb .dot { width: 9px; height: 9px; }
#feed { overflow-y: auto; font-size: 0.82rem; color: var(--muted); }
#feed .ev {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  animation: fadein 0.25s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }
#joinDock {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: rgba(255, 255, 255, 0.96);
  color: #111;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#joinDock #qr { width: 132px; height: 132px; }
#joinDock .lbl { font-size: 0.8rem; font-weight: 700; }
#joinDock .lbl b { letter-spacing: 0.15em; }

/* ---- Player (phone) ---- */
#playView {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  touch-action: none;
}
#playTop {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
}
#playTop .you { font-weight: 700; }
#stage {
  flex: 1;
  position: relative;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 40%, #24344a, #15202e);
}
canvas#mini {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.pad {
  position: absolute;
  bottom: 6%;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.15);
  touch-action: none;
}
#joystick { left: 5%; }
#aimstick { right: 5%; }
.padlbl {
  position: absolute;
  bottom: 8px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}
.knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.knob.aim { background: var(--accent-2); }

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.8rem;
}
.pill.charged {
  background: rgba(56,189,248,0.9);
  color: #06212e;
  font-weight: 700;
  animation: chargedpulse 0.6s ease-in-out infinite alternate;
}
@keyframes chargedpulse { from { filter: brightness(1); } to { filter: brightness(1.4); } }

#deathOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(120, 10, 10, 0.55);
  backdrop-filter: blur(2px);
  z-index: 5;
}
#deathText {
  font-size: 3rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.05em;
  text-shadow: 0 3px 12px rgba(0,0,0,0.6);
}
#deathOverlay .sub { color: rgba(255,255,255,0.85); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.swatch {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent;
}
.swatch.active { border-color: #fff; }
.err { color: var(--danger); }
.ok { color: var(--accent); }

/* ---- Admin control layout ---- */
#adminBar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-2);
}
#ctrlHeader {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 0;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  font-size: 0.95rem;
  border-radius: 10px;
}
.tab.active { background: var(--panel-2); color: var(--ink); }
.plain {
  text-transform: none;
  letter-spacing: normal;
  font-size: 1rem;
  text-align: left;
}
.addUser { display: flex; gap: 8px; flex-wrap: wrap; }
.addUser .plain { flex: 1 1 200px; }
select.plain {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--panel-2);
  border-radius: 12px;
  padding: 0 10px;
}
.userRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--panel-2);
}
.userRow .email { flex: 1; word-break: break-all; }
.badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.admin { background: rgba(74,222,128,0.18); color: var(--accent); }
.badge.gm { background: rgba(56,189,248,0.18); color: var(--accent-2); }
.linkbtn {
  background: none;
  color: var(--danger);
  padding: 4px 6px;
  font-size: 0.85rem;
}
label.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.9rem;
  color: var(--ink);
}
.gobtn {
  background: var(--accent-2);
  color: #06212e;
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 10px;
}
#adminMain {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}
#adminMapWrap {
  position: relative;
  flex: 1 1 420px;
  aspect-ratio: 1 / 1;
  max-width: 640px;
  background: var(--bg);
  border-radius: 14px;
}
canvas#adminMap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
#mapHint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(0,0,0,0.4);
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
}
#adminSide {
  flex: 1 1 240px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#adminSide .card { width: 100%; padding: 1rem; }
.tools { display: flex; gap: 8px; }
.tool {
  flex: 1;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.2;
  padding: 10px 6px;
  border: 2px solid transparent;
}
.tool small { color: var(--muted); font-size: 0.7rem; }
.tool.active { border-color: var(--accent); }
#scoreboard .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 2px;
  border-bottom: 1px solid var(--panel-2);
}
#scoreboard .row b { color: var(--accent); }
.dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; vertical-align:middle; }
