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

:root {
  --gold: #f5c542;
  --red: #e04545;
  --green: #6fd36f;
  --panel: rgba(16, 20, 26, .92);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0d12;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #e8e4d8;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#game { position: absolute; inset: 0; display: block; touch-action: none; }

/* ---------- 触屏操作层 ---------- */
#touchUI { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
.stick {
  position: absolute; bottom: calc(28px + env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.2);
  pointer-events: auto; touch-action: none;
}
#stickMove { left: calc(22px + env(safe-area-inset-left)); }
.stick-aim { right: calc(22px + env(safe-area-inset-right)); border-color: rgba(255,120,100,.35); }
.stick .knob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(255,255,255,.22);
}
.stick-aim .knob { background: rgba(255,130,110,.3); }
#touchWeapons {
  position: absolute; right: calc(18px + env(safe-area-inset-right));
  bottom: calc(178px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 9px; pointer-events: auto;
}
#touchWeapons button {
  width: 52px; height: 52px; border-radius: 12px; font-size: 22px; position: relative;
  background: rgba(16,20,26,.72); border: 1px solid rgba(255,255,255,.22); color: #fff;
  touch-action: none;
}
#touchWeapons button span { position: absolute; bottom: 1px; right: 5px; font-size: 10px; color: var(--gold); }
#touchWeapons button.active { border-color: var(--gold); box-shadow: 0 0 9px rgba(245,197,66,.5); }
#touchWeapons button:disabled { opacity: .32; }
#touchPause {
  position: absolute; top: calc(58px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 10px; font-size: 18px;
  background: rgba(16,20,26,.72); border: 1px solid rgba(255,255,255,.22); color: #fff;
  pointer-events: auto; touch-action: none;
}

.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at 50% 30%, #1a222e 0%, #0a0d12 75%);
  z-index: 20;
}
.screen.overlay { background: rgba(6, 8, 11, .78); backdrop-filter: blur(3px); }

.fog {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 20% 80%, rgba(90,140,80,.10) 0%, transparent 45%),
    radial-gradient(circle at 80% 20%, rgba(160,60,60,.10) 0%, transparent 45%);
  animation: fogmove 9s ease-in-out infinite alternate;
}
@keyframes fogmove { from { opacity: .5; } to { opacity: 1; } }

