:root {
  --btn: max(64px, 13vmin);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: none;
  touch-action: none;
}

.ui {
  position: fixed;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #fcfcfc;
  background: rgba(0, 0, 0, 0.55);
  border: 3px solid #fcfcfc;
  cursor: pointer;
  touch-action: none;
}
.ui svg { width: 55%; height: 55%; }

#btnGrenade {
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  border-color: #f83800;
  color: #f83800;
}
#btnGrenade.armed {
  background: #f83800;
  color: #fcfcfc;
  animation: pulse 0.4s infinite alternate;
}
@keyframes pulse { to { transform: scale(1.12); } }

#btnPause {
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  width: 48px;
  height: 48px;
}
#btnFull {
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  width: 48px;
  height: 48px;
}

body.touch[data-scene="battle"] #btnGrenade { display: flex; }
body[data-scene="battle"] #btnPause { display: flex; }
body.can-fs #btnFull { display: flex; }

#rotate {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 0 16px;
  text-align: center;
  font: 12px/1.8 "Press Start 2P", monospace;
  color: #f8b800;
}
@media (orientation: portrait) {
  body.touch #rotate { display: block; }
}

/* ---- Sharp crosshair cursor for mouse players (drawn by the OS, no lag) ---- */
#screen {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' shape-rendering='crispEdges'%3E%3Cg fill='%23000'%3E%3Crect x='1' y='14' width='11' height='4'/%3E%3Crect x='20' y='14' width='11' height='4'/%3E%3Crect x='14' y='1' width='4' height='11'/%3E%3Crect x='14' y='20' width='4' height='11'/%3E%3Crect x='14' y='14' width='4' height='4'/%3E%3C/g%3E%3Cg fill='%23FCFCFC'%3E%3Crect x='2' y='15' width='9' height='2'/%3E%3Crect x='21' y='15' width='9' height='2'/%3E%3Crect x='15' y='2' width='2' height='9'/%3E%3Crect x='15' y='21' width='2' height='9'/%3E%3C/g%3E%3Crect x='15' y='15' width='2' height='2' fill='%23F83800'/%3E%3C/svg%3E") 16 16, crosshair;
}
body.mg #screen {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' shape-rendering='crispEdges'%3E%3Cg fill='%23000'%3E%3Crect x='1' y='14' width='11' height='4'/%3E%3Crect x='20' y='14' width='11' height='4'/%3E%3Crect x='14' y='1' width='4' height='11'/%3E%3Crect x='14' y='20' width='4' height='11'/%3E%3Crect x='14' y='14' width='4' height='4'/%3E%3C/g%3E%3Cg fill='%23F8B800'%3E%3Crect x='2' y='15' width='9' height='2'/%3E%3Crect x='21' y='15' width='9' height='2'/%3E%3Crect x='15' y='2' width='2' height='9'/%3E%3Crect x='15' y='21' width='2' height='9'/%3E%3C/g%3E%3Crect x='15' y='15' width='2' height='2' fill='%23F83800'/%3E%3C/svg%3E") 16 16, crosshair;
}
body.touch #screen { cursor: default; }

/* ---- Rules button and side panel ---- */
#btnRules {
  display: flex;
  gap: 8px;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  height: 48px;
  padding: 0 12px;
  font: 12px "Press Start 2P", monospace;
  border-color: #f8b800;
  color: #f8b800;
}
#btnRules span:first-child { font-size: 18px; }
#btnPause { top: calc(68px + env(safe-area-inset-top)); }
body.rules-open #btnRules { display: none; }

#rules {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  display: flex;
  flex-direction: column;
  background: #0c0c0c;
  border-left: 3px solid #f8b800;
  color: #e8e8e8;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: text;
  user-select: text;
  touch-action: pan-y;
  z-index: 10;
}
#rules[hidden] { display: none; }
#rules header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 2px solid #3c3c3c;
}
#rules h1 {
  margin: 0;
  font: 14px "Press Start 2P", monospace;
  color: #f8b800;
}
#rulesClose {
  width: 44px;
  height: 44px;
  font-size: 20px;
  color: #fcfcfc;
  background: none;
  border: 2px solid #fcfcfc;
  cursor: pointer;
}
#rulesBody {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 4px 16px 24px;
}
#rules h2 {
  margin: 20px 0 8px;
  font: 11px/1.6 "Press Start 2P", monospace;
  color: #f8b800;
}
#rules p { margin: 0 0 8px; }
#rules ul, #rules ol { margin: 0 0 8px; padding-left: 20px; }
#rules li { margin-bottom: 4px; }
#rules b { color: #fcfcfc; }
#rules kbd {
  padding: 0 4px;
  border: 1px solid #7c7c7c;
  font: 12px monospace;
  color: #fcfcfc;
}
#rules .ico {
  height: 20px;
  vertical-align: middle;
  image-rendering: pixelated;
}
#rules table.btns { border-collapse: collapse; margin-bottom: 8px; }
#rules table.btns td { padding: 6px 8px 6px 0; vertical-align: top; }
#rules table.btns td:first-child { width: 52px; text-align: center; font-size: 24px; }
#rules .btn-demo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 3px solid #fcfcfc;
  color: #fcfcfc;
  font: 16px "Press Start 2P", monospace;
}
#rules .btn-demo svg { width: 55%; height: 55%; }
#rules .btn-demo.round { border-radius: 50%; }
#rules .btn-demo.red { border-color: #f83800; color: #f83800; }
#rules .btn-demo.yellow { border-color: #f8b800; color: #f8b800; }
#rules .god {
  margin: 12px 0 4px;
  padding: 10px 12px;
  border: 2px dashed #3c3c3c;
}
#rules .god p { margin: 8px 0 0; font-size: 13px; color: #bcbcbc; }
#rules .god-btn {
  width: 100%;
  min-height: 48px;
  font: 12px/1.4 "Press Start 2P", monospace;
  color: #fcfcfc;
  background: #3c3c3c;
  border: 3px solid #7c7c7c;
  cursor: pointer;
  touch-action: manipulation;
}
#rules .god-btn.on {
  color: #000;
  background: #f8b800;
  border-color: #fcfcfc;
}
