* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: "Press Start 2P", "Courier New", monospace;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, #0a0a18 0%, #000 70%);
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  max-width: 100vw;
  max-height: 100vh;
}

@media (max-width: 1099px) {
  #app {
    justify-content: flex-start;
    padding-top: 8px;
    padding-bottom: 188px;
  }
  #game {
    max-height: calc(100vh - 196px);
  }
}

#pad {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 18px calc(16px + env(safe-area-inset-bottom));
}

.dpad {
  position: relative;
  width: 168px;
  height: 168px;
  pointer-events: auto;
  touch-action: none;
}

.dpad .dir {
  position: absolute;
  width: 56px;
  height: 56px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(18, 18, 28, 0.72);
  color: #ffe566;
  font-size: 18px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.dpad .up { top: 0; left: 56px; }
.dpad .down { bottom: 0; left: 56px; }
.dpad .left { left: 0; top: 56px; }
.dpad .right { right: 0; top: 56px; }

.dpad-core {
  position: absolute;
  left: 62px;
  top: 62px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(255, 229, 102, 0.12);
  border: 2px solid rgba(255, 229, 102, 0.28);
  pointer-events: none;
}

.dpad .dir.active {
  background: rgba(255, 229, 102, 0.28);
  border-color: #ffe566;
  color: #fff;
}

.actions {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  pointer-events: auto;
  padding-bottom: 8px;
}

.actions button {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 3px solid rgba(255, 165, 74, 0.85);
  background: rgba(18, 18, 28, 0.78);
  color: #ffa54a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: auto;
  touch-action: none;
}

.actions button span {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 16px;
  line-height: 1;
}

.actions button small {
  font-family: "Press Start 2P", "Noto Sans SC", sans-serif;
  font-size: 8px;
  color: #ddd;
}

#btn-z {
  width: 92px;
  height: 92px;
  border-color: #ffe566;
  color: #ffe566;
}

.actions button.active {
  background: rgba(255, 229, 102, 0.32);
  color: #fff;
  transform: scale(0.96);
}

body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015) 0px,
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 5;
}

@media (orientation: landscape) and (max-height: 520px) {
  .dpad {
    width: 140px;
    height: 140px;
  }
  .dpad .dir {
    width: 46px;
    height: 46px;
    font-size: 15px;
  }
  .dpad .up { left: 47px; }
  .dpad .down { left: 47px; }
  .dpad .left { top: 47px; }
  .dpad .right { top: 47px; }
  .dpad-core {
    left: 52px;
    top: 52px;
    width: 36px;
    height: 36px;
  }
  .actions button {
    width: 64px;
    height: 64px;
  }
  #btn-z {
    width: 76px;
    height: 76px;
  }
}

@media (min-width: 1100px) and (pointer: fine) {
  #pad {
    opacity: 0.55;
  }
}
