:root {
  color-scheme: dark;
  --page-bg: #0e0f1a;
  --text: #e8ecf1;
  --muted: #9aa0b4;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(58, 63, 102, 0.24), transparent 45%),
    var(--page-bg);
  color: var(--text);
  font-family: Consolas, Menlo, monospace;
}

.app {
  display: grid;
  place-items: center;
  width: min(100vw, 720px);
  padding: 16px;
  gap: 12px;
}

canvas {
  display: block;
  width: min(612px, calc(100vw - 32px));
  height: auto;
  max-height: calc(100vh - 32px);
  border-radius: 6px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  image-rendering: pixelated;
  outline: none;
}

.touch-controls {
  display: none;
  width: min(612px, calc(100vw - 24px));
  grid-template-columns: 216px 1fr;
  align-items: end;
  gap: 16px;
  touch-action: none;
  user-select: none;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(2, 104px);
  grid-template-rows: repeat(2, 104px);
  justify-content: center;
  justify-items: center;
  align-items: center;
  gap: 8px;
  width: 216px;
  height: 216px;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-self: stretch;
  align-content: start;
  gap: 8px;
}

.touch-rotation {
  grid-column: 1 / 3;
  min-height: 96px;
  font-size: 16px;
}

.touch-button {
  min-width: 0;
  min-height: 44px;
  border: 1px solid #3a3f66;
  border-radius: 6px;
  background: #1a1d33;
  color: #e8ecf1;
  font: 700 13px Consolas, Menlo, monospace;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  touch-action: none;
}

.touch-button:active,
.touch-button.is-active {
  background: #ffd166;
  color: #15172b;
}

.touch-pad .touch-button {
  width: 104px;
  height: 104px;
  font-size: 26px;
}

.touch-left {
  grid-column: 1;
  grid-row: 1;
}

.touch-right {
  grid-column: 2;
  grid-row: 1;
}

.touch-down {
  grid-column: 1 / 3;
  grid-row: 2;
}

@media (hover: none), (max-width: 720px) {
  body {
    align-items: center;
    min-height: 100dvh;
    overflow: auto;
  }

  .app {
    width: 100%;
    padding: 8px;
    min-height: 100dvh;
    align-content: center;
  }

  canvas {
    width: min(100%, 612px);
    max-width: calc(100vw - 16px);
    max-height: none;
  }

  .touch-controls {
    display: grid;
  }
}

@media (max-width: 420px) {
  .touch-controls {
    grid-template-columns: 172px 1fr;
    gap: 8px;
  }

  .touch-pad {
    grid-template-columns: repeat(2, 82px);
    grid-template-rows: repeat(2, 82px);
    width: 172px;
    height: 172px;
  }

  .touch-pad .touch-button {
    width: 82px;
    height: 82px;
    font-size: 22px;
  }

  .touch-actions {
    gap: 6px;
  }

  .touch-button {
    min-height: 40px;
    font-size: 11px;
  }

  .touch-rotation {
    min-height: 86px;
    font-size: 13px;
  }
}
