:root {
  --bg: #10141a;
  --panel: #1b212b;
  --panel-2: #232b38;
  --line: #333d4d;
  --text: #e8edf5;
  --dim: #93a1b5;
  --blue: #00b2e1;
  --blue-dark: #0086ac;
  --red: #f14e54;
  --green: #00e16e;
  --yellow: #f2b134;
  --radius: 10px;
  --font: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.hidden { display: none !important; }

button {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  padding: 11px 18px;
  cursor: pointer;
  transition: transform .06s ease, filter .12s ease;
  color: #fff;
}
button:active { transform: translateY(2px); }
button:hover { filter: brightness(1.12); }

button.primary { background: var(--blue); box-shadow: 0 4px 0 var(--blue-dark); }
button.primary:active { box-shadow: 0 2px 0 var(--blue-dark); }
button.ghost { background: var(--panel-2); box-shadow: 0 4px 0 #161c25; }
button.ghost:active { box-shadow: 0 2px 0 #161c25; }
button.big { font-size: 19px; padding: 15px 30px; width: 100%; }
button.mini { font-size: 12px; padding: 6px 11px; background: var(--panel-2); box-shadow: none; border-radius: 7px; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select {
  font-family: var(--font);
  font-size: 15px;
  background: #131820;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  width: 100%;
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); }

/* ======================================================== main menu === */
#menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% -10%, #1d2735 0%, transparent 60%),
    repeating-linear-gradient(0deg, #151a22 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, #151a22 0 1px, transparent 1px 40px),
    var(--bg);
  z-index: 20;
}

#menu-inner { width: min(720px, 100%); }

#menu header { text-align: center; margin-bottom: 22px; }
#menu h1 {
  font-size: clamp(46px, 9vw, 76px);
  margin: 0;
  letter-spacing: -2px;
  color: var(--blue);
  text-shadow: 0 5px 0 var(--blue-dark);
}
#menu h1 span { color: var(--text); text-shadow: 0 5px 0 #0e1219; }
.tagline { color: var(--dim); margin: 6px 0 0; font-size: 15px; }

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.panel h2 { margin: 0 0 16px; font-size: 21px; }

.row { display: flex; gap: 10px; margin-top: 12px; }
.row > button { flex: 1; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; text-align: center; }
.join-row button { flex: 0 0 110px; }

.field { display: block; margin-bottom: 4px; }
.field > span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; font-size: 14px; color: var(--dim); }
.checks label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.checks input { width: auto; }

.howto { margin-top: 16px; color: var(--dim); font-size: 14px; }
.howto summary { cursor: pointer; font-weight: 700; }
.howto ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.75; }
.howto b { color: var(--text); }

.notice {
  background: #3a2126;
  border: 2px solid #6b3138;
  color: #ffb4b8;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  text-align: center;
}

#menu footer { text-align: center; color: var(--dim); font-size: 13px; margin-top: 16px; }

#room-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.room {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border: 2px solid transparent;
}
.room:hover { border-color: var(--blue); }
.room .rname { font-weight: 700; flex: 1; }
.room .rmeta { color: var(--dim); font-size: 13px; }
.room .rcode { font-family: ui-monospace, monospace; color: var(--yellow); letter-spacing: 2px; }
.empty-note { color: var(--dim); text-align: center; padding: 24px; }

/* ============================================================= HUD === */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: none; }

#leaderboard {
  position: absolute;
  top: 12px; right: 12px;
  width: 205px;
  background: rgba(15, 19, 26, .72);
  border-radius: 10px;
  padding: 10px 12px;
}
#leaderboard h3 { margin: 0 0 8px; font-size: 13px; text-align: center; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
#lb-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
#lb-list li { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
#lb-list .bar { position: absolute; left: 0; top: 0; bottom: 0; opacity: .22; border-radius: 4px; }
#lb-list li > span { position: relative; }
#lb-list .lbname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list .lbscore { color: var(--dim); font-variant-numeric: tabular-nums; }
#lb-list li.me { font-weight: 700; }
.lb-row { position: relative; border-radius: 4px; padding: 3px 6px !important; }

