:root {
  --bg: #0b1020;
  --panel: rgba(12, 18, 36, 0.78);
  --border: rgba(120, 160, 255, 0.18);
  --text: #e8eeff;
  --muted: #8a98c0;
  --accent: #4dffb5;
  --danger: #ff5c7a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

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

#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: calc(100% - 200px);
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  min-width: 64px;
  backdrop-filter: blur(6px);
}
.stat .label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat span:last-child { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

#board {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 180px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  backdrop-filter: blur(6px);
}
#board h3 { margin: 0 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
#board ol { margin: 0; padding: 0; list-style: none; }
#board li { display: flex; gap: 6px; align-items: center; padding: 2px 0; }
#board li .sw { width: 15px; height: 10px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
#board li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li .pc { font-variant-numeric: tabular-nums; color: var(--muted); }
#board li.me .nm { color: var(--accent); font-weight: 800; }
#board-online { margin-top: 6px; font-size: 11px; color: var(--muted); }

#feed {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
#feed div {
  background: var(--panel);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  animation: fade 4s forwards;
}
#feed div.bad { color: #fff; background: rgba(170, 30, 55, 0.85); font-weight: 600; }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* red flash at the screen edges when you lose a life */
#hit {
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px 30px rgba(255, 40, 70, 0.75);
  opacity: 0;
}
#hit.on { animation: hit 0.7s ease-out; }
@keyframes hit { 0% { opacity: 1; } 100% { opacity: 0; } }

#minimap {
  position: fixed;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 150px;
  height: 150px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.5);
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

#zoom {
  position: fixed;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#zoom button, #chat-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 20px;
  backdrop-filter: blur(6px);
}
#chat-btn {
  position: fixed;
  left: 60px;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: auto;
  padding: 0 14px;
  font-size: 13px;
}
#chat-btn.on { color: var(--accent); border-color: var(--accent); }

/* The chat field is invisible: what you type is drawn above your avatar. */
#chat {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

#paused {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

#menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(11, 16, 32, 0.6), rgba(11, 16, 32, 0.25));
  padding: 86px 16px 16px;
  overflow-y: auto;
  pointer-events: none; /* the map behind the menu can be dragged and zoomed */
}
#menu .card { pointer-events: auto; }
body.spectating #game { cursor: grab; }
/* On wide screens the minimap and leaderboard stay usable above the menu. */
@media (min-width: 900px) {
  #minimap, #board { z-index: 1; }
}
body.dragging #game { cursor: grabbing; }
#menu[hidden] { display: none; }
.card {
  width: min(420px, 100%);
  margin: auto; /* centers, but scrolls from the top when taller than the screen */
  background: rgba(14, 20, 42, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.logo {
  display: block;
  width: 120px;
  height: 144px;
  margin: -78px auto 6px;
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.35)) drop-shadow(0 10px 18px rgba(0, 0, 0, 0.5));
  transform-origin: 50% 100%;
  animation: hop 2.6s ease-in-out infinite;
}
@keyframes hop {
  0%, 70%, 100% { transform: translateY(0) scale(1, 1); }
  76% { transform: translateY(0) scale(1.06, 0.94); }
  84% { transform: translateY(-12px) scale(0.97, 1.03); }
  92% { transform: translateY(0) scale(1.03, 0.97); }
}
@media (prefers-reduced-motion: reduce) { .logo { animation: none; } }
h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 30px;
  text-align: center;
  margin: 0 0 18px;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(77, 255, 181, 0.5), 3px 3px 0 #1d5bff;
}
.msg {
  text-align: center;
  color: var(--danger);
  font-weight: 600;
  margin: 0 0 14px;
}
.msg .score { display: block; color: var(--muted); font-weight: 400; font-size: 13px; margin-top: 4px; }
form { display: flex; gap: 8px; }
input {
  flex: 1;
  min-width: 0;
  background: #060a17;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  background: var(--accent);
  color: #04120c;
  border: 0;
  border-radius: 10px;
  padding: 0 20px;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
.pick { margin-top: 14px; }
.pick-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.swatches, .palette { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.swatches .custom {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: conic-gradient(#e74c3c, #f1c40f, #2ecc71, #1abc9c, #3498db, #9b59b6, #e84393, #e74c3c);
  cursor: pointer;
}
.swatches .custom::after {
  content: '+';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
.swatches .custom.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.swatches .custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; padding: 0; border: 0; cursor: pointer; }
.pick-label em { font-style: normal; text-transform: none; letter-spacing: 0; }
.flag-editor { display: flex; flex-direction: column; gap: 8px; }
#flag-editor {
  width: 100%;
  max-width: 288px;
  aspect-ratio: 16 / 10;
  image-rendering: pixelated;
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--border);
  cursor: crosshair;
  touch-action: none;
}
.flag-tools { display: flex; gap: 8px; align-items: flex-start; }
.palette { flex: 1; gap: 4px; }
.palette button {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.15);
}
#flag-fill {
  flex: none;
  padding: 6px 10px;
  font-size: 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.swatches button.sel, .palette button.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
#board li .sw { image-rendering: pixelated; }
.rules { margin: 18px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.rules b { color: var(--text); font-weight: 600; }
.conn { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 0; }

@media (max-width: 600px) {
  #board { width: 140px; font-size: 12px; padding: 8px 10px; }
  #board li:nth-child(n + 6) { display: none; }
  #hud { max-width: calc(100% - 170px); }
  .stat { min-width: 0; padding: 4px 8px; }
  .stat span:last-child { font-size: 14px; }
  #minimap { width: 100px; height: 100px; }
  #feed { top: auto; bottom: 130px; }
  .rules { font-size: 12px; }
  .palette button { width: 20px; height: 20px; }
}
