:root {
  --ink: #0a0612;
  --ink-2: #140d22;
  --panel: rgba(18, 11, 32, 0.82);
  --line: #3a2a5c;
  --text: #efe6ff;
  --muted: #9a8bb8;
  --hot: #ff2e88;
  --cyan: #28f0ff;
  --gold: #ffcc33;
  --danger: #ff3b3b;
  --ok: #4dff9a;
  --display: "Bungee", "Impact", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
}

#arena {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
  z-index: 50;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ---------- windows (retro OS chrome) ---------- */

.window {
  background: var(--ink-2);
  border: 2px solid var(--line);
  box-shadow: 8px 8px 0 rgba(255, 46, 136, 0.35), 0 0 60px rgba(40, 240, 255, 0.08);
  max-width: calc(100vw - 32px);
}

.window-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: linear-gradient(90deg, #2b1a4f, #4a1640);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #e6d9ff;
}
.window-bar.danger { background: linear-gradient(90deg, #6b0d1d, #a3163a); }

.bar-buttons { display: flex; gap: 4px; }
.bar-buttons i {
  width: 12px; height: 12px;
  border: 1px solid #c9b8f0;
  display: inline-block;
}

.window-body { padding: 24px 28px 22px; }
.center { text-align: center; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
  background: radial-gradient(ellipse at center, rgba(10, 6, 18, 0.55), rgba(10, 6, 18, 0.92));
  padding: 16px;
  overflow-y: auto;
}
#menu {
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 46, 136, 0.18), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(40, 240, 255, 0.14), transparent 45%),
    linear-gradient(rgba(10, 6, 18, 0.7), rgba(10, 6, 18, 0.9));
}
.death { background: radial-gradient(ellipse at center, rgba(80, 0, 20, 0.35), rgba(10, 6, 18, 0.7)); pointer-events: none; }

/* ---------- menu ---------- */

.menu-window { width: 520px; animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1) both; }

.title {
  position: relative;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(42px, 9vw, 68px);
  line-height: 1;
  margin: 4px 0 6px;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--hot), -2px -2px 0 rgba(40, 240, 255, 0.7);
  animation: jitter 3.2s infinite steps(1);
}
.title::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  color: var(--cyan);
  clip-path: inset(0 0 100% 0);
  animation: slice 3.2s infinite steps(1);
}

.tagline { margin: 0 0 20px; color: var(--muted); }

.join-form { display: flex; gap: 10px; }
.join-form input {
  flex: 1;
  min-width: 0;
  background: #07040d;
  border: 2px solid var(--line);
  color: var(--text);
  font: 600 18px var(--mono);
  padding: 12px 14px;
  outline: none;
}
.join-form input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(40, 240, 255, 0.2); }

.play-btn {
  font-family: var(--display);
  font-size: 20px;
  padding: 12px 26px;
  border: 0;
  color: var(--ink);
  background: var(--gold);
  box-shadow: 4px 4px 0 var(--hot);
  transition: transform 0.08s, box-shadow 0.08s;
}
.play-btn:hover { transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--hot); }
.play-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--hot); }
.play-btn:disabled { filter: grayscale(1) brightness(0.6); cursor: wait; }

.ghost-btn {
  font: 600 14px var(--mono);
  padding: 12px 18px;
  color: var(--text);
  background: transparent;
  border: 2px solid var(--line);
}
.ghost-btn:hover { border-color: var(--muted); }

.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