.title {
  font-size: 92px; letter-spacing: 12px; font-weight: 900;
  text-shadow: 0 0 30px rgba(224,69,69,.35), 0 4px 0 #000;
  z-index: 1;
}
.title .t1 { color: #b8e086; }
.title .t2 { color: var(--red); }
.subtitle { color: #8b94a3; letter-spacing: 6px; margin-bottom: 20px; z-index: 1; }

.screen-title { font-size: 42px; letter-spacing: 6px; text-shadow: 0 3px 0 #000; }
.screen-title.red { color: var(--red); }
.screen-title.gold { color: var(--gold); }
.screen-sub { color: #8b94a3; }

/* ---------- buttons ---------- */
.btn {
  min-width: 220px; padding: 13px 34px;
  font-size: 19px; letter-spacing: 3px; font-family: inherit;
  color: #e8e4d8; cursor: pointer;
  background: linear-gradient(180deg, #2c3542 0%, #1b222c 100%);
  border: 1px solid #48566a; border-radius: 6px;
  box-shadow: 0 4px 0 #10151c, 0 6px 14px rgba(0,0,0,.5);
  transition: transform .08s, filter .15s;
  z-index: 1;
}
.btn:hover { filter: brightness(1.25); transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #10151c; }
.btn.big {
  font-size: 24px; padding: 16px 46px;
  background: linear-gradient(180deg, #7a2c2c 0%, #4c1717 100%);
  border-color: #a85050;
}
.btn.small { min-width: 0; font-size: 15px; padding: 9px 22px; }
.btn.back { position: absolute; left: 30px; bottom: 30px; min-width: 0; }
.btn:disabled { opacity: .35; cursor: not-allowed; filter: grayscale(.6); }

.menu-btns { display: flex; flex-direction: column; gap: 14px; align-items: center; z-index: 1; }
.menu-coins { position: absolute; top: 26px; right: 34px; font-size: 22px; color: var(--gold); }

/* ---------- map cards ---------- */
.map-cards { display: flex; gap: 26px; }
.map-card {
  width: 250px; height: 330px; border-radius: 10px; overflow: hidden;
  border: 2px solid #3a4657; cursor: pointer; position: relative;
  background: #141a22;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.map-card:hover:not(.locked) {
  transform: translateY(-8px) scale(1.03);
  border-color: var(--gold);
  box-shadow: 0 14px 34px rgba(0,0,0,.6);
}
.map-card .thumb { height: 190px; position: relative; }
.map-card h3 { font-size: 24px; padding: 14px 16px 4px; letter-spacing: 3px; }
.map-card p { font-size: 13px; color: #8b94a3; padding: 0 16px; line-height: 1.5; }
.map-card .prog { position: absolute; bottom: 10px; left: 16px; font-size: 13px; color: var(--gold); }
.map-card.locked { cursor: not-allowed; filter: grayscale(.85) brightness(.55); }
.map-card.locked::after {
  content: "🔒 通关上一区域解锁";
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #ccc; background: rgba(0,0,0,.45);
}

/* ---------- level buttons ---------- */
.level-btns { display: flex; gap: 18px; }
.level-btn {
  width: 92px; height: 92px; border-radius: 10px;
  font-size: 30px; font-weight: 900; font-family: inherit; color: #e8e4d8;
  background: linear-gradient(180deg, #2c3542, #1b222c);
  border: 2px solid #48566a; cursor: pointer; position: relative;
  transition: transform .12s, border-color .12s;
}
.level-btn:hover:not(:disabled) { transform: translateY(-5px); border-color: var(--gold); }
.level-btn .star { position: absolute; bottom: 6px; left: 0; right: 0; font-size: 13px; color: var(--gold); }
.level-btn.boss { border-color: #a04040; color: #ff9a7a; }
.level-btn.boss::before { content: "👹"; position: absolute; top: -14px; right: -8px; font-size: 22px; }

/* ---------- shop ---------- */
.shop-coins { font-size: 24px; color: var(--gold); }
.shop-rows { display: flex; flex-direction: column; gap: 10px; width: min(620px, 92vw); max-height: 56vh; overflow-y: auto; padding-right: 6px; }
.shop-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid #333e4e; border-radius: 8px;
  padding: 12px 16px;
}
.shop-row .icon { font-size: 30px; width: 44px; text-align: center; }
.shop-row .info { flex: 1; }
.shop-row .info b { font-size: 17px; letter-spacing: 1px; }
.shop-row .info small { display: block; color: #8b94a3; margin-top: 3px; }
.pips { display: flex; gap: 4px; margin-top: 6px; }
.pip { width: 22px; height: 8px; border-radius: 2px; background: #2a3340; }
.pip.on { background: var(--green); box-shadow: 0 0 6px rgba(111,211,111,.5); }
.shop-row .lv-tag { min-width: 90px; text-align: center; color: var(--gold); font-size: 15px; }
.shop-row.locked { opacity: .45; filter: grayscale(.5); }
.shop-row.locked .lv-tag { color: #8b94a3; }
.shop-cat {
  margin-top: 8px; padding: 2px 4px;
  font-size: 15px; letter-spacing: 2px; color: #aab4c2;
  border-bottom: 1px solid #333e4e;
}
.shop-row .buy {
  min-width: 110px; padding: 10px 14px; font-size: 15px; font-family: inherit;
  color: #1b1405; font-weight: 700; letter-spacing: 1px;
  background: linear-gradient(180deg, #f5c542, #c99a1e);
  border: none; border-radius: 6px; cursor: pointer;
}
.shop-row .buy:hover:not(:disabled) { filter: brightness(1.12); }
.shop-row .buy:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- 通关三选一 ---------- */
.win-upgrades { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.win-upgrades .screen-sub { color: var(--gold); }
.up-row { display: flex; gap: 14px; }
.up-card {
  width: 170px; padding: 16px 12px; font-family: inherit; color: #e8e4d8;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: linear-gradient(180deg, #2c3542, #1b222c);
  border: 2px solid #48566a; border-radius: 10px; cursor: pointer;
  transition: transform .12s, border-color .12s;
}
.up-card:hover:not(:disabled) { transform: translateY(-5px); border-color: var(--gold); }
.up-card .ic { font-size: 32px; }
.up-card b { font-size: 17px; letter-spacing: 2px; }
.up-card small { color: #8b94a3; line-height: 1.4; }
.up-card em { font-style: normal; color: var(--green); font-size: 13px; }
.up-card:disabled { opacity: .35; cursor: default; }
.up-card.picked {
  opacity: 1; border-color: var(--gold);
  box-shadow: 0 0 18px rgba(245,197,66,.4);
}

/* ---------- help / results ---------- */
.help-box {
  width: min(640px, 90vw); background: var(--panel);
  border: 1px solid #333e4e; border-radius: 10px;
  padding: 26px 30px; line-height: 2; font-size: 16px;
}
.help-box b { color: var(--gold); }

.result-stats {
  background: var(--panel); border: 1px solid #333e4e; border-radius: 10px;
  padding: 18px 40px; font-size: 18px; line-height: 2.1; text-align: center;
}
.result-stats .gold { color: var(--gold); }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 20px; pointer-events: none;
  text-shadow: 0 2px 3px rgba(0,0,0,.8);
}
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 8px; }
.hud-right { align-items: flex-end; }
.hp-wrap { display: flex; align-items: center; gap: 8px; }
.hp-label { color: var(--red); font-size: 20px; }
.hp-bar {
  width: 230px; height: 20px; border-radius: 10px; position: relative;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.18); overflow: hidden;
}
#hpFill {
  height: 100%; width: 100%; border-radius: 9px;
  background: linear-gradient(180deg, #7ee06f, #3d9c3d);
  transition: width .18s;
}
#hpFill.low { background: linear-gradient(180deg, #f0716d, #b02c2c); }
.hp-bar span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.hud-coins { font-size: 19px; color: var(--gold); }
.hud-weapon {
  font-size: 16px; color: #cfe0ff; letter-spacing: 1px;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.18);
  border-radius: 6px; padding: 5px 12px; width: fit-content;
}
.hud-center { text-align: center; }
.hud-map { font-size: 15px; color: #aab4c2; letter-spacing: 2px; }
.hud-wave { font-size: 22px; font-weight: 900; letter-spacing: 3px; color: #f0e6c8; }
.hud-kills { font-size: 19px; }
.hud-hint { font-size: 12px; color: #6b7686; }

#waveBanner {
  position: absolute; top: 34%; left: 0; right: 0; z-index: 11;
  text-align: center; font-size: 54px; font-weight: 900; letter-spacing: 10px;
  color: #f0e6c8; text-shadow: 0 0 24px rgba(224,69,69,.55), 0 4px 0 #000;
  pointer-events: none;
  animation: bannerIn 2.4s ease forwards;
}
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(1.6); }
  15% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- 手机小屏适配 ---------- */
@media (max-width: 760px), (max-height: 500px) {
  .title { font-size: 42px; letter-spacing: 6px; }
  .subtitle { font-size: 12px; letter-spacing: 3px; margin-bottom: 8px; }
  .screen-title { font-size: 26px; letter-spacing: 3px; }
  .screen { gap: 12px; }
  .btn { min-width: 170px; padding: 10px 22px; font-size: 16px; }
  .btn.big { font-size: 19px; padding: 12px 30px; }
  .btn.back { left: 14px; bottom: 14px; padding: 8px 16px; min-width: 0; }
  .map-cards { flex-wrap: wrap; justify-content: center; gap: 12px; max-height: 62vh; overflow-y: auto; }
  .map-card { width: 150px; height: 212px; }
  .map-card .thumb { height: 96px; }
  .map-card .thumb canvas { width: 100%; height: 100%; }
  .map-card h3 { font-size: 15px; padding: 8px 10px 2px; }
  .map-card p { font-size: 10px; padding: 0 10px; }
  .map-card .prog { font-size: 11px; left: 10px; bottom: 6px; }
  .level-btns { flex-wrap: wrap; justify-content: center; gap: 10px; }
  .level-btn { width: 62px; height: 62px; font-size: 22px; }
  .level-btn .star { font-size: 10px; }
  .up-row { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .up-card { width: 130px; padding: 10px 8px; }
  .up-card .ic { font-size: 24px; }
  .up-card b { font-size: 14px; }
  .up-card small { font-size: 11px; }
  .help-box { padding: 14px 16px; font-size: 12px; line-height: 1.7; max-height: 58vh; overflow-y: auto; }
  .result-stats { padding: 10px 20px; font-size: 14px; line-height: 1.8; }
  .shop-rows { max-height: 52vh; }
  .shop-row { padding: 8px 10px; gap: 8px; }
  .shop-row .icon { font-size: 22px; width: 32px; }
  .shop-row .info b { font-size: 14px; }
  .shop-row .lv-tag { min-width: 64px; font-size: 12px; }
  #hud { padding: 8px 10px; }
  .hp-bar { width: 130px; height: 16px; }
  .hud-map { font-size: 10px; }
  .hud-wave { font-size: 13px; }
  .hud-kills { font-size: 14px; }
  .hud-weapon { font-size: 12px; padding: 3px 8px; }
  .hud-hint { display: none; }
  #waveBanner { font-size: 26px; letter-spacing: 4px; }
}
