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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0d0d12;
  color: #e8e6f0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  background: #10131c;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: rgba(10, 10, 16, 0.85);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  padding: 16px;
}

.panel {
  background: rgba(22, 24, 34, 0.95);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 24px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.title {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 2px;
}
.subtitle {
  text-align: center;
  color: #9aa0b4;
  font-size: 14px;
  margin-bottom: 20px;
}

.btn {
  display: inline-block;
  min-width: 140px;
  min-height: 48px;
  padding: 12px 20px;
  margin: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  background: #2a2f44;
  color: #e8e6f0;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, filter 0.15s;
}
.btn:hover { background: #363c58; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: #4c5bd4; border-color: #6b78ee; }
.btn.primary:hover { background: #5a68e0; }
.btn.gold { background: #a07414; border-color: #d2a23c; }
.btn.gold:hover { background: #b5851a; }
.btn.danger { background: #8f2f3c; border-color: #c05263; }
.btn.danger:hover { background: #a23846; }
.btn.small { min-width: 90px; min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.col { display: flex; flex-direction: column; align-items: center; }
.row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.muted { color: #9aa0b4; font-size: 13px; }
.stat-row { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 15px; }

/* ===== 菜单 ===== */
#menuScreen .panel { text-align: center; }
.menu-hero { font-size: 44px; margin: 8px 0; }
.menu-tokens { margin-top: 14px; font-size: 15px; color: #d2a23c; }
.menu-version { position: absolute; bottom: 8px; right: 12px; color: #555a6e; font-size: 12px; }

/* ===== 地图 ===== */
#mapScreen { flex-direction: column; justify-content: flex-start; }
.map-header { text-align: center; margin: 12px 0; }
.map-header h2 { font-size: 22px; }
.map-header .subtitle { margin: 4px 0 0; }
#mapFloorInfo { font-size: 14px; color: #d2a23c; margin-top: 4px; }
#mapContainer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px;
  width: 100%;
  max-width: 640px;
}
.map-row { display: flex; justify-content: center; gap: 10px; position: relative; }
.map-node {
  width: 62px; height: 62px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  background: #232840;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 24px;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, border-color 0.15s;
  z-index: 2;
}
.map-node .node-type { font-size: 11px; color: #b9bfd4; margin-top: 2px; }
.map-node:hover { transform: scale(1.06); }
.map-node.reachable { border-color: #6b78ee; background: #333b60; }
.map-node.reachable:hover { background: #3c456e; }
.map-node.current { border-color: #ffd45e; box-shadow: 0 0 14px rgba(255,212,94,0.4); }
.map-node.cleared { border-color: #4a5a2f; background: #23301d; }
.map-node.locked { opacity: 0.32; cursor: not-allowed; }
.map-node.boss-node { border-color: #b05263; background: #3a1f2a; }
.map-node.boss-node.reachable { border-color: #ff7b8d; background: #4a2734; }
.map-node .node-tag { font-size: 10px; position: absolute; top: -6px; right: -6px; background: #4c5bd4; border-radius: 8px; padding: 1px 6px; }
#mapNextBtn { margin: 16px 0 8px; }

/* ===== 商店 ===== */
#shopScreen .panel { max-width: 520px; }
.shop-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.shop-gold { color: #d2a23c; font-weight: 700; font-size: 18px; }
#shopList { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; max-height: 60vh; overflow-y: auto; }
.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: #1c2030;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px 14px;
}
.shop-item .si-icon { font-size: 30px; width: 44px; text-align: center; }
.shop-item .si-info { flex: 1; }
.shop-item .si-name { font-weight: 700; font-size: 15px; }
.shop-item .si-desc { color: #9aa0b4; font-size: 12px; margin-top: 2px; }
.shop-item .si-rarity { font-size: 11px; }
.shop-item.rarity-rare { border-color: #4c5bd4; }
.shop-item.rarity-epic { border-color: #a074d4; }
.shop-item.rarity-legendary { border-color: #d2a23c; }

/* ===== 休息 ===== */
#restScreen .panel { text-align: center; }
.rest-options { display: flex; gap: 16px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.rest-card {
  width: 190px;
  background: #1c2030;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.rest-card:hover { transform: scale(1.03); border-color: #6b78ee; }
.rest-card .rc-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.rest-card .rc-desc { font-size: 13px; color: #9aa0b4; margin-bottom: 10px; min-height: 40px; }

/* ===== 结算 ===== */
#resultScreen .panel { text-align: center; max-width: 480px; }
.result-grade { font-size: 72px; font-weight: 900; margin: 10px 0; text-shadow: 0 0 30px rgba(255,212,94,0.5); }
.grade-S { color: #ffd45e; }
.grade-A { color: #ff9f4a; }
.grade-B { color: #8fd0ff; }
.grade-C { color: #9fe08a; }
.grade-D { color: #c0c4d8; }
.result-stats { margin: 14px 0; }
.result-tokens { font-size: 20px; color: #d2a23c; font-weight: 800; margin: 10px 0; }

/* ===== 局外成长 ===== */
#metaScreen .panel { max-width: 560px; }
.meta-title { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.meta-tokens { text-align: center; color: #d2a23c; font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.meta-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; max-height: 58vh; overflow-y: auto; }
.meta-item {
  display: flex; align-items: center; justify-content: space-between;
  background: #1c2030; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 12px 16px; gap: 12px;
}
.meta-item .mi-info { flex: 1; }
.meta-item .mi-name { font-weight: 700; }
.meta-item .mi-desc { color: #9aa0b4; font-size: 12px; margin-top: 2px; }
.meta-item .mi-level { color: #8fd0ff; font-size: 13px; }

/* ===== 角色选择 ===== */
.char-grid { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.char-card {
  width: 150px;
  background: #1c2030; border: 2px solid rgba(255,255,255,0.1);
  border-radius: 14px; padding: 14px; text-align: center; cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.char-card:hover { transform: scale(1.03); border-color: #6b78ee; }
.char-card.locked { opacity: 0.6; }
.char-card.selected { border-color: #ffd45e; box-shadow: 0 0 14px rgba(255,212,94,0.3); }
.char-card .cc-icon { font-size: 40px; margin-bottom: 6px; }
.char-card .cc-name { font-weight: 700; font-size: 15px; }
.char-card .cc-weapon { color: #9aa0b4; font-size: 12px; margin: 4px 0; }
.char-card .cc-cost { color: #d2a23c; font-size: 13px; }

/* ===== 战斗 HUD ===== */
#battleHUD {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
}
#hud-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; gap: 10px;
}
#hud-timer { font-size: 22px; font-weight: 800; min-width: 74px; text-align: center; text-shadow: 0 2px 6px rgba(0,0,0,0.8); }
#hud-gold { font-size: 16px; font-weight: 700; color: #d2a23c; text-shadow: 0 2px 6px rgba(0,0,0,0.8); }
#hud-hp-bar {
  flex: 1; max-width: 360px; height: 22px;
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 11px; position: relative; overflow: hidden;
}
#hud-hp-fill { height: 100%; background: linear-gradient(90deg, #c2413a, #e0695f); transition: width 0.15s; }
#hud-hp-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,0.9); }
#hud-level { position: fixed; top: 52px; left: 14px; font-size: 16px; font-weight: 800; text-shadow: 0 2px 6px rgba(0,0,0,0.8); }
#xp-bar { position: fixed; top: 78px; left: 14px; width: 150px; height: 8px; background: rgba(0,0,0,0.5); border-radius: 4px; overflow: hidden; }
#xp-fill { height: 100%; background: linear-gradient(90deg, #4c8fd4, #7fb0ea); transition: width 0.1s; }

#boss-bar {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  width: min(420px, 80vw); height: 18px;
  background: rgba(0,0,0,0.55); border: 1px solid #b05263;
  border-radius: 9px; overflow: hidden; text-align: center;
}
#boss-fill { height: 100%; background: linear-gradient(90deg, #a23846, #e0695f); transition: width 0.2s; }
#boss-name { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,0.9); }

#skill-buttons {
  position: fixed; right: 14px; bottom: 14px;
  display: flex; gap: 12px;
  pointer-events: none;
}
.skill-btn {
  pointer-events: auto;
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(76, 91, 212, 0.35);
  color: #fff; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.skill-btn .cd-mask {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(0,0,0,0.6);
}
.skill-btn .key-hint {
  position: absolute; bottom: -4px; right: -4px;
  background: #1c2030; border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px; font-size: 10px; padding: 1px 5px;
}

/* ===== 升级弹窗 ===== */
#upgradeModal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(8, 8, 14, 0.82);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
}
#upgrade-title { font-size: 24px; font-weight: 800; margin-bottom: 18px; text-shadow: 0 0 20px rgba(124, 140, 255, 0.5); }
#upgrade-options { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; max-width: 720px; }
.up-card {
  width: 190px; min-height: 210px;
  background: #1c2030; border: 2px solid rgba(255,255,255,0.12);
  border-radius: 16px; padding: 16px;
  text-align: center; cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column;
}
.up-card:hover { transform: translateY(-4px) scale(1.02); border-color: #6b78ee; box-shadow: 0 8px 30px rgba(76,91,212,0.35); }
.up-card .uc-icon { font-size: 40px; margin-bottom: 8px; }
.up-card .uc-name { font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.up-card .uc-type { font-size: 11px; color: #8fd0ff; margin-bottom: 8px; }
.up-card .uc-desc { font-size: 12px; color: #b9bfd4; flex: 1; line-height: 1.5; }
.up-card .uc-tier { font-size: 12px; font-weight: 700; margin-top: 8px; }
.tier-common { color: #c0c4d8; }
.tier-rare { color: #6b78ee; }
.tier-epic { color: #a074d4; }
.tier-legendary { color: #d2a23c; }

/* ===== 事件 ===== */
#eventModal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(8, 8, 14, 0.82);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#event-content { text-align: center; font-size: 15px; margin-bottom: 16px; line-height: 1.6; white-space: pre-wrap; }
#event-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }

/* ===== 虚拟摇杆 ===== */
#joystickZone {
  position: fixed; left: 0; bottom: 0;
  width: 170px; height: 170px;
  z-index: 6;
  pointer-events: auto;
}
#joystick-base {
  position: absolute; left: 22px; bottom: 22px;
  width: 126px; height: 126px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.25);
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  border: 2px solid rgba(255,255,255,0.5);
}

/* ===== 暂停 ===== */
#pauseOverlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(8,8,14,0.7);
  display: flex; align-items: center; justify-content: center;
}
#pause-title { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 14px; }

/* ===== 手机适配 ===== */
@media (max-width: 640px) {
  .panel { padding: 18px; }
  .title { font-size: 24px; }
  .map-node { width: 52px; height: 52px; font-size: 20px; }
  .map-node .node-type { font-size: 9px; }
  .up-card { width: 150px; min-height: 180px; padding: 12px; }
  .up-card .uc-icon { font-size: 32px; }
  .char-card { width: 120px; }
  .btn { min-height: 46px; font-size: 15px; }
  .skill-btn { width: 56px; height: 56px; font-size: 22px; }
  .rest-card { width: 150px; }
  #joystick-base { width: 108px; height: 108px; left: 16px; bottom: 16px; }
  #joystick-knob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
  #joystickZone { width: 140px; height: 140px; }
}

@media (max-width: 380px) {
  .map-node { width: 44px; height: 44px; font-size: 18px; }
  .map-node .node-type { display: none; }
}