.status-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; color: var(--muted); font-size: 12px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.dot.bad { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.howto { margin: 18px 0 12px; padding-left: 20px; line-height: 1.55; color: #cfc2ea; }
.howto li { margin-bottom: 4px; }
.howto b { color: var(--cyan); }
.howto b.gold { color: var(--gold); }

.keys { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  margin: 0 1px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  background: #07040d;
  color: var(--text);
  font: 600 11px var(--mono);
  text-align: center;
}

.menu-stack {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.fame-window { width: 340px; animation: pop 0.35s 0.12s cubic-bezier(.2, 1.4, .4, 1) both; }
.fame-window .window-body { padding: 18px 18px 16px; }
.fame-title { font-size: 22px; color: var(--cyan); text-shadow: 2px 2px 0 var(--hot); margin-bottom: 10px; }
.fame-me {
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px dashed var(--gold);
  color: #ffe9a8;
  font-size: 12px;
  line-height: 1.5;
}
.fame-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fame-table th { color: var(--muted); font-weight: 600; text-align: right; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.fame-table td { padding: 3px 4px; text-align: right; }
.fame-table th:nth-child(2), .fame-table td:nth-child(2) {
  text-align: left;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fame-table td:first-child { color: var(--muted); }
.fame-table tr:first-child td:nth-child(2) { color: var(--gold); font-weight: 700; }
.fame-table tr:first-child td:nth-child(2)::before { content: "\265B  "; }
.fame-empty { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

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

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud button { pointer-events: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(4px);
}

.hud-top {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.timer-panel { padding: 6px 14px; display: flex; align-items: baseline; gap: 10px; }
.label { font-size: 11px; color: var(--muted); letter-spacing: 0.12em; }
.timer { font-family: var(--display); font-size: 26px; }
.timer.urgent { color: var(--danger); animation: blink 0.5s infinite steps(1); }

.event-banner {
  padding: 6px 18px;
  text-align: center;
  border-color: var(--gold);
  box-shadow: 0 0 24px rgba(255, 204, 51, 0.35);
  display: flex; flex-direction: column;
}
.event-title { font-family: var(--display); color: var(--gold); font-size: 18px; }
.event-sub { font-size: 12px; color: #ffe9a8; }
.event-banner.warning { animation: blink 0.6s infinite steps(1); }

.conn-panel { padding: 6px 8px 6px 12px; display: flex; align-items: center; gap: 8px; font-size: 12px; }
.icon-btn {
  font: 700 10px var(--mono);
  color: var(--text);
  background: #07040d;
  border: 1px solid var(--line);
  padding: 4px 6px;
}
.icon-btn.off { color: var(--muted); text-decoration: line-through; }

.me-panel {
  position: absolute;
  left: 12px; bottom: 12px;
  display: flex;
  align-items: stretch;
}
.me-score {
  padding: 8px 16px;
  font-family: var(--display);
  font-size: 30px;
  color: var(--gold);
  display: flex; flex-direction: column; justify-content: center;
  border-right: 1px solid var(--line);
  min-width: 110px;
}
.me-panel small, .death-stats small {
  display: block;
  font: 600 10px var(--mono);
  color: var(--muted);
  letter-spacing: 0.12em;
}
.me-stats { display: grid; grid-template-columns: repeat(4, auto); gap: 0 16px; padding: 10px 16px; align-items: center; }
.me-stats span { font-size: 18px; font-weight: 700; }

.board-panel {
  position: absolute;
  top: 64px; right: 12px;
  width: 240px;
}
.crown-holder { color: var(--gold); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard { list-style: none; margin: 0; padding: 6px 0; }
.leaderboard li {
  display: grid;
  grid-template-columns: 22px 12px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 13px;
  transition: background 0.2s;
}
.leaderboard li.me { background: rgba(40, 240, 255, 0.12); }
.leaderboard li.dead { opacity: 0.45; }
.leaderboard .rank { color: var(--muted); }
.leaderboard .swatch { width: 10px; height: 10px; }
.leaderboard .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .crowned .name { color: var(--gold); }
.leaderboard .crowned .name::before { content: "\265B  "; }
.leaderboard .score { font-weight: 700; }
.board-rule { font-size: 10px; color: var(--muted); padding: 4px 10px 8px; border-top: 1px dashed var(--line); }

.minimap {
  position: absolute;
  right: 12px; bottom: 12px;
  width: 140px; height: 140px;
  image-rendering: pixelated;
}

.toasts {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  width: min(560px, calc(100vw - 32px));
}
.toast {
  background: rgba(10, 6, 18, 0.88);
  border-left: 4px solid var(--cyan);
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  animation: toast-in 0.25s cubic-bezier(.2, 1.4, .4, 1) both;
  max-width: 100%;
}
.toast.kill { border-color: var(--hot); }
.toast.crown, .toast.greed, .toast.greedbonus { border-color: var(--gold); color: #ffe9a8; }
.toast.me { border-color: var(--ok); }
.toast.out { animation: toast-out 0.4s forwards; }

/* ---------- death / results ---------- */

.small-window { width: 420px; }
.results-window { width: 560px; }
h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0 0 8px; }
#death-title { color: var(--danger); text-shadow: 2px 2px 0 rgba(40, 240, 255, 0.5); }
.quip { color: #e8d6ff; margin: 0 0 16px; }
.death-stats { display: flex; justify-content: center; gap: 28px; margin-bottom: 14px; }
.death-stats span { font-size: 24px; font-weight: 700; }
.respawn { margin: 0 0 8px; color: var(--muted); }
.respawn-bar { height: 6px; background: #07040d; border: 1px solid var(--line); }
.respawn-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--hot), var(--gold)); }
.glitch-in { animation: glitch-in 0.4s steps(6) both; }

.winner { color: var(--gold); font-size: 38px; text-shadow: 3px 3px 0 var(--hot); }
.standings { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.standings th { color: var(--muted); font-weight: 600; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.standings td { padding: 4px 6px; text-align: left; }
.standings tr.me td { background: rgba(40, 240, 255, 0.12); }
.standings tr:first-child td { color: var(--gold); font-weight: 700; }
.next { color: var(--muted); }

/* ---------- animation ---------- */

@keyframes pop { from { transform: scale(0.9) rotate(-1deg); opacity: 0; } }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes toast-in { from { transform: translateY(-10px) scale(0.9); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-8px); opacity: 0; } }
@keyframes jitter {
  0%, 100% { transform: none; }
  92% { transform: translate(2px, -1px) skewX(-6deg); }
  94% { transform: translate(-3px, 1px); }
  96% { transform: none; }
}
@keyframes slice {
  0%, 100% { clip-path: inset(0 0 100% 0); }
  92% { clip-path: inset(30% 0 45% 0); transform: translateX(-6px); }
  94% { clip-path: inset(65% 0 10% 0); transform: translateX(5px); }
  96% { clip-path: inset(0 0 100% 0); }
}
@keyframes glitch-in {
  0% { transform: translateX(-20px) skewX(20deg); opacity: 0; filter: hue-rotate(90deg); }
  50% { transform: translateX(12px) skewX(-8deg); opacity: 1; }
  100% { transform: none; filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .board-panel { width: 170px; top: 60px; }
  .leaderboard li:nth-child(n+6):not(.me) { display: none; }
  .minimap { width: 96px; height: 96px; }
  .me-stats { grid-template-columns: repeat(2, auto); padding: 6px 10px; }
  .me-score { font-size: 22px; min-width: 80px; }
  .timer { font-size: 20px; }
  .event-banner { display: none; }
  .window-body { padding: 18px 16px; }
}
