:root {
  --ink: #1c2430;
  --paper: #e8f0e4;
  --accent: #2f6f8a;
  --warn: #c45c3a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #121820;
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 12px 20px;
}
header.top {
  width: min(1280px, 100%);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #dce8f0;
  font-size: 14px;
  padding: 6px 4px;
}
header.top .gold { color: #f4d35e; font-weight: 700; }
.mute-btn, .view-btn {
  background: #2b3d4f;
  border: 1px solid #4a6780;
  color: #eef6ff;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.view-switch {
  display: flex;
  gap: 0;
  flex: 0 0 auto;
}
.view-btn { border-radius: 6px 0 0 6px; }
.view-btn + .view-btn { border-radius: 0 6px 6px 0; border-left: 0; }
.view-btn.active {
  background: #3d7a52;
  border-color: #7ecf9a;
}
#stage {
  position: relative;
  width: min(1280px, 100%);
  aspect-ratio: 1280 / 720;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  border-radius: 8px;
  overflow: hidden;
}
canvas#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #5a8a48;
  cursor: crosshair;
}
canvas#fps {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 2;
  cursor: none;
}
canvas#fps.hidden {
  visibility: hidden;
  pointer-events: none;
  z-index: 0;
}
#fps-hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  color: #eef6ff;
  text-shadow: 0 1px 4px #000;
}
#fps-hud.hidden { display: none !important; }
#fps-hud .crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  color: rgba(255,255,255,.85);
  line-height: 1;
}
#fps-draw {
  position: absolute;
  left: 50%;
  top: calc(50% + 28px);
  transform: translateX(-50%);
  width: 160px;
  text-align: center;
  pointer-events: none;
}
#fps-draw.hidden { display: none; }
#fps-draw em {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-style: normal;
  letter-spacing: 0.02em;
  color: #f4e6b0;
}
.fps-draw-track {
  height: 6px;
  background: rgba(0,0,0,.45);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.35);
}
#fps-draw-bar {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #c9a227, #ffe566);
}
#fps-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s linear;
}
#fps-mode {
  position: absolute;
  left: 14px;
  top: 12px;
  font-weight: 700;
  font-size: 15px;
}
#fps-hp {
  position: absolute;
  left: 14px;
  top: 34px;
  font-size: 13px;
  color: #f4d35e;
}
#fps-hud .fps-hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  font-size: 12px;
  opacity: .85;
}
#stage.soldier-on canvas#game {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 22%;
  height: auto;
  z-index: 4;
  border: 2px solid rgba(255,255,255,.7);
  border-radius: 4px;
  cursor: default;
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.bottom {
  width: min(1280px, 100%);
  background: #1e2834;
  color: #eef;
  border-radius: 0 0 8px 8px;
  padding: 8px 10px 12px;
  margin-top: -8px;
}
.row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0;
}
.shop-btn {
  flex: 0 0 auto;
  min-width: 108px;
  background: #2b3d4f;
  border: 1px solid #4a6780;
  color: #eef6ff;
  border-radius: 8px;
  padding: 4px 8px 6px;
  cursor: pointer;
  text-align: center;
}
.shop-btn .ico {
  display: block;
  height: 48px;
}
.shop-btn .ico canvas {
  width: 48px;
  height: 48px;
}
.shop-btn:hover { background: #35506a; }
.shop-btn.tower { border-color: #7a6240; background: #3d3428; }
.shop-btn .n { display: block; font-weight: 700; font-size: 13px; }
.shop-btn .m { display: block; font-size: 11px; opacity: .8; }
#special-btn {
  margin-left: auto;
  background: #8a3a28;
  border: 1px solid #d47a5a;
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}
#special-btn:disabled { opacity: .4; cursor: not-allowed; }
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,14,20,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: auto;
}
#menu { z-index: 20; }
#help-panel, #pause-panel, #result-panel { z-index: 30; }
.panel { position: relative; z-index: 21; pointer-events: auto; }
.overlay.hidden, .hidden { display: none !important; }
.panel {
  background: #f4efe4;
  color: var(--ink);
  padding: 22px 28px;
  border-radius: 10px;
  min-width: 280px;
  max-width: 520px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
}
.panel h1, .panel h2 { margin: 0 0 10px; }
.panel p { margin: 8px 0; line-height: 1.5; font-size: 14px; }
.panel button, .menu-btn {
  margin: 6px;
  padding: 8px 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
}
.panel button.ghost { background: #5a6570; }
#menu {
  background:
    linear-gradient(180deg, rgba(12,20,28,.55), rgba(12,20,28,.82)),
    url("../assets/splash.png") center / cover no-repeat;
  color: #f4f7fa;
}
#menu h1 { font-size: 36px; letter-spacing: 2px; text-shadow: 0 2px 8px #000; }
label.delay { display: block; margin: 12px 0; font-size: 13px; }
input[type=range] { width: 220px; vertical-align: middle; }
#help-panel { text-align: left; }
#status { opacity: .85; }
