:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1f2630;
  --line: #2f3945;
  --text: #e6edf3;
  --muted: #9aa6b2;
  --accent: #5eead4;
  --danger: #fb7185;
  --warning: #facc15;
  --ok: #4ade80;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top, #111827, var(--bg));
  color: var(--text);
}

.app {
  min-height: 100vh;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel {
  width: min(1180px, 100%);
  background: rgba(22, 27, 34, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.login-panel {
  max-width: 740px;
  padding: 26px;
}

h1 { margin: 0 0 8px; }
.subtitle { color: var(--muted); margin: 0 0 18px; }
.hint { color: var(--muted); margin-top: 18px; line-height: 1.5; }
.error { color: var(--danger); min-height: 22px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

input, select, button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
}

button {
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px) scale(0.99); }

.actions { margin-top: 16px; }
#joinBtn, .fire-btn { background: linear-gradient(180deg, #14b8a6, #0f766e); border: none; }
.secondary-btn { background: #263140; }
.small-btn { padding: 10px 12px; font-size: 14px; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toggle-label {
  justify-content: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.02);
}

.toggle-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  padding: 0;
  accent-color: #22d3ee;
}

.toggle-label span {
  color: var(--text);
  font-weight: bold;
}

.toggle-label small {
  color: var(--muted);
  line-height: 1.35;
}

.hidden { display: none !important; }

.game-panel { padding: 14px; }
.topbar, .bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px;
  flex-wrap: wrap;
}

.center-status-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.center-status {
  font-weight: bold;
  color: var(--warning);
}

.room-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(94, 234, 212, 0.3);
  background: rgba(94, 234, 212, 0.12);
  color: var(--accent);
  font-size: 13px;
}

.right-info { text-align: right; }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(74, 222, 128, 0.15);
  color: var(--ok);
  border: 1px solid rgba(74, 222, 128, 0.3);
}
.badge.secondary {
  color: var(--accent);
  background: rgba(94, 234, 212, 0.14);
  border-color: rgba(94, 234, 212, 0.3);
}
.badge.danger {
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.3);
}

.game-wrap {
  width: 100%;
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #05070b;
}

canvas {
  display: block;
  width: min(100%, 972px);
  height: auto;
  margin: 0 auto;
  touch-action: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 4px 6px;
  color: var(--muted);
  font-size: 14px;
}
.box {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: -2px;
}
.box.floor { background: #334155; }
.box.wall { background: #a16207; }
.box.bomb { background: #e11d48; }
.box.enemy { background: #60a5fa; }
.box.clock { background: #22d3ee; border: 1px solid #cffafe; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 0 8px;
}
.dpad {
  display: grid;
  gap: 8px;
}
.middle-row {
  display: flex;
  gap: 8px;
}
.controls button {
  min-width: 72px;
  min-height: 58px;
  font-size: 22px;
}
.fire-wrap { display: flex; justify-content: flex-end; flex: 1; }
.fire-btn { min-width: 130px; min-height: 86px; font-size: 24px; }

.bottom-actions {
  display: flex;
  gap: 10px;
}

@media (max-width: 900px) {
  .right-info { text-align: left; }
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .fire-wrap { justify-content: center; }
}

@media (max-width: 640px) {
  .app { padding: 8px; }
  .login-panel, .game-panel { padding: 12px; }
  .controls button { min-width: 64px; min-height: 54px; }
  .fire-btn { min-width: 100%; }
}


#controlsHint {
  line-height: 1.4;
  color: var(--muted);
}

@media (pointer: coarse) {
  body {
    overscroll-behavior: none;
  }

  .controls {
    position: sticky;
    bottom: 0;
    padding: 14px 6px max(10px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(13,17,23,0), rgba(13,17,23,0.88) 18%, rgba(13,17,23,0.98));
    backdrop-filter: blur(8px);
  }

  .controls button {
    min-width: 82px;
    min-height: 68px;
    font-size: 28px;
  }

  .fire-btn {
    min-height: 96px;
    font-size: 28px;
  }
}

@media (max-width: 640px) {
  .topbar {
    font-size: 14px;
  }

  .badge {
    margin-left: 4px;
    padding: 5px 8px;
  }

  .legend {
    gap: 10px;
    font-size: 13px;
  }

  .bottombar {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .middle-row {
    justify-content: center;
  }

  .controls button {
    min-width: 74px;
    min-height: 62px;
    font-size: 24px;
  }
}

.box.crate { background: #b45309; }
.box.pickup { background: #111111; border: 1px solid #cbd5e1; }
.badge.warn {
  color: #fde68a;
  background: rgba(250, 204, 21, 0.14);
  border-color: rgba(250, 204, 21, 0.3);
}
.action-stack {
  display: flex;
  gap: 10px;
  align-items: stretch;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.bomb-btn {
  min-width: 110px;
  min-height: 86px;
  font-size: 24px;
  background: linear-gradient(180deg, #f59e0b, #b45309);
  border: none;
}
@media (pointer: coarse) {
  .bomb-btn {
    min-height: 96px;
    font-size: 28px;
  }
}
@media (max-width: 640px) {
  .action-stack {
    width: 100%;
  }
  .bomb-btn {
    min-width: calc(50% - 5px);
  }
  .fire-btn {
    min-width: calc(50% - 5px);
  }
}


.range-label input[type="range"] {
  padding: 0;
}

.range-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.range-meta span {
  color: var(--text);
  font-weight: bold;
}

.range-meta small {
  color: var(--muted);
  font-size: 12px;
}

.badge.ammo {
  color: #fef08a;
  background: rgba(250, 204, 21, 0.14);
  border-color: rgba(250, 204, 21, 0.3);
}

.badge.warn {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.3);
}


.range-meta { display:flex; flex-direction:column; gap:4px; }
.range-meta small { color: var(--muted); }
.player-list { display:flex; flex-wrap:wrap; gap:8px; justify-content:flex-end; margin-top:8px; }
.player-pill {
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(255,255,255,0.05);
  font-size:13px;
}
.player-pill.me { box-shadow: 0 0 0 1px rgba(74,222,128,0.25) inset; }
.player-dot { width:10px; height:10px; border-radius:50%; display:inline-block; }
.box.pickup { background: #111111; border:1px solid #cbd5e1; }
.box.crate { background: #b45309; }
.badge.warn {
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.3);
}
.action-stack { display:flex; flex-direction:column; gap:10px; }
.bomb-btn { background: linear-gradient(180deg, #ef4444, #991b1b); border:none; min-width:130px; min-height:62px; font-size:22px; }
@media (max-width: 900px) {
  .player-list { justify-content:flex-start; }
}
@media (pointer: coarse) {
  .bomb-btn { min-height: 82px; font-size: 24px; }
}