#teamscores {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: rgba(15, 19, 26, .72);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
}

#minimap-wrap {
  position: absolute;
  right: 12px; bottom: 12px;
  background: rgba(15, 19, 26, .72);
  border-radius: 10px;
  padding: 6px;
  line-height: 0;
}
/* Opaque: a translucent minimap lets the arena show through and reads as noise. */
#minimap { border-radius: 6px; background: #10141a; }

#killfeed {
  position: absolute;
  top: 12px; left: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.kf-item { background: rgba(15, 19, 26, .7); border-radius: 6px; padding: 4px 9px; }
.kf-item b { color: var(--yellow); }

#stats-panel {
  position: absolute;
  left: 12px; bottom: 96px;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  width: 208px;
  pointer-events: auto;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  opacity: .92;
}
.stat-row.maxed { opacity: .38; cursor: default; }
.stat-row .key {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .12);
  font-size: 11px;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.stat-bar {
  position: relative;
  flex: 1;
  height: 21px;
  background: rgba(15, 19, 26, .7);
  border-radius: 5px;
  overflow: hidden;
}
.stat-bar .fill { position: absolute; inset: 0; width: 0; transition: width .15s ease; }
.stat-bar .pips { position: absolute; inset: 0; display: flex; }
.stat-bar .pips i { flex: 1; border-right: 1px solid rgba(0, 0, 0, .35); }
.stat-bar .pips i:last-child { border-right: none; }
.stat-bar .label {
  position: absolute; inset: 0;
  display: flex; align-items: center;
  padding-left: 7px;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  white-space: nowrap;
}
.stat-row.can-buy .stat-bar { box-shadow: 0 0 0 2px rgba(255, 255, 255, .55); }

#upgrade-panel {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  background: rgba(15, 19, 26, .82);
  border-radius: 12px;
  padding: 12px;
  pointer-events: auto;
  max-width: 260px;
}
.upgrade-title { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
#upgrade-cards { display: flex; flex-direction: column; gap: 6px; }
.upgrade-card {
  display: flex; flex-direction: column;
  gap: 2px;
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 9px;
  padding: 8px 11px;
  cursor: pointer;
}
.upgrade-card:hover { border-color: var(--blue); }
.upgrade-card b { font-size: 14px; }
.upgrade-card small { color: var(--dim); font-size: 11px; line-height: 1.3; }

#bottom-bar {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  width: min(560px, 92vw);
  text-align: center;
}
#score-line { font-size: 13px; color: var(--dim); margin-bottom: 5px; }
#score-line span { color: var(--text); font-weight: 700; font-size: 16px; }
#level-bar {
  position: relative;
  height: 24px;
  background: rgba(15, 19, 26, .75);
  border-radius: 12px;
  overflow: hidden;
}
#level-fill { position: absolute; inset: 0; width: 0; background: var(--yellow); transition: width .2s ease; }
#level-text {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}
#name-line { margin-top: 5px; font-size: 13px; color: var(--dim); }

#toggles {
  position: absolute;
  left: 12px; bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--dim);
}
.toggle b { color: var(--text); }

#chat-log {
  position: absolute;
  left: 12px; top: 90px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  max-width: 320px;
}
.chat-line { background: rgba(15, 19, 26, .65); border-radius: 6px; padding: 3px 8px; }
.chat-line .who { font-weight: 700; }
.chat-line.system { color: var(--dim); font-style: italic; }

#chat-input {
  position: absolute;
  left: 12px; bottom: 130px;
  width: 340px;
  pointer-events: auto;
}

#respawn {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: rgba(10, 13, 18, .78);
  pointer-events: auto;
  text-align: center;
}
#respawn h2 { margin: 0; font-size: 34px; }
#respawn p { margin: 0 0 8px; color: var(--dim); }
#respawn button { min-width: 220px; }

/* ======================================================= lobby bar === */
#lobby-bar {
  position: fixed;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 19, 26, .82);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 13px;
  z-index: 12;
}
#lobby-code { font-family: ui-monospace, monospace; letter-spacing: 3px; color: var(--yellow); }

