:root {
  --bg: #000;
  --accent: #ce3029;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---- game screen ---- */
#screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
}

/* ---- utility bar ---- */
#utility {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 10px calc(6px + env(safe-area-inset-top, 0px));
  background: #101018;
  border-top: 1px solid #26262f;
}
.util {
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: .06em;
  color: #e8e8f0;
  background: #23232e;
  border: 1px solid #3a3a48;
  border-radius: 8px;
  padding: 8px 14px;
}
.util:active { background: #333340; }

/* ---- touch controls ---- */
#controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #101018;
  border-top: 1px solid #26262f;
}

#dpad {
  position: relative;
  width: 168px;
  height: 168px;
}
.dbtn, .dcenter {
  position: absolute;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #cfcfda;
  background: #22222d;
  border: 1px solid #3a3a48;
  border-radius: 10px;
}
.dbtn:active { background: #3b3b4c; color: #fff; }
.dbtn.up    { left: 56px; top: 0; }
.dbtn.down  { left: 56px; bottom: 0; }
.dbtn.left  { left: 0; top: 56px; }
.dbtn.right { right: 0; top: 56px; }
.dcenter { left: 56px; top: 56px; background: transparent; border: none; }

#ab {
  display: flex;
  gap: 18px;
  align-items: flex-end;
}
.abtn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  font: 800 26px/1 system-ui, sans-serif;
  color: #fff;
  border: 2px solid rgba(255,255,255,.25);
}
.abtn:active { filter: brightness(1.35); }
.abtn.a { background: #b63629; }
.abtn.b { background: #7f86d8; }

/* ---- fullscreen overlay mode ---- */
#stage.fs {
  background: #000;
}
#stage.fs #screen {
  position: absolute;
  inset: 0;
}
#stage.fs #utility, #stage.fs #controls {
  position: absolute;
  z-index: 5;
  width: auto;
  background: transparent;
  border: none;
  opacity: .28;
  transition: opacity .2s;
}
#stage.fs #utility { top: 0; left: 50%; transform: translateX(-50%); padding-top: 8px; }
#stage.fs #controls {
  bottom: 8px; left: 8px; right: 8px;
}
#stage.fs.touched #utility, #stage.fs.touched #controls { opacity: .85; }

#stage.fs #dpad { transform: scale(.85); }
#stage.fs #ab { transform: scale(.85); }

@media (max-width: 480px) {
  #dpad, #controls { max-height: 170px; }
  .abtn { width: 64px; height: 64px; font-size: 22px; }
}
