:root {
  --bg0: #62a8ff;
  --bg1: #f7a0d8;
  --panel: rgba(15, 20, 30, 0.82);
  --line: #99d8ff;
  --text: #e8f7ff;
  --accent: #ffe26f;
  --danger: #ff4d6d;
}

* { box-sizing: border-box; }
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
img, canvas {
  -webkit-user-drag: none;
  user-drag: none;
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Courier New", monospace;
  background: linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--text);
  overscroll-behavior: none;
}

body.mobile-client {
  background: #6aa8ff;
}

body {
  touch-action: manipulation;
}

#game-wrap,
#game-wrap * {
  -webkit-touch-callout: none;
}

body.mobile-game-active {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #6aa8ff;
}

#game-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

body.mobile-client #game-wrap {
  width: calc(var(--app-vw, 100vw) * 1px);
  height: calc(var(--app-vh, 100vh) * 1px);
  background: #6aa8ff;
}

body.mobile-game-active #game-wrap {
  width: calc(var(--app-vw, 100vw) * 1px);
  height: calc(var(--app-vh, 100vh) * 1px);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

body.mobile-game-active canvas {
  margin: 0 !important;
}

canvas {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  position: relative;
  z-index: 0;
  touch-action: none;
}

body.mobile-client canvas {
  image-rendering: auto;
}

.menu-lobby-panel {
  margin-top: 380px;
}

#overlay-root {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 14px;
  border-radius: 8px;
  width: min(92vw, 420px);
  margin: 14px auto;
}

.panel h1, .panel h2, .panel h3 { margin-top: 0; color: var(--accent); }
.panel label { display: block; font-size: 13px; margin-top: 8px; }
.panel input, .panel select, .panel button {
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0d1320;
  color: var(--text);
}
.panel .row {
  display: flex;
  gap: 8px;
}
.panel .row > * { flex: 1; }

.btn-danger { border-color: var(--danger) !important; }

.pixel-panel {
  border-radius: 0;
  border: 4px solid #ffffff;
  background: rgba(20, 18, 42, 0.9);
  box-shadow: 0 0 0 4px #1b1635, 8px 8px 0 0 rgba(15, 12, 34, 0.95);
  image-rendering: pixelated;
}

.pixel-panel h2 {
  margin-bottom: 10px;
  font-size: 28px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffe26f;
  text-shadow: 2px 2px 0 #161232;
}

.pixel-panel label,
.pixel-panel p,
.pixel-panel input,
.pixel-panel select,
.pixel-panel button {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.pixel-panel input,
.pixel-panel select,
.pixel-panel button {
  border-radius: 0;
  border: 3px solid #9ad8ff;
  background: #101833;
  color: #f4fbff;
  box-shadow: inset -2px -2px 0 #0a0f20, inset 2px 2px 0 #2a3e71;
}

.pixel-panel button {
  border-color: #ffe26f;
  background: #1c2a55;
  color: #fff4bd;
  box-shadow: inset -2px -2px 0 #111935, inset 2px 2px 0 #3956a0, 3px 3px 0 #0d1328;
  text-transform: uppercase;
}

.pixel-panel button:active {
  transform: translate(1px, 1px);
  box-shadow: inset -2px -2px 0 #111935, inset 2px 2px 0 #3956a0, 2px 2px 0 #0d1328;
}

#mobile-play-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.45);
}
#mobile-play-overlay.hidden { display: none; }
#mobile-play-btn {
  font-size: 18px;
  padding: 14px 18px;
}

.mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.mobile-stick-wrap {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 160px;
  height: 160px;
  pointer-events: none;
}

.mobile-stick {
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: 144px;
  height: 144px;
  border-radius: 999px;
  pointer-events: auto;
  touch-action: none;
  background: rgba(10, 18, 30, 0.12);
}

.mobile-stick-ring {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.38);
  background:
    radial-gradient(circle at 40% 35%, rgba(255,255,255,0.12), rgba(255,255,255,0.03) 45%, rgba(0,0,0,0.12) 100%);
  box-shadow:
    inset 0 0 24px rgba(255,255,255,0.06),
    0 8px 20px rgba(0,0,0,0.18);
}

.mobile-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.5);
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.32), rgba(255,255,255,0.11) 50%, rgba(0,0,0,0.16) 100%);
  box-shadow: 0 6px 14px rgba(0,0,0,0.2);
  transform: translate(-50%, -50%) translate(0px, 0px);
}

.mobile-buttons {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(42vw, 220px);
  pointer-events: none;
}

.mobile-btn {
  pointer-events: auto;
  touch-action: none;
  height: 76px;
  border-radius: 18px;
  border: 2px solid rgba(255,255,255,0.42);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.08)),
    rgba(18, 28, 42, 0.28);
  color: #f7fbff;
  font-family: "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 0.8px;
  font-size: 15px;
  text-transform: uppercase;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.2),
    0 8px 18px rgba(0,0,0,0.18);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.mobile-btn-jump {
  border-radius: 999px;
}

.mobile-btn-item {
  border-radius: 999px;
}

.mobile-btn.is-pressed {
  transform: translateY(1px) scale(0.985);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06)),
    rgba(14, 22, 34, 0.34);
}

@media (pointer: fine) {
  .mobile-controls { display: none; }
}

@media (pointer: coarse) {
  canvas {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }

  body.mobile-game-active canvas {
    margin: 0 !important;
  }

  .menu-lobby-panel {
    margin-top: max(180px, calc(env(safe-area-inset-top) + min(26vh, 240px)));
    max-height: calc((var(--app-vh, 100vh) * 1px) - max(196px, calc(env(safe-area-inset-top) + 22vh)) - max(12px, env(safe-area-inset-bottom)));
    overflow: auto;
    padding: 10px;
  }

  .menu-lobby-panel h2,
  .menu-lobby-panel h3 {
    font-size: 22px;
    margin-bottom: 8px;
  }

  .menu-lobby-panel label,
  .menu-lobby-panel p,
  .menu-lobby-panel li,
  .menu-lobby-panel input,
  .menu-lobby-panel select,
  .menu-lobby-panel button {
    font-size: 12px;
  }

  .menu-lobby-panel input,
  .menu-lobby-panel select,
  .menu-lobby-panel button {
    padding: 7px;
  }
}

@media (pointer: fine) {
  .menu-lobby-panel {
    margin-top: 380px;
    max-height: none;
    overflow: visible;
    padding: 14px;
  }
}

.leaderboard-page {
  touch-action: auto;
}
.lb-container {
  width: min(96vw, 980px);
  margin: 20px auto;
  background: rgba(0,0,0,0.45);
  border: 1px solid var(--line);
  padding: 14px;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  border-bottom: 1px solid rgba(255,255,255,0.2);
  padding: 8px;
  text-align: left;
}
