:root {
  --bg-deep: #0f1b2d;
  --panel-bg: #182942;
  --panel-border: #3a5c8a;
  --text-main: #f4f7fb;
  --text-muted: #93acc9;
  --gold: #ffcc33;
  --green: #38c958;
  --blue: #3b9eff;
  --red: #ff4d5a;
}
* { box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: radial-gradient(circle at 50% 20%, #19385d 0%, #0b1626 100%);
  color: var(--text-main); font-family: "Kanit", sans-serif; overflow-x: hidden;
}
.screen { display: none; min-height: 100dvh; width: 100%; }
.screen.active { display: flex; flex-direction: column; }
#menuScreen.active { align-items: center; justify-content: center; padding: 16px; }
.pixel-card {
  background: var(--panel-bg); border: 4px solid var(--panel-border);
  box-shadow: 0 8px 0 #09111d, inset 0 0 0 2px #0f1b2d;
  padding: 22px 20px; width: 100%; max-width: 440px;
}
.title-wrap { text-align: center; margin-bottom: 18px; }
.title-badge {
  display: inline-block; font-family: "Press Start 2P", monospace; font-size: 9px;
  background: #ff4d5a; color: #fff; padding: 5px 10px; margin-bottom: 10px;
  box-shadow: 0 3px 0 #9b1d27;
}
.game-title {
  font-family: "Press Start 2P", monospace; font-size: 24px; line-height: 1.35; margin: 0;
  color: var(--gold); text-shadow: 4px 4px 0 #8a4b00, -2px -2px 0 #1b1000;
}
.subtitle { margin: 10px 0 0; font-size: 14px; color: var(--text-muted); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.4px; }
input[type="text"] {
  width: 100%; padding: 10px 12px; background: #0d1829; border: 3px solid #304d75;
  color: #fff; font-family: "Kanit", sans-serif; font-size: 16px; outline: none;
  user-select: text; -webkit-user-select: text;
}
input[type="text"]:focus { border-color: var(--gold); }
.skin-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.skin-btn {
  background: #0d1829; border: 3px solid #304d75; padding: 6px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-muted); font-family: "Kanit", sans-serif; font-size: 10px;
  transition: transform 0.08s;
}
.skin-btn:hover { transform: translateY(-2px); }
.skin-btn.selected { border-color: var(--gold); background: #233c61; color: #fff; box-shadow: 0 0 0 2px rgba(255,204,51,0.3); }
.skin-btn canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.pixel-btn {
  font-family: "Kanit", sans-serif; font-weight: 700; font-size: 14px; padding: 10px 12px;
  border: 3px solid rgba(0,0,0,0.35); color: #fff; cursor: pointer;
  text-shadow: 0 2px 0 rgba(0,0,0,0.4); box-shadow: 0 4px 0 rgba(0,0,0,0.45);
  transition: transform 0.06s;
}
.pixel-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.45); }
.btn-green { background: #2eb84d; }
.btn-gold { background: #e39b14; }
.btn-blue { background: #2a85e6; }
.btn-gray { background: #4a5e78; }
.controls-hint {
  display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-muted);
  text-align: center; border-top: 2px dashed #2b4569; padding-top: 10px;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #101e33; border-bottom: 3px solid #2a466d; gap: 8px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; }
.room-pill {
  font-family: "Press Start 2P", monospace; font-size: 10px;
  background: #1b3152; padding: 6px 8px; border: 2px solid #3a5c8a; color: var(--gold);
}
.phase-pill {
  font-family: "Press Start 2P", monospace; font-size: 10px;
  padding: 6px 10px; background: #233b5e; border: 2px solid #4c74ab; color: #fff;
}
.mini-btn {
  background: #233b5e; border: 2px solid #466999; color: #fff;
  font-family: "Kanit", sans-serif; font-size: 13px; padding: 4px 9px; cursor: pointer;
}
.mini-btn.btn-danger { background: #8a2430; border-color: #c74252; }
.arena-layout {
  flex: 1; display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 12px; max-width: 1120px; width: 100%; margin: 0 auto;
}
.canvas-wrapper {
  position: relative; width: 100%; max-width: 720px; aspect-ratio: 4 / 3;
  background: #143f66; border: 4px solid #3a5c8a;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); overflow: hidden;
}
#gameCanvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.center-banner {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none; text-align: center; padding: 16px;
}
.banner-main {
  font-family: "Press Start 2P", monospace; font-size: clamp(18px, 4vw, 34px); color: var(--gold);
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  animation: popIn 0.25s ease-out;
}
.banner-sub {
  margin-top: 8px; font-size: clamp(13px, 2vw, 17px); color: #fff;
  background: rgba(11,22,38,0.8); padding: 4px 12px; border: 2px solid var(--gold);
}
@keyframes popIn { from { transform: scale(0.65); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.lobby-bar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; background: rgba(12,24,42,0.88);
  border: 3px solid #3a5c8a; padding: 8px; z-index: 5; white-space: nowrap;
}
.sidebar { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
.panel { background: var(--panel-bg); border: 3px solid var(--panel-border); padding: 10px 12px; }
.panel h3 { margin: 0 0 8px; font-size: 13px; color: var(--gold); border-bottom: 2px solid #294369; padding-bottom: 4px; }
.player-list, .hof-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.player-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #102036; padding: 5px 8px; border-left: 3px solid var(--green);
}
.player-row.dead { opacity: 0.5; border-left-color: var(--red); }
.player-row.me { outline: 2px solid var(--gold); }
.player-stats { font-size: 12px; color: var(--gold); }
.legend-item { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.hof-row { display: flex; justify-content: space-between; font-size: 12px; color: #dce7f5; }
.muted { color: var(--text-muted); font-size: 12px; }
.touch-controls {
  display: none; position: fixed; bottom: 14px; left: 0; right: 0; padding: 0 20px;
  justify-content: space-between; align-items: flex-end; pointer-events: none; z-index: 20;
}
.joystick-zone {
  width: 126px; height: 126px; pointer-events: auto; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.joystick-base {
  width: 108px; height: 108px; border-radius: 50%;
  background: rgba(16,32,54,0.65); border: 3px solid rgba(255,255,255,0.35); position: relative;
}
.joystick-knob {
  width: 44px; height: 44px; border-radius: 50%; background: var(--gold);
  border: 3px solid #7d4c00; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
}
.touch-dash-btn {
  pointer-events: auto; touch-action: manipulation; width: 92px; height: 92px; border-radius: 50%;
  background: #ff4d5a; border: 4px solid #fff; box-shadow: 0 6px 0 #8a1620;
  color: #fff; font-family: "Press Start 2P", monospace; font-size: 12px; cursor: pointer;
}
.touch-dash-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a1620; }
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0c1829; color: var(--gold); border: 3px solid var(--gold);
  padding: 8px 16px; font-size: 14px; z-index: 100;
}
@media (max-width: 900px) {
  .arena-layout { flex-direction: column; justify-content: flex-start; padding: 8px; padding-bottom: 155px; }
  .sidebar { width: 100%; max-width: 720px; display: grid; grid-template-columns: 1fr 1fr; }
  #hofPanel { grid-column: 1 / -1; }
  .touch-controls { display: flex; }
  .lobby-bar { flex-wrap: wrap; justify-content: center; width: 92%; }
}
@media (hover: none) and (pointer: coarse) { .touch-controls { display: flex; } }