* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f1b26;
  --bg2: #16232f;
  --panel: #1c2d3d;
  --panel2: #23364a;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef4f8;
  --muted: #93a7b8;
  --red: #e3350d;
  --red-dark: #b3280a;
  --yellow: #f8d030;
  --green: #3fa88a;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, #1d3346 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 1920px;
  padding: 24px 18px 40px;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

.screen.active {
  display: flex;
}

/* ---------- 角色选择 ---------- */
.hero {
  text-align: center;
  padding: 18px 0 6px;
}

.hero-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2b4055, #1a2b3a);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), inset 0 0 0 2px var(--border);
}

.hero h1 {
  font-size: 30px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--yellow), #ffb43a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.char-card {
  background: #182938;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  user-select: none;
  position: relative;
}

.char-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.25);
}

.char-card.selected {
  border-color: var(--yellow);
  background: #223146;
  box-shadow: 0 0 0 3px rgba(248, 208, 48, 0.18), 0 6px 18px rgba(0, 0, 0, 0.3);
}

.char-card.selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--yellow);
  font-weight: 800;
}

.char-card canvas {
  image-rendering: pixelated;
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

.char-card .cn {
  font-size: 15px;
  font-weight: 700;
}

.char-card .en {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.level-row {
  display: flex;
  gap: 10px;
}

.level-card {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  background: #182938;
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.level-card .lv {
  font-size: 15px;
  font-weight: 700;
}

.level-card .desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.level-card.selected {
  border-color: var(--green);
  background: #1d3643;
  box-shadow: 0 0 0 3px rgba(63, 168, 138, 0.18);
}

.btn {
  border: none;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 800;
  padding: 15px 20px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(180deg, #ff5a2e, var(--red));
  color: #fff;
  box-shadow: 0 6px 18px rgba(227, 53, 13, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  font-size: 15px;
}

.score-board {
  display: flex;
  gap: 10px;
}

.score-card {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.score-card .rank {
  font-size: 12px;
  color: var(--muted);
}

.score-card .val {
  font-size: 16px;
  font-weight: 800;
  color: var(--yellow);
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- 游戏界面 ---------- */
#game-screen {
  align-items: center;
  gap: 12px;
}

.hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud-top {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  width: auto;
  z-index: 4;
}

.hud-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(23, 38, 52, 0.82);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}

.hud-center {
  display: flex;
  gap: 26px;
  align-items: baseline;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-size: 11px;
  color: var(--muted);
}

.hud-item span:last-child {
  font-size: 22px;
  font-weight: 800;
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
}

.char-tag {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(23, 38, 52, 0.82);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px 5px 6px;
  backdrop-filter: blur(3px);
}

.char-tag canvas {
  image-rendering: pixelated;
}

.char-tag span {
  font-size: 13px;
  font-weight: 700;
}

.speed-tag {
  background: rgba(63, 168, 138, 0.18);
  color: var(--green);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px !important;
  font-weight: 600 !important;
}

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
}

#board {
  display: block;
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border);
  background: var(--bg2);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(9, 16, 24, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.overlay-box {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 30px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
}

.overlay-box h2 {
  font-size: 24px;
  letter-spacing: 2px;
  margin-bottom: 14px;
}

.overlay-score .big {
  font-size: 52px;
  font-weight: 900;
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
}

.overlay-score .unit {
  color: var(--muted);
  margin-left: 4px;
}

.overlay-score .sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.overlay-btns {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.overlay-btns .btn {
  flex: 1;
  padding: 12px 8px;
  font-size: 15px;
}

.touchpad {
  display: none;
  grid-template-rows: auto auto auto;
  gap: 6px;
  margin-top: 4px;
}

.pad-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.pad-btn {
  width: 60px;
  height: 52px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.pad-btn:active {
  background: var(--panel2);
  transform: scale(0.95);
}

.pad-center {
  background: transparent;
  border: none;
}

@media (max-width: 640px) {
  .touchpad {
    display: grid;
  }

  #game-screen {
    min-height: calc(100vh - 40px);
    justify-content: flex-start;
  }
}

@media (min-width: 641px) {
  .char-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
