* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 24px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #eef1f7;
  background: radial-gradient(circle at top, #242a40 0%, #141726 70%);
  overflow-x: hidden;
}

header {
  text-align: center;
  max-width: 640px;
  width: 100%;
}

h1 {
  margin: 0 0 6px;
  font-size: 30px;
  letter-spacing: 4px;
  color: #ffd27a;
  text-shadow: 0 2px 12px rgba(255, 170, 60, 0.35);
}

.intro {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.7;
  color: #aab3c9;
}

main {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud {
  margin: 4px 0 10px;
  font-size: 16px;
  color: #d8deec;
  text-align: center;
}

.stage {
  position: relative;
  width: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 2px solid #3a4262;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(12, 14, 24, 0.72);
  backdrop-filter: blur(2px);
}

.overlay.show {
  display: flex;
}

#msg {
  margin: 0;
  white-space: pre-line;
  text-align: center;
  font-size: 17px;
  line-height: 1.8;
  color: #f4f6fb;
}

.btn {
  padding: 10px 34px;
  border: none;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 600;
  color: #2a1a06;
  background: linear-gradient(135deg, #ffd27a, #ff9f43);
  box-shadow: 0 6px 18px rgba(255, 159, 67, 0.4);
  cursor: pointer;
}

.btn:active {
  transform: translateY(2px);
}

.touch {
  display: none;
  width: 100%;
  margin-top: 14px;
  justify-content: space-between;
  align-items: center;
}

@media (pointer: coarse) {
  .touch {
    display: flex;
  }
}

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

.pad button {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  font-size: 18px;
  color: #eef1f7;
  background: #2c3350;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.pad button:active {
  background: #3d4870;
}

.pad .fire {
  background: #b83a32;
  font-size: 13px;
  font-weight: 600;
}

.pad button[data-k="up"] {
  grid-column: 2;
  grid-row: 1;
}

.pad button[data-k="left"] {
  grid-column: 1;
  grid-row: 2;
}

.pad .fire {
  grid-column: 2;
  grid-row: 2;
}

.pad button[data-k="right"] {
  grid-column: 3;
  grid-row: 2;
}

.pad button[data-k="down"] {
  grid-column: 2;
  grid-row: 3;
}

footer {
  margin-top: 18px;
  max-width: 640px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: #7f89a6;
}

footer p {
  margin: 0;
}
