html, body { margin: 0; height: 100%; background: #0b0b0b; }
body {
  font-family: "Courier New", monospace; color: #ddd;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#game {
  height: 100vh; height: 100dvh; display: grid;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "wrap";
}
#wrap { grid-area: wrap; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
canvas {
  display: block; image-rendering: pixelated;
  border: 4px solid #3a3a3a; box-shadow: 0 0 0 2px #111, 0 0 40px #000; background: #1a1a1a;
}
.side { display: none; }

/* ---- Kosketusohjaimet ---- */
body.touch { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
body.touch #game {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--side);
  grid-template-areas: "left wrap right";
  --side: clamp(120px, 19vw, 230px);
}
body.touch canvas { border-width: 2px; box-shadow: none; }
body.touch .side {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; min-width: 0; min-height: 0; touch-action: none;
}
#left { grid-area: left; }
#right { grid-area: right; }
@media (orientation: portrait) {
  body.touch #game {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "wrap wrap" "left right";
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  body.touch .side { padding: 10px 0; }
}

#pad {
  --s: min(40vmin, 190px);
  width: var(--s); height: var(--s); position: relative; border-radius: 50%;
  background: radial-gradient(circle, #2b2b2b 0 30%, #1c1c1c 31% 100%);
  border: 3px solid #3c3c3c; box-shadow: inset 0 0 18px #000, 0 0 0 2px #111;
  touch-action: none;
}
#pad .arr {
  position: absolute; width: 34%; height: 34%; display: flex; align-items: center; justify-content: center;
  color: #777; font-size: calc(var(--s) * 0.16); border-radius: 8px; pointer-events: none;
}
#pad .arr.on { color: #fff; background: rgba(45, 99, 200, 0.55); }
#pad .up    { left: 33%; top: 2%; }
#pad .down  { left: 33%; bottom: 2%; }
#pad .left  { top: 33%; left: 2%; }
#pad .right { top: 33%; right: 2%; }

.btn {
  font: bold 13px "Courier New", monospace; color: #ddd; letter-spacing: 1px;
  background: linear-gradient(#3b3b3b, #222); border: 2px solid #4a4a4a; border-radius: 6px;
  padding: 8px 10px; touch-action: manipulation; min-height: 38px;
}
.btn:active { background: #555; }
.btn.dim, #bMolotov.dim { opacity: 0.35; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#bFire {
  --f: min(30vmin, 140px);
  width: var(--f); height: var(--f); border-radius: 50%;
  font: bold 20px "Courier New", monospace; color: #fff; letter-spacing: 2px;
  background: radial-gradient(circle at 40% 35%, #e0564a, #b3261e 55%, #6e1510);
  border: 3px solid #3c3c3c; box-shadow: 0 0 0 2px #111, 0 5px 0 #400; touch-action: none;
}
#bFire.on { transform: translateY(3px); box-shadow: 0 0 0 2px #111, 0 2px 0 #400; filter: brightness(1.25); }
#bMolotov {
  padding: 2px 6px; border-radius: 10px; touch-action: none; line-height: 0;
  background: linear-gradient(#2e2e2e, #1b1b1b); border: 2px solid #4a4a4a;
}
#bMolotov:active { background: #444; }
#bMolotov canvas { display: block; border: 0; box-shadow: none; background: none; image-rendering: auto; width: 110px; height: 50px; }