#settings-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, .75);
  z-index: 30;
  padding: 20px;
  overflow-y: auto;
}
.modal-inner {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  width: min(620px, 100%);
}
.dim { color: var(--dim); font-size: 13px; margin-top: 0; }

/* ==================================================== touch controls === */
#touch-controls { position: fixed; inset: 0; z-index: 11; }
.stick {
  position: absolute;
  bottom: 24px;
  width: 132px; height: 132px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .07);
  border: 2px solid rgba(255, 255, 255, .16);
  touch-action: none;
}
#stick-move { left: 24px; }
#stick-aim { right: 24px; }
.knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .3);
}

@media (max-width: 720px) {
  #leaderboard { width: 150px; font-size: 12px; }
  /* Stacked above the level bar, which itself sits above the thumb sticks. */
  #stats-panel { width: 168px; bottom: 252px; }
  #minimap-wrap { transform: scale(.72); transform-origin: bottom right; }
  #bottom-bar { bottom: 172px; }
  #toggles { display: none; }
  #chat-input { width: calc(100vw - 24px); }
  .grid2 { grid-template-columns: 1fr; }
}

/* ==================================================== v4 additions ===== */

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--dim);
  margin: 18px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.section-label:first-of-type { margin-top: 4px; }

/* --- top bar: round banner + team scores --- */
#topbar {
  position: absolute;
  top: 46px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#round-banner {
  background: rgba(15, 19, 26, .82);
  border-radius: 10px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
#round-banner .rb-timer { color: var(--yellow); font-variant-numeric: tabular-nums; }
#round-banner .rb-sub { display: block; font-size: 11px; color: var(--dim); font-weight: 400; }
#round-banner.urgent .rb-timer { color: var(--red); }
#teamscores {
  position: static;
  transform: none;
  display: flex;
  gap: 10px;
  background: rgba(15, 19, 26, .72);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
}

/* --- chips on the score line --- */
.chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, .1);
}
#bounty-chip { background: rgba(242, 177, 52, .22); color: var(--yellow); }
#streak-chip { background: rgba(241, 78, 84, .22); color: #ff9a9e; }
#drone-chip  { background: rgba(0, 178, 225, .22); color: #7fd8f2; }

#mutator-strip {
  margin-top: 5px;
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 10px;
}
.mut-tag {
  background: rgba(191, 127, 245, .2);
  color: #d7b6fb;
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* --- ability HUD --- */
#ability-hud {
  position: absolute;
  right: 12px; bottom: 210px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 19, 26, .74);
  border-radius: 12px;
  padding: 9px 12px 9px 9px;
  max-width: 250px;
}
.ability-ring { position: relative; width: 56px; height: 56px; flex: 0 0 56px; }
#ability-canvas { width: 56px; height: 56px; }
.ability-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ability-meta b { font-size: 14px; }
.ability-meta small { font-size: 11px; color: var(--dim); line-height: 1.3; }
.ability-key { opacity: .65; }
#ability-hud.ready { box-shadow: 0 0 0 2px rgba(242, 177, 52, .55); }
#ability-hud.active { box-shadow: 0 0 22px rgba(242, 177, 52, .6); }

/* --- mutator vote --- */
#vote-panel {
  position: absolute;
  left: 50%; bottom: 120px;
  transform: translateX(-50%);
  background: rgba(15, 19, 26, .9);
  border-radius: 12px;
  padding: 12px 14px;
  pointer-events: auto;
  text-align: center;
}
.vote-title { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
#vote-options { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.vote-card {
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  min-width: 150px;
  text-align: left;
}
.vote-card:hover { border-color: var(--blue); }
.vote-card.chosen { border-color: var(--yellow); }
.vote-card b { display: block; font-size: 13px; }
.vote-card small { display: block; color: var(--dim); font-size: 11px; line-height: 1.3; }
.vote-card .tally { float: right; color: var(--yellow); font-weight: 700; }

