@font-face {
  font-family: "DotGothic16";
  src: url("../assets/fonts/DotGothic16-subset.woff2") format("woff2");
  font-display: block;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: "DotGothic16", "MS Gothic", monospace;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#screen {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  image-rendering: crisp-edges;   /* Firefox */
  image-rendering: pixelated;     /* Chrome / Safari / Edge */
  background: #000;
}

/* ------------------------------------------------------------------ touch controls */
#touch { display: none; }
body.touch #touch { display: block; }

#touch button, #dpad { touch-action: none; }

.btn {
  position: absolute;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(40, 40, 70, 0.55);
  color: #fff;
  font: bold 28px/1 "DotGothic16", monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  pointer-events: auto;
}
.btn small { font-size: 10px; font-weight: normal; opacity: 0.85; margin-top: 2px; }
.btn.on { background: rgba(248, 184, 0, 0.7); border-color: #fff; transform: scale(0.94); }
.btn.a { right: 14px; bottom: 34px; }
.btn.b { right: 112px; bottom: 12px; }

#dpad {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(40, 40, 70, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.45);
  pointer-events: auto;
}
#dpad .arr {
  position: absolute;
  width: 0; height: 0;
  border: 14px solid transparent;
  opacity: 0.8;
}
#dpad .u { left: 50%; top: 8px; margin-left: -14px; border-bottom: 22px solid #fff; border-top: 0; }
#dpad .d { left: 50%; bottom: 8px; margin-left: -14px; border-top: 22px solid #fff; border-bottom: 0; }
#dpad .l { top: 50%; left: 8px; margin-top: -14px; border-right: 22px solid #fff; border-left: 0; }
#dpad .r { top: 50%; right: 8px; margin-top: -14px; border-left: 22px solid #fff; border-right: 0; }
#dpad[data-dir*="u"] .u, #dpad[data-dir*="d"] .d,
#dpad[data-dir*="l"] .l, #dpad[data-dir*="r"] .r { filter: drop-shadow(0 0 4px #f8b800) brightness(0.6) sepia(1) saturate(6) hue-rotate(5deg); opacity: 1; }

.pause {
  position: absolute;
  top: 8px;
  right: max(8px, env(safe-area-inset-right));
  width: 44px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(40, 40, 70, 0.5);
  color: #fff;
  font: bold 14px/1 monospace;
  pointer-events: auto;
}

/* Portrait phones: game on top, controls in a pad below. */
@media (orientation: portrait) {
  body.touch #touch {
    position: relative;
    flex: none;
    height: min(42vh, 260px);
  }
  body.touch .pause { top: -40px; }
  body.touch .btn.a { right: 14px; bottom: 60px; }
  body.touch .btn.b { right: 106px; bottom: 28px; }
  body.touch #dpad { left: 16px; bottom: 24px; }
}

/* Landscape phones: controls float over the black side bars. */
@media (orientation: landscape) {
  body.touch #touch {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }
  body.touch #dpad { left: max(14px, env(safe-area-inset-left)); bottom: 14px; width: 132px; height: 132px; }
  body.touch .btn { width: 72px; height: 72px; font-size: 24px; }
  body.touch .btn.a { right: max(14px, env(safe-area-inset-right)); bottom: 40px; }
  body.touch .btn.b { right: calc(max(14px, env(safe-area-inset-right)) + 82px); bottom: 14px; }
}

@media (max-height: 380px) and (orientation: landscape) {
  body.touch #dpad { width: 112px; height: 112px; }
  body.touch .btn { width: 62px; height: 62px; font-size: 20px; }
  body.touch .btn small { display: none; }
  body.touch .btn.b { right: calc(max(14px, env(safe-area-inset-right)) + 72px); }
}
