:root {
  --bg: #07101d;
  --panel: rgba(12, 24, 42, 0.92);
  --panel-edge: rgba(120, 160, 220, 0.25);
  --text: #eaf1fb;
  --muted: #93a6c2;
  --accent: #3b82f6;
  --accent-hi: #60a5fa;
  --danger: #ef4444;
  --hud: rgba(7, 16, 29, 0.82);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas#map {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */

.hud { display: none; }

body:not([data-state='menu']) .hud { display: flex; }

#hud-top {
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--hud);
  border-bottom: 1px solid var(--panel-edge);
  z-index: 5;
}

.stat { display: flex; flex-direction: column; min-width: 0; }
.stat .k {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat .v.gold { color: #facc15; }
.stat .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .sub { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }

.hud-buttons { margin-left: auto; display: flex; gap: 6px; }

.icon-btn {
  min-width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
  font-size: 14px;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.16); }

#board {
  position: fixed;
  right: 8px;
  top: calc(env(safe-area-inset-top) + 66px);
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  background: rgba(7, 16, 29, 0.6);
  border-radius: 8px;
  font-size: 11px;
  pointer-events: none;
  z-index: 4;
}
#board li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#board li.me { font-weight: 700; }
#board .sw { width: 9px; height: 9px; border-radius: 2px; flex: none; }
#board .pc { margin-left: auto; padding-left: 8px; font-variant-numeric: tabular-nums; color: var(--muted); }

#hud-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  flex-direction: column;
  gap: 4px;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--hud);
  border-top: 1px solid var(--panel-edge);
  z-index: 5;
}

.send-row { display: flex; align-items: center; gap: 12px; }
.send-row label { font-weight: 700; font-size: 14px; }
#pct-label {
  min-width: 112px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

input[type='range'] {
  flex: 1;
  height: 36px;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  touch-action: none;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
}
input[type='range']::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}
input[type='range']::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}

.action-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.act {
  flex: none;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: 14px;
}
.act:active { background: rgba(255, 255, 255, 0.18); }
.act.nuke { background: rgba(239, 68, 68, 0.25); border-color: rgba(239, 68, 68, 0.6); }
.act:disabled { opacity: 0.4; }
/* While you're aiming or placing something, the banner shows what to tap
   with a clear red Cancel button underneath. */
.banner[data-kind='mode'] { flex-direction: column; align-items: stretch; gap: 8px; text-align: center; }
.banner[data-kind='mode'] #btn-banner {
  align-self: center;
  min-width: 140px;
  height: 36px;
  padding: 0 20px;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.85);
  border: 1px solid rgba(254, 202, 202, 0.7);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}
.banner[data-kind='mode'] #btn-banner:active { background: rgba(185, 28, 28, 1); }
/* On a phone the button spans the banner, so it's easy to hit. */
@media (max-width: 520px) {
  .banner[data-kind='mode'] #btn-banner { align-self: stretch; height: 40px; }
}

.sheet {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(env(safe-area-inset-bottom) + 108px);
  max-width: 420px;
  margin: 0 auto;
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 7;
}
.sheet.show { display: flex; }
body:not([data-state='play']) .sheet { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; }
.sheet-head .icon-btn { min-width: 34px; height: 34px; }
.build-list { display: flex; flex-direction: column; gap: 6px; }
.build-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-align: left;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
}
.build-list button:active { background: rgba(255, 255, 255, 0.15); }
.build-list button:disabled { opacity: 0.45; }
.build-list button.danger { background: rgba(220, 38, 38, 0.22); border-color: rgba(248, 113, 113, 0.6); }
.build-list button.danger:active { background: rgba(220, 38, 38, 0.4); }
.build-list .bi { font-size: 24px; width: 30px; text-align: center; }
.build-list .bt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.build-list .bt small { color: var(--muted); font-size: 12px; }
.build-list .now { margin: 2px 2px 4px; font-size: 13px; color: var(--muted); }
.build-list .bc { font-weight: 800; color: #facc15; font-variant-numeric: tabular-nums; }

.hint {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Banner and toast ---------- */

.banner {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 110px);
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  z-index: 6;
  /* Long prompts wrap, so Cancel always stays on screen. */
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100vw - 16px);
}
.banner p { margin: 0; font-size: 14px; flex: 1 1 auto; min-width: 0; line-height: 1.3; }
.banner #btn-banner { flex: none; }
body[data-state='spawn'] .banner[data-kind='spawn'],
body[data-state='play'] .banner[data-kind='mode'] { display: flex; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 160px);
  transform: translate(-50%, 8px);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 9, 18, 0.55);
  z-index: 10;
  overflow-y: auto;
}
body[data-state='menu'] #menu,
body[data-state='lobby'] #lobby,
body[data-state='paused'] #pause,
#over.show { display: flex; }

