html {
  display: flex;
  height: 100%;
  background: #000;
}

body {
  background: #000;
  display: flex;
  flex: 1;
  justify-content: center;
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-shell {
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  justify-content: center;
  width: 100%;
}

.game-stage {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 0;
}

.game-stage canvas {
  display: block;
  height: auto;
  image-rendering: pixelated;
  max-height: 100vh;
  max-height: 100dvh;
  max-width: 100vw;
  width: auto;
}

.loading {
  align-items: center;
  display: flex;
  color: #fff;
  font-family: Lucida Console, Courier, monospace;
  font-size: 32px;
}

.touch-controls {
  display: none;
}

@media (hover: none), (pointer: coarse), (max-width: 700px) {
  .game-shell {
    justify-content: flex-start;
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
  }

  .game-stage {
    flex: 1 1 auto;
    width: 100%;
  }

  .game-stage canvas {
    max-height: calc(100dvh - 176px - env(safe-area-inset-bottom));
  }

  .touch-controls {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    flex: 0 0 176px;
    justify-content: space-between;
    padding: 8px max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
    width: 100%;
  }

  .touch-button {
    align-items: center;
    background: rgba(48, 48, 48, 0.94);
    border: 2px solid #a5a5a5;
    border-radius: 14px;
    color: #fff;
    display: flex;
    font-family: Lucida Console, Courier, monospace;
    font-size: 22px;
    font-weight: bold;
    justify-content: center;
    padding: 0;
    touch-action: none;
  }

  .touch-button.is-pressed {
    background: #d74000;
    border-color: #fff;
    transform: scale(0.94);
  }

  .d-pad {
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
  }

  .d-pad .touch-button {
    height: 50px;
    width: 50px;
  }

  .d-pad__up { grid-column: 2; grid-row: 1; }
  .d-pad__left { grid-column: 1; grid-row: 2; }
  .d-pad__right { grid-column: 3; grid-row: 2; }
  .d-pad__down { grid-column: 2; grid-row: 3; }

  .action-pad {
    align-items: center;
    display: flex;
    gap: 16px;
  }

  .fire-button {
    border-radius: 50%;
    height: 88px;
    width: 88px;
  }

  .pause-button {
    height: 48px;
    width: 48px;
  }
}

@media (hover: none) and (orientation: landscape),
  (pointer: coarse) and (orientation: landscape),
  (max-width: 700px) and (orientation: landscape) {
  .game-shell {
    justify-content: center;
  }

  .game-stage canvas {
    max-height: 100dvh;
  }

  .touch-controls {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 0;
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
    pointer-events: none;
    position: fixed;
  }

  .touch-controls > * {
    pointer-events: auto;
  }
}