/* --- killcam --- */
#killcam {
  background: rgba(30, 36, 47, .9);
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 300px;
  text-align: left;
}
.killcam-head { font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.killcam-head b { color: var(--red); font-size: 15px; }
.killcam-body { display: flex; flex-direction: column; gap: 6px; }
#kc-tank { font-weight: 700; font-size: 14px; }
#kc-stats { display: flex; flex-direction: column; gap: 3px; }
.kc-stat { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.kc-stat .kc-bar { width: 84px; height: 8px; border-radius: 4px; background: rgba(0, 0, 0, .4); overflow: hidden; }
.kc-stat .kc-fill { height: 100%; }
.kc-stat .kc-name { flex: 1; color: var(--dim); }
.spectate-hint { margin-top: 4px; }

/* --- end-of-round scoreboard --- */
#scoreboard {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(10, 13, 18, .86);
  pointer-events: auto;
  text-align: center;
  padding: 20px;
}
#scoreboard h2 { margin: 0; font-size: 32px; }
#sb-winner { margin: 0; font-size: 19px; color: var(--yellow); font-weight: 700; }
#sb-table { border-collapse: collapse; font-size: 14px; min-width: min(520px, 90vw); }
#sb-table th {
  text-align: left; color: var(--dim); font-size: 11px;
  text-transform: uppercase; letter-spacing: 1px; padding: 6px 12px;
}
#sb-table td { padding: 7px 12px; border-top: 1px solid var(--line); }
#sb-table tr.me { background: rgba(0, 178, 225, .14); font-weight: 700; }
#sb-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- touch ability button --- */
#touch-ability {
  position: absolute;
  right: 176px; bottom: 44px;
  width: 62px; height: 62px;
  border-radius: 50%;
  background: rgba(242, 177, 52, .3);
  border: 2px solid rgba(242, 177, 52, .6);
  color: #fff;
  font-size: 22px;
  padding: 0;
}

#toggles label { display: inline-flex; align-items: center; gap: 5px; }
#toggles input[type=range] { width: 60px; height: 3px; padding: 0; }

@media (max-width: 720px) {
  #ability-hud { right: 8px; bottom: 300px; max-width: 190px; padding: 6px; }
  .ability-meta small { display: none; }
  #vote-panel { bottom: 300px; }
  #topbar { top: 40px; }
  #sb-table { font-size: 12px; }
}

/* A maxed stat is a perk unlocked, not a dead row — make it look earned. */
.stat-row.maxed { opacity: 1; cursor: help; }
.stat-row.maxed .stat-bar { box-shadow: inset 0 0 0 1px rgba(242, 177, 52, .75); }
.stat-row.maxed .key { background: rgba(242, 177, 52, .3); color: var(--yellow); }
.stat-row.maxed .label::after { content: ' ★'; color: var(--yellow); }

/* The vote panel and the end-of-round scoreboard are both round-end UI, so the
   vote has to sit above the scoreboard's backdrop and clear of its table. */
#scoreboard { z-index: 2; }
#scoreboard #sb-table { margin-bottom: 96px; }
#vote-panel { z-index: 3; bottom: 26px; }

/* The class picker shares the left column with the stat bars, so anchor it
   above them and let it scroll rather than letting the two collide. */
#upgrade-panel {
  top: auto;
  bottom: 300px;
  transform: none;
  max-height: calc(100vh - 380px);
  overflow-y: auto;
}
.upgrade-card small {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 720px) {
  #upgrade-panel { bottom: 456px; max-height: calc(100vh - 540px); }
}

/* Five tier-1 choices must fit a 720p viewport without scrolling. */
.upgrade-card { padding: 6px 10px; gap: 0; }
.upgrade-card small { -webkit-line-clamp: 1; }

/* Between rounds the upgrade UI is inert (round start respawns everyone). */
#hud.between-rounds #stats-panel,
#hud.between-rounds #upgrade-panel { opacity: .4; pointer-events: none; }

/* Link out to the field guide from the main menu. */
.guide-link {
  flex: 1;
  display: block;
  text-align: center;
  padding: 11px 18px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px dashed var(--line);
  color: var(--dim);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.guide-link:hover { color: var(--text); border-color: var(--blue); }
