:root {
  color-scheme: dark;
  --ink: #fff7dc;
  --muted: #b7c1bc;
  --line: rgba(255, 255, 255, 0.16);
  --panel: rgba(16, 24, 32, 0.92);
  --panel-strong: #101820;
  --gold: #f3c14b;
  --green: #43d18f;
  --red: #f05d52;
  --blue: #4aa3ff;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 247, 220, 0.06), transparent 34%),
    #0b1117;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

.game-shell {
  width: min(100vw, 520px);
  height: 100svh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) 132px;
  gap: 8px;
}

.topbar,
.hud {
  position: relative;
  z-index: 2;
}

.topbar {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  flex: 0 0 auto;
  padding: 5px 7px;
  border: 2px solid var(--gold);
  border-radius: 4px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0;
}

.icon-button {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 28px;
  font-weight: 800;
}

.hud {
  display: grid;
  grid-template-columns: 0.8fr 0.8fr 1.4fr;
  gap: 7px;
}

.stat {
  min-width: 0;
  min-height: 50px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  align-content: center;
  gap: 5px;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.stat strong {
  font-size: 22px;
  line-height: 1;
}

.stat b {
  color: var(--green);
}

.cooldown-track {
  height: 17px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

#dashFill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green), var(--gold));
  transition: width 80ms linear;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #19252c;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  background: #19252c;
}

.message-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(360px, calc(100% - 28px));
  transform: translate(-50%, -50%);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(12, 18, 24, 0.94);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 12px;
  text-align: center;
}

.message-panel[hidden] {
  display: none;
}

.message-panel strong {
  font-size: 30px;
  line-height: 1.05;
}

.message-panel span {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

#startBtn {
  min-height: 48px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #ef8c4f);
  color: #15100b;
  font-weight: 900;
}

.touch-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.joystick {
  width: 116px;
  height: 116px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.09) 0 30%, transparent 31%),
    rgba(255, 255, 255, 0.07);
  position: relative;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.24);
}

.stick {
  width: 54px;
  height: 54px;
  position: absolute;
  left: 31px;
  top: 31px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fff0a7, var(--gold));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.action-stack {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-button {
  width: 82px;
  height: 82px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: #101820;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.action-button:active,
.icon-button:active,
#startBtn:active {
  transform: translateY(1px) scale(0.98);
}

.dash {
  background: radial-gradient(circle at 35% 28%, #dcf4ff, var(--blue) 72%);
}

.arrest {
  background: radial-gradient(circle at 35% 28%, #fff8cb, var(--gold) 72%);
}

.action-button[disabled] {
  opacity: 0.48;
}

@media (min-width: 700px) {
  body {
    background:
      linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent),
      #0b1117;
  }
}

@media (max-width: 380px) {
  .game-shell {
    grid-template-rows: auto auto minmax(0, 1fr) 118px;
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  h1 {
    font-size: 21px;
  }

  .badge {
    font-size: 10px;
  }

  .joystick {
    width: 104px;
    height: 104px;
  }

  .stick {
    width: 48px;
    height: 48px;
    left: 28px;
    top: 28px;
  }

  .action-button {
    width: 72px;
    height: 72px;
    font-size: 16px;
  }
}
