* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #0a0a1a;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 20px;
}

#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
  width: 100%;
  max-width: 768px;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  border: 2px solid #333;
  width: 100%;
  max-width: 768px;
  height: auto;
  aspect-ratio: 256 / 240;
}

/* ---- Fullscreen button ---- */
#fullscreen-btn {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 100;
  width: 36px;
  height: 36px;
  background: rgba(30, 30, 50, 0.75);
  color: #ccc;
  border: 1px solid #555;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

#fullscreen-btn:hover,
#fullscreen-btn:focus-visible {
  background: rgba(60, 60, 100, 0.9);
  color: #fff;
}

/* ---- Touch controls overlay ---- */
#touch-controls {
  position: fixed;
  bottom: 12px;
  left: 0;
  right: 0;
  z-index: 90;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px;
  pointer-events: none;
}

#touch-controls button {
  pointer-events: auto;
}

/* D-pad */
.dpad {
  display: grid;
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  gap: 2px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.dpad-btn:active {
  background: rgba(255, 255, 255, 0.35);
}

.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

/* START button */
.start-btn {
  width: 72px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  background: rgba(180, 180, 180, 0.25);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  font-size: 12px;
  font-weight: bold;
  font-family: monospace;
  letter-spacing: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  pointer-events: auto;
}

.start-btn:active {
  background: rgba(180, 180, 180, 0.5);
  color: #fff;
  transform: scale(0.94);
}

/* Action buttons */
.action-btns {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.action-btn {
  width: 56px;
  height: 56px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: bold;
  font-family: monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.4);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.action-btn:active {
  transform: scale(0.92);
}

.btn-z {
  background: rgba(80, 160, 255, 0.4);
  color: #fff;
}

.btn-z:active {
  background: rgba(80, 160, 255, 0.65);
}

.btn-x {
  background: rgba(255, 100, 100, 0.4);
  color: #fff;
}

.btn-x:active {
  background: rgba(255, 100, 100, 0.65);
}

/* ---- Help panel ---- */
#help-panel {
  width: 100%;
  max-width: 768px;
  background: #111;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 12px 16px;
  color: #ccc;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 13px;
  line-height: 1.6;
}

#help-panel h3 {
  color: #f0d060;
  margin: 8px 0 4px;
  font-size: 14px;
}

#help-panel h3:first-child {
  margin-top: 0;
}

#help-panel table {
  width: 100%;
  border-collapse: collapse;
}

#help-panel td {
  padding: 2px 8px;
}

#help-panel td:first-child {
  color: #6db3f8;
  width: 140px;
  font-family: monospace;
}

#help-panel p {
  margin: 2px 0;
  color: #bbb;
}

/* ---- Mobile adjustments ---- */
@media (max-width: 480px) {
  body {
    padding-top: 0;
  }

  #game-wrapper {
    gap: 6px;
  }

  #help-panel {
    font-size: 12px;
    padding: 8px 10px;
  }

  /* Larger touch targets on small screens */
  .dpad-btn {
    width: 52px;
    height: 52px;
  }

  .action-btn {
    width: 60px;
    height: 60px;
  }
}