.panel {
  width: 100%;
  max-width: 380px;
  margin: auto;
  padding: 24px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.panel h2 { margin: 0; font-size: 28px; }

.logo {
  margin: 0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  text-shadow: 3px 3px 0 #1d4ed8;
}
.logo span { color: var(--danger); text-shadow: 3px 3px 0 #7f1d1d; margin-left: 0.2em; }

.tag { margin: 0; color: var(--muted); font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}
.seg button.on { background: var(--accent); border-color: var(--accent-hi); }

.primary, .secondary {
  height: 50px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
}
.primary { border: 0; background: var(--accent); }
.primary:active { background: #2563eb; }
.secondary { border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.06); }
.secondary:active { background: rgba(255, 255, 255, 0.14); }
.secondary.small { height: 34px; font-size: 13px; padding: 0 12px; border-radius: 8px; }

.how { text-align: left; font-size: 14px; color: var(--muted); }
.how summary { cursor: pointer; color: var(--text); font-weight: 600; }
.how ul { padding-left: 18px; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.how b { color: var(--text); }

.record { margin: 0; font-size: 12px; color: var(--muted); min-height: 1em; }

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 4px 0;
  text-align: left;
  font-size: 15px;
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Every nation's statistics at the end of a game. */
.nations { overflow-x: auto; margin: 0 -8px; }
.nations table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.nations th { color: var(--muted); font-weight: 600; padding: 4px; text-align: right; white-space: nowrap; }
.nations td { padding: 4px; text-align: right; border-top: 1px solid var(--panel-edge); white-space: nowrap; }
.nations th:first-child, .nations td:first-child { text-align: left; }
.nations td small { color: var(--muted); font-size: 10px; }
.nations tr.me td { font-weight: 700; }
.nations tr.out td { opacity: 0.55; }
.nations .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

#over-title.win { color: #4ade80; }
#over-title.lose { color: var(--danger); }

/* ---------- Multiplayer ---------- */

body[data-state='lobby'] .hud { display: none; }
.mp-box { gap: 8px; }
.text {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  min-width: 0;
}
.mp-row { display: flex; gap: 6px; }
.mp-row .secondary { height: 42px; font-size: 15px; padding: 0 12px; flex: none; }
.code-in { flex: 1; text-transform: uppercase; letter-spacing: 0.2em; text-align: center; font-weight: 800; }
.room { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 44px; font-weight: 900; letter-spacing: 0.25em; color: var(--text); }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.players li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); font-weight: 600; }
.players .sw { width: 12px; height: 12px; border-radius: 3px; }
.tag.small { font-size: 12px; }
.primary:disabled { opacity: 0.45; }
.mp-only { display: none; }
body.mp .mp-only { display: block; }
body.mp #btn-restart { display: none; }
body.mp-client #btn-speed { visibility: hidden; }

/* Ten colours as two even rows of five. */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatches button {
  width: 100%;
  height: 32px;
  border-radius: 8px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.swatches button.on { border-color: #fff; transform: scale(1.12); }

.swatches button:disabled { opacity: 0.25; transform: scale(0.85); }
.players li.me { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.players .pn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .ps { font-size: 12px; font-weight: 700; color: var(--muted); }
.players .ps.ok { color: #4ade80; }

.players li.ai, .players li.off { font-weight: 500; }
.players li.off { opacity: 0.6; }
.players li.tog { cursor: pointer; }
.players li.tog:active { background: rgba(255, 255, 255, 0.12); }
.players .sw.empty { background: transparent; border: 1px dashed var(--muted); }
.players .ps.on { color: var(--accent-hi); }

body.mp-connecting #btn-ready,
body.mp-connecting .lobby-colour-field { display: none; }

.team-b {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
button.team-b { cursor: pointer; }
/* An AI nation's level in the lobby (the host taps to change it). */
.lvl-b {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  font-size: 11px;
  font-weight: 700;
}
button.lvl-b { cursor: pointer; }
.lvl-b.easy { background: rgba(34, 197, 94, 0.25); color: #dcfce7; border-color: rgba(74, 222, 128, 0.6); }
.lvl-b.normal { background: rgba(234, 179, 8, 0.22); color: #fef9c3; border-color: rgba(250, 204, 21, 0.6); }
.lvl-b.hard { background: rgba(239, 68, 68, 0.28); color: #fee2e2; border-color: rgba(248, 113, 113, 0.65); }
.team-b.t1 { background: rgba(59, 130, 246, 0.3); color: #dbeafe; border-color: rgba(96, 165, 250, 0.7); }
.team-b.t2 { background: rgba(239, 68, 68, 0.3); color: #fee2e2; border-color: rgba(248, 113, 113, 0.7); }
.team-b.t3 { background: rgba(234, 179, 8, 0.3); color: #fef9c3; border-color: rgba(250, 204, 21, 0.7); }
#board .tm {
  margin-right: 4px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 9px;
  font-weight: 800;
}

#board .bn { max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; }
#board .tr {
  min-width: 3.2em;
  padding-left: 8px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sound-row { display: flex; gap: 24px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  width: 50px;
  height: 28px;
  flex: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--panel-edge);
  transition: background 0.2s;
}
.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent-hi); }
.switch input:checked + .track .knob { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-hi); outline-offset: 2px; }

.build-list { max-height: calc(100vh - 260px); overflow-y: auto; }
#over .panel { max-width: 460px; }

/* ---------- Diplomacy ---------- */

/* Leaderboard rows open a nation's diplomacy panel. */
#board li { pointer-events: auto; cursor: pointer; padding: 3px 0; }

/* How an AI nation feels about you, from hostile (left) to trusted. */
.meter { margin: 2px 0 4px; }
.meter-bar {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #dc2626, #f97316 25%, #a3a3a3 50%, #84cc16 75%, #16a34a);
}
.meter-bar span {
  position: absolute;
  top: -3px;
  width: 6px;
  height: 16px;
  margin-left: -3px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5);
}
.rel-hostile { color: #f87171; }
.rel-wary { color: #fb923c; }
.rel-neutral { color: #d4d4d4; }
.rel-friendly { color: #a3e635; }
.rel-trusted { color: #4ade80; }

.aid-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.aid-row button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  font-weight: 700;
}
.aid-row small { font-weight: 500; color: var(--muted); font-size: 11px; }

/* An alliance offer from another nation. */
.offer {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 70px);
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  z-index: 8;
  width: min(92vw, 340px);
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  transition: opacity 0.2s, transform 0.2s;
}
.offer.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.offer p { margin: 0 0 10px; font-weight: 700; }
.offer-row { display: flex; gap: 8px; justify-content: center; }
.offer-row button,
.offer-row button.small {
  flex: 1 1 0;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid transparent;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 15px;
}
.offer-row .secondary { border-color: var(--panel-edge); }

/* The diplomacy button shows just its icon on narrow phones. */
@media (max-width: 520px) { #btn-diplo .lbl { display: none; } }

/* The list of nations in the diplomacy menu. */
.nation-row .bi .sw { display: inline-block; width: 18px; height: 18px; border-radius: 4px; }
.nation-row .bc { color: var(--muted); }
.back-btn { align-self: flex-start; padding: 6px 10px; font-size: 13px; }

/* On narrow phones the hint gets its own line under the buttons, so it isn't
   squeezed to a few letters. */
@media (max-width: 520px) {
  .action-row { flex-wrap: wrap; row-gap: 6px; }
  .hint { flex: 1 0 100%; order: 10; }
  .sheet { bottom: calc(env(safe-area-inset-bottom) + 126px); }
}

/* ---------- Tutorial ---------- */

.tut {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 62px);
  transform: translateX(-50%);
  z-index: 7;
  width: min(92vw, 380px);
  padding: 10px 14px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid rgba(96, 165, 250, 0.6);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  display: none;
}
body.tutorial[data-state='play'] .tut,
body.tutorial[data-state='spawn'] .tut { display: block; }
body.tutorial #board { display: none; }
.tut p { margin: 0 0 8px; font-size: 14px; line-height: 1.35; }
.tut .tut-step { margin-bottom: 4px; font-size: 11px; font-weight: 800; letter-spacing: 0.06em; color: #93c5fd; text-transform: uppercase; }
.tut.done { border-color: rgba(74, 222, 128, 0.8); }
.tut-row { display: flex; gap: 8px; }
.tut-row button { flex: 1 1 0; }

/* ---------- National perks ---------- */

#btn-special.ready { border-color: rgba(250, 204, 21, 0.7); background: rgba(250, 204, 21, 0.18); }
.perks-link {
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 700;
}
.perk-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  text-align: left;
  font-size: 13px;
}
.perk-row small { color: var(--muted); font-size: 12px; line-height: 1.35; }

/* ---------- In-game HUD (redesign) ---------- */

/* The bottom bar's real height, kept up to date from game.js, so sheets and
   the targeting banner always sit just above it. */
:root { --dock-h: 132px; }
.sheet { bottom: calc(var(--dock-h) + 8px); }
.banner { bottom: calc(var(--dock-h) + 10px); }
@media (max-width: 520px) { .sheet { bottom: calc(var(--dock-h) + 8px); } }

/* Top bar: compact stat chips, settings on the right. */
#hud-top { gap: 8px; padding: calc(env(safe-area-inset-top) + 6px) 10px 6px; overflow: visible; }
.stats { display: flex; gap: 6px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.stat {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.stat .ic { font-size: 14px; line-height: 1; }
.stat .v { font-size: 15px; }
.stat .sub { font-size: 11px; }
.hud-buttons { position: relative; align-items: center; }
.hud-menu { display: flex; gap: 6px; }
#btn-hud-menu { display: none; }
.icon-btn { min-width: 36px; height: 36px; }

/* Phones: sound, speed and pause tuck into a menu. */
@media (max-width: 600px) {
  #btn-hud-menu { display: block; }
  .hud-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    flex-direction: column;
    padding: 6px;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--panel-edge);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    z-index: 8;
  }
  .hud-menu.open { display: flex; }
  .stat { padding: 4px 8px; gap: 4px; }
  .stat .v { font-size: 14px; }
  .stats { gap: 4px; }
}
/* Very narrow phones: drop the clock's icon and tighten the chips. */
@media (max-width: 400px) {
  .stat { padding: 4px 6px; gap: 3px; }
  .stat .ic { font-size: 12px; }
  .stat:last-child .ic { display: none; }
  .stat .sub { display: none; }
}

/* Leaderboard: a pill showing your rank, which opens the full list. */
.board-pill {
  position: fixed;
  right: 8px;
  top: calc(env(safe-area-inset-top) + 58px);
  z-index: 4;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(7, 16, 29, 0.78);
  font-size: 12px;
  font-weight: 700;
}
.board-pill .chev { color: var(--muted); transition: transform 0.15s; }
body.board-open .board-pill .chev { transform: rotate(180deg); }
#board { top: calc(env(safe-area-inset-top) + 92px); background: rgba(7, 16, 29, 0.78); border: 1px solid var(--panel-edge); }
body:not(.board-open) #board { display: none; }

/* Messages appear at the top, clear of the menus and buttons. */
.toast { top: calc(env(safe-area-inset-top) + 60px); bottom: auto; transform: translate(-50%, -8px); }
.toast.show { transform: translate(-50%, 0); }

/* Send: quick percentage chips (plus a fine slider on wider screens). */
.send-row { gap: 8px; }
.send-k { font-weight: 700; font-size: 13px; color: var(--muted); }
.pct-chips { display: flex; gap: 4px; }
.pct-chips button {
  min-width: 46px;
  height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 700;
}
.pct-chips button.on { background: var(--accent); border-color: var(--accent-hi); }
#pct-label { min-width: 0; margin-left: auto; font-size: 13px; color: var(--muted); }
#pct-label b { color: var(--text); }
@media (max-width: 700px) { #pct { display: none; } }

/* The dock: five fixed tabs, icon over label. Locked ones stay in place,
   dimmed, so you can see what's still to come. */
.dock { display: flex; gap: 6px; }
.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 5px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.05);
}
.tab .ti { font-size: 20px; line-height: 1.1; }
.tab .tl { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab:active { background: rgba(255, 255, 255, 0.14); }
.tab.locked { opacity: 0.4; }
.tab.locked .tl::before { content: '🔒 '; font-size: 10px; }
.tab.wait .tl { color: var(--muted); font-variant-numeric: tabular-nums; }
.tab.nuke:not(.locked) { border-color: rgba(239, 68, 68, 0.55); background: rgba(239, 68, 68, 0.14); }
.tab.special.ready { border-color: rgba(250, 204, 21, 0.75); background: rgba(250, 204, 21, 0.16); }
.tab .badge {
  position: absolute;
  top: 3px;
  right: 6px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
}
/* Wide screens: the bottom bar's contents sit in a centred column. */
#hud-bottom > * { width: 100%; max-width: 720px; margin: 0 auto; }
.hint { text-align: center; font-size: 11px; }

/* Tile menus (Build). */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.build-list .tile {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  text-align: center;
  min-height: 78px;
}
.build-list .tile .bi { width: auto; font-size: 24px; }
.build-list .tile .tn { font-size: 12px; font-weight: 700; }
.build-list .tile .bc { font-size: 12px; }
.build-list .tile.sel { border-color: var(--accent-hi); background: rgba(59, 130, 246, 0.22); }
.build-list .tile.poor .bc { color: #f87171; }
.tile-detail {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.35);
  font-size: 13px;
  line-height: 1.4;
}
.tile-detail b { display: block; margin-bottom: 2px; font-size: 14px; }
.build-list .tile-detail button { margin-top: 8px; width: 100%; justify-content: center; background: var(--accent); border-color: var(--accent-hi); font-weight: 800; }

/* Someone has gone MAD: a red alert with a Retaliate button. */
.mad-alert { border-color: rgba(248, 113, 113, 0.8); box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.35), 0 12px 40px rgba(0, 0, 0, 0.5); z-index: 9; }
.mad-alert p small { display: block; margin-top: 4px; font-weight: 500; color: var(--muted); }
.mad-alert #btn-mad-yes { background: #dc2626; border-color: rgba(254, 202, 202, 0.7); }

/* Aiming on a touch screen: the prompt, then Cancel and Fire side by side. */
.banner[data-kind='mode'] { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.banner[data-kind='mode'] p { flex: 1 0 100%; }
.banner .aim-tip { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
.banner[data-kind='mode'] #btn-fire {
  min-width: 120px;
  height: 36px;
  padding: 0 20px;
  border-radius: 10px;
  background: #16a34a;
  border: 1px solid rgba(187, 247, 208, 0.7);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.banner #btn-fire:active { background: #15803d; }
@media (max-width: 520px) {
  .banner[data-kind='mode'] #btn-banner,
  .banner[data-kind='mode'] #btn-fire { flex: 1 1 0; }
}

/* MAD: what to hit first, a compact segmented row on the banner. */
.focus-seg {
  display: flex;
  gap: 2px;
  margin: 8px auto 0;
  padding: 2px;
  width: max-content;
  max-width: 100%;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-edge);
  overflow-x: auto;
}
.focus-seg button {
  flex: 1 0 auto;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.focus-seg button.on { background: rgba(220, 38, 38, 0.85); color: #fff; }
@media (max-width: 420px) { .focus-seg button { padding: 5px 6px; font-size: 11px; } }
.mad-alert .mad-clock { display: block; margin-top: 4px; font-size: 13px; font-weight: 700; color: #fca5a5; }
.mad-alert .mad-clock b { font-size: 16px; color: #fff; }

/* Spy odds on the aiming banner. */
.odds { display: inline-block; margin-left: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.odds.good { background: rgba(22, 163, 74, 0.3); color: #bbf7d0; }
.odds.fair { background: rgba(234, 179, 8, 0.25); color: #fde68a; }
.odds.poor { background: rgba(220, 38, 38, 0.3); color: #fecaca; }
