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

#wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body.touch.portrait #wrap {
  align-items: flex-start;
  padding-top: env(safe-area-inset-top);
}

/* ===== Сенсорное управление ===== */
#touch { display: none; }
body.touch #touch { display: block; }

#dpad {
  position: fixed;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.2);
  touch-action: none;
}

#dpad .a {
  position: absolute;
  width: 0;
  height: 0;
  border: 14px solid transparent;
  opacity: 0.45;
}
#dpad .a.on { opacity: 1; }
#dpad .up    { left: 61px; top: 6px;     border-bottom-color: #fff; border-top-width: 0; }
#dpad .down  { left: 61px; bottom: 6px;  border-top-color: #fff; border-bottom-width: 0; }
#dpad .left  { top: 61px;  left: 6px;    border-right-color: #fff; border-left-width: 0; }
#dpad .right { top: 61px;  right: 6px;   border-left-color: #fff; border-right-width: 0; }

#dpad .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

#btns button {
  position: fixed;
  border: none;
  color: #fff;
  font: bold 14px/1 monospace;
  touch-action: none;
}

#btn-fire {
  right: max(24px, env(safe-area-inset-right));
  bottom: max(40px, env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #b82000;
  box-shadow: 0 4px 0 #600;
}

#btn-start {
  right: max(130px, calc(env(safe-area-inset-right) + 106px));
  bottom: max(36px, env(safe-area-inset-bottom));
  width: 64px;
  height: 28px;
  border-radius: 14px;
  background: #555;
}

#btns button.on { filter: brightness(1.4); transform: translateY(2px); }
