:root {
  --bg: #0d1117;
  --panel: rgba(18, 24, 32, 0.92);
  --line: #2a3542;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4fc3f7;
  --accent-ink: #062330;
  --danger: #ff6b6b;
  --hp: #6fdc8c;
  --reload: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

#view { position: fixed; inset: 0; cursor: crosshair; }
#view canvas { display: block; }

button, input { font: inherit; }

.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

h1 { margin: 0; font-size: 28px; letter-spacing: 2px; }
.sub { margin: 4px 0 20px; color: var(--muted); font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }

input {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: #0b0f14;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
input:focus { border-color: var(--accent); }

button {
  padding: 10px 16px;
  color: var(--text);
  background: #1c2733;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { width: 100%; color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }
button:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 8px; margin-top: 8px; }
.row.join input { flex: 1; text-transform: uppercase; letter-spacing: 4px; }

.gun-list { display: grid; gap: 8px; }
.gun-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 10px 12px;
  text-align: left;
  background: #0b0f14;
}
.gun-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.gun-card b { font-size: 15px; }
.gun-card small { color: var(--muted); }
.gun-card .tier { grid-row: span 2; align-self: center; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: #23402b; color: #8be0a0; }

.code-label { margin: 0; color: var(--muted); font-size: 13px; }
.code { margin: 0 0 16px; font-size: 44px; font-weight: 800; letter-spacing: 10px; color: var(--accent); }

.players { list-style: none; margin: 0 0 16px; padding: 0; }
.players li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.players li small { color: var(--muted); }

.error { min-height: 1.2em; margin: 12px 0 0; color: var(--danger); font-size: 14px; }

#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top-left { position: absolute; top: 12px; left: 12px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-width: 180px; }
.hud-code { font-size: 13px; color: var(--muted); }
.hud-code b { color: var(--accent); letter-spacing: 3px; }
.hud-players { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
.hud-players li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.hud-players .dot { width: 8px; height: 8px; border-radius: 50%; }
.hud-players .mini { flex: 1; height: 4px; background: #222b35; border-radius: 2px; overflow: hidden; }
.hud-players .mini i { display: block; height: 100%; background: var(--hp); }

.hud-bottom {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.hud-gun { font-size: 13px; color: var(--muted); }
.hud-ammo b { font-size: 26px; }
.hud-ammo span { margin-left: 4px; color: var(--muted); }
.bar { height: 6px; margin-top: 6px; background: #222b35; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; }
.bar.reload i { background: var(--reload); }
.bar.hp i { background: var(--hp); }

.hud-wave {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, calc(100vw - 32px));
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.wave-line { display: flex; justify-content: space-between; align-items: baseline; }
.wave-line b { font-size: 18px; }
.wave-line span { color: var(--muted); font-size: 13px; }
.wave-sub { display: flex; justify-content: space-between; margin-top: 4px; font-size: 12px; color: var(--muted); }
.wave-sub b { color: var(--text); }
.bar.core i { background: var(--accent); }
.wave-ready { margin-top: 6px; font-size: 13px; color: var(--reload); }

.hud-money {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
}
.hud-money b { color: var(--reload); font-size: 20px; margin-left: 4px; }

.build {
  position: absolute;
  right: 12px;
  top: 70px;
  width: 240px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  pointer-events: auto;
}
.build h3 { margin: 0 0 4px; font-size: 15px; }
.build p { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.build button { display: flex; justify-content: space-between; width: 100%; margin-top: 6px; padding: 8px 10px; font-size: 13px; text-align: left; }
.build button kbd { margin-right: 8px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font-size: 11px; color: var(--muted); }
.build button .cost { color: var(--reload); }
.build button small { display: block; color: var(--muted); font-size: 11px; }

.hud-gun-row { display: flex; justify-content: space-between; }
.hud-gunup { font-size: 12px; color: var(--reload); }
.hud-swap { font-size: 12px; color: var(--muted); }
.hud-supply { margin-top: 8px; font-size: 12px; color: var(--accent); }
.hud-supply.urgent { color: var(--danger); font-weight: 700; }
.bar.supply i { background: var(--accent); }

.toast { position: absolute; bottom: 200px; left: 50%; transform: translateX(-50%); padding: 8px 14px; background: rgba(120, 30, 30, 0.9); border-radius: 8px; font-size: 14px; }

.hud-help { position: absolute; right: 12px; bottom: 12px; font-size: 12px; color: var(--muted); }
.hud-dead { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); padding: 10px 18px; background: rgba(120, 20, 20, 0.8); border-radius: 8px; }

#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.floater { position: absolute; font-weight: 800; font-size: 14px; color: #fff; text-shadow: 0 1px 3px #000; transform: translate(-50%, -50%); white-space: nowrap; }
.floater.crit { color: #ffd166; font-size: 17px; }
.floater.precise { color: #ff9f6b; }

@media (max-width: 960px) {
  .build { top: auto; bottom: 220px; }
}

@media (max-width: 600px) {
  .hud-help { display: none; }
}
