:root {
  color-scheme: dark;
  --bg: #0b1016;
  --panel: #131b24;
  --line: #24313e;
  --text: #e7eef6;
  --muted: #8fa3b8;
  --accent: #f2c94c;
  --danger: #ef6d5a;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #cfd8e3;
  --text: #1b2430;
  --muted: #5d6f82;
  --accent: #b98a12;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #16202b 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

.app {
  width: min(680px, 100vw);
  margin: 0 auto;
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 2px;
}

.stats {
  display: flex;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  min-width: 44px;
}

.stat .label {
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 1px;
}

.stage {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #070a0e;
  aspect-ratio: 1 / 1;
}

#field {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 9, 13, 0.78);
  backdrop-filter: blur(2px);
  transition: opacity 0.18s ease;
}

.overlay[hidden] {
  display: none;
}

.panel {
  max-width: 360px;
  text-align: center;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 3px;
  color: var(--accent);
}

.panel p {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.7;
  color: #cdd9e5;
}

.panel button,
.fire,
.key {
  font: inherit;
  color: var(--text);
  background: #1d2833;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.panel button {
  padding: 10px 22px;
  font-weight: 700;
  background: var(--accent);
  border-color: var(--accent);
  color: #201a05;
}

.panel button:active { transform: translateY(1px); }

.pad {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 8px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
}

.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 2 / 2; }

.key {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.key.active,
.fire.active {
  background: #2c3d4f;
  border-color: var(--accent);
}

.fire {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  color: #201a05;
  background: var(--accent);
  border-color: var(--accent);
}

.hints {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

@media (pointer: coarse), (max-width: 720px) {
  .pad { display: flex; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 17px; }
  .stat { font-size: 14px; min-width: 38px; }
  .hints { font-size: 10px; }
}
