:root {
  --bg-outer: #090b12;
  --shell-bg: #121521;
  --topbar-bg: rgba(18, 21, 33, 0.94);
  --panel-bg: rgba(23, 27, 43, 0.96);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --text-main: #f4f7ff;
  --text-dim: #9aa6c4;
  --gold: #ffd15c;
  --cyan: #4de2ff;
  --o2-safe: #32e2ff;
  --o2-warn: #ffab38;
  --o2-danger: #ff4757;
  --flame: #ff6b35;
  --crystal: #c77dff;
  --green: #38e59b;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(77, 226, 255, 0.12), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(255, 107, 53, 0.14), transparent 50%),
    var(--bg-outer);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hidden {
  display: none !important;
}

/* 9:16 微信小游戏竖屏外壳 */
.wx-shell {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: min(100dvh, 860px);
  background: var(--shell-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(77, 226, 255, 0.08);
}

@media (max-width: 460px) {
  .wx-shell {
    height: 100dvh;
    max-width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

/* 模拟微信小游戏顶栏 */
.wx-topbar {
  flex: 0 0 auto;
  height: 46px;
  padding: 0 10px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 20;
}

.wx-back {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s, transform 0.12s;
  white-space: nowrap;
}

.wx-back:hover {
  background: rgba(255, 255, 255, 0.16);
}

.wx-back:active {
  transform: scale(0.95);
}

.wx-title {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff6dc;
}

.wx-capsule {
  display: inline-flex;
  align-items: center;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.wx-cap-btn {
  width: 34px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.wx-cap-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.wx-cap-divider {
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.18);
}

/* HUD 区域 */
.hud-panel {
  flex: 0 0 auto;
  padding: 8px 10px 6px;
  background: linear-gradient(180deg, #171c2e 0%, #131725 100%);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 15;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-stat {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-depth {
  flex: 1.45;
  gap: 4px;
}

.hud-timer {
  flex: 0.8;
  align-items: center;
}

.hud-coins {
  flex: 0.95;
  align-items: flex-end;
}

.hud-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.hud-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(255, 187, 85, 0.2);
  color: #ffd37d;
  white-space: nowrap;
}

.hud-micro {
  font-size: 10px;
  color: var(--text-dim);
  line-height: 1.1;
}

.hud-val {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.hud-val.gold {
  color: var(--gold);
}

.hud-val.danger {
  color: var(--o2-danger);
  animation: pulseText 0.65s infinite alternate;
}

.mini-bar {
  width: 100%;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.mini-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ff9f43, #ff5e57, #c77dff);
  transition: width 0.2s ease-out;
}

/* 氧气条 + 应急氧气 */
.o2-wrap {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(77, 226, 255, 0.18);
  border-radius: 10px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.o2-wrap.low {
  border-color: rgba(255, 71, 87, 0.85);
  box-shadow: 0 0 12px rgba(255, 71, 87, 0.35);
  animation: o2Pulse 0.6s infinite alternate;
}

.o2-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
}

.o2-label {
  color: #bcefff;
}

.o2-pct {
  color: var(--o2-safe);
}

.o2-wrap.low .o2-pct {
  color: var(--o2-danger);
}

.o2-bar {
  width: 100%;
  height: 8px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.38);
  overflow: hidden;
}

.o2-fill {
  width: 100%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #27c6ff, #65f3ff);
  transition: width 0.1s linear, background 0.25s;
}

.btn-o2-emergency {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(77, 226, 255, 0.35);
  background: linear-gradient(180deg, rgba(39, 198, 255, 0.22), rgba(18, 118, 173, 0.32));
  color: #dff9ff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s;
}

.btn-o2-emergency:hover:not(:disabled) {
  filter: brightness(1.15);
}

.btn-o2-emergency:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-o2-emergency:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-o2-emergency.urgent:not(:disabled) {
  border-color: #65f3ff;
  box-shadow: 0 0 14px rgba(77, 226, 255, 0.55);
  animation: pulseBtn 0.7s infinite alternate;
}

.emg-top {
  font-size: 11px;
  font-weight: 700;
}

.emg-cost {
  font-size: 10px;
  color: var(--gold);
  font-weight: 700;
}

/* 装备图标栏 */
.upgrade-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  overflow-x: auto;
  scrollbar-width: none;
}

.upgrade-strip::-webkit-scrollbar {
  display: none;
}

.upg-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11px;
  font-weight: 700;
  color: #eaf2ff;
}

.upg-chip-empty {
  font-size: 10px;
  color: rgba(154, 166, 196, 0.65);
}

/* Canvas 舞台 */
.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  background: #14111c;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* 连锁爆炸横幅 */
.chain-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  padding: 6px 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 94, 58, 0.94), rgba(255, 177, 43, 0.94));
  color: #1c0b04;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.4px;
  box-shadow: 0 6px 20px rgba(255, 94, 58, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 12;
  white-space: nowrap;
}

.chain-banner.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* 弹窗覆盖层 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 11, 20, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 30;
  overflow-y: auto;
}

.overlay-start {
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 184, 77, 0.2), transparent 46%),
    linear-gradient(180deg, rgba(24, 18, 34, 0.88) 0%, rgba(16, 12, 24, 0.94) 55%, rgba(44, 15, 22, 0.95) 100%);
}

.start-card,
.modal-card {
  width: 100%;
  max-width: 380px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(29, 34, 54, 0.96), rgba(18, 21, 35, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.13);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  text-align: center;
}

.start-emblem {
  position: relative;
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 18px;
  background: linear-gradient(135deg, #ffb84d, #ff5e57 60%, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 26px rgba(255, 118, 66, 0.45);
}

.emblem-icon {
  font-size: 30px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.start-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffe082, #ff9f43, #ff6b6b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.15;
}

.start-sub {
  font-size: 12px;
  color: #cbd5f0;
  margin-top: -6px;
}

/* 地下分层预览条 */
.strata-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.st-chip {
  flex: 1;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 2px;
  border-radius: 8px;
  color: #fff;
  white-space: nowrap;
}

.st-1 { background: #6b4423; }
.st-2 { background: #9c4a26; }
.st-3 { background: #434b63; }
.st-4 { background: #5a2e8a; }
.st-5 { background: #b52b27; }

/* 模式切换 */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  padding: 9px 8px;
  border-radius: 13px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

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

.mode-btn.active {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(255, 209, 92, 0.2), rgba(255, 126, 61, 0.15));
  box-shadow: 0 0 18px rgba(255, 209, 92, 0.22);
}

.mode-name {
  font-size: 13px;
  font-weight: 800;
}

.mode-goal {
  font-size: 10px;
  color: var(--text-dim);
}

.mode-btn.active .mode-goal {
  color: #ffe399;
}

/* 玩法说明框 */
.how-to-box {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 9px 10px;
  text-align: left;
  font-size: 11.5px;
  line-height: 1.45;
  color: #d7e0f5;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.how-to-box kbd {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 10px;
  font-family: inherit;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  font-size: 11px;
  color: #ffe8b0;
  font-weight: 600;
}

.best-pill {
  font-size: 11px;
  color: #9be7ff;
  background: rgba(77, 226, 255, 0.1);
  border: 1px solid rgba(77, 226, 255, 0.22);
  border-radius: 999px;
  padding: 5px 10px;
}

/* 按钮体系 */
.btn-primary,
.btn-secondary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 44px;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: transform 0.12s, filter 0.15s;
}

.btn-primary {
  background: linear-gradient(180deg, #ffcf4d 0%, #ff8a2b 100%);
  color: #211003;
  box-shadow: 0 6px 18px rgba(255, 138, 43, 0.42);
}

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

.btn-primary:active,
.btn-secondary:active,
.btn-ghost:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-main);
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
  height: 38px;
  font-size: 13px;
}

/* 三选一升级卡片 */
.upgrade-modal {
  gap: 10px;
  padding: 14px;
}

.upgrade-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 209, 92, 0.2);
  border: 1px solid rgba(255, 209, 92, 0.45);
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
}

.upgrade-title {
  font-size: 18px;
  font-weight: 900;
  color: #fff;
}

.upgrade-sub {
  font-size: 11.5px;
  color: var(--text-dim);
}

.upgrade-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upg-card {
  width: 100%;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

.upg-card:hover {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(255, 209, 92, 0.18), rgba(255, 126, 61, 0.1));
}

.upg-card:active {
  transform: scale(0.98);
}

.upg-card-ico {
  flex: 0 0 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 23px;
}

.upg-card-body {
  flex: 1;
  min-width: 0;
}

.upg-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.upg-card-name {
  font-size: 14px;
  font-weight: 800;
  color: #fff8e1;
}

.upg-card-lv {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 99px;
  background: rgba(77, 226, 255, 0.2);
  color: #7eeeff;
}

.upg-card-desc {
  font-size: 11.5px;
  line-height: 1.35;
  color: #cdd7f0;
}

/* 暂停与结算 */
.pause-icon {
  font-size: 34px;
}

.modal-title {
  font-size: 19px;
  font-weight: 900;
}

.modal-desc {
  font-size: 12px;
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.report-modal {
  gap: 12px;
}

.report-kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--cyan);
  margin-bottom: 8px;
}

.report-rank-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: left;
}

.rank-badge {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  color: #1f1202;
  background: linear-gradient(135deg, #fff099, #ffb833);
  box-shadow: 0 8px 22px rgba(255, 184, 51, 0.45);
}

.rank-badge.rank-A {
  background: linear-gradient(135deg, #c77dff, #7b2cbf);
  color: #fff;
  box-shadow: 0 8px 22px rgba(199, 125, 255, 0.4);
}

.rank-badge.rank-B {
  background: linear-gradient(135deg, #4de2ff, #0077b6);
  color: #fff;
  box-shadow: 0 8px 22px rgba(77, 226, 255, 0.35);
}

.rank-badge.rank-C {
  background: linear-gradient(135deg, #9aa6c4, #525d7a);
  color: #fff;
  box-shadow: none;
}

.report-title {
  font-size: 18px;
  font-weight: 900;
  color: #fff;
}

.report-reason {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rep-cell {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rep-label {
  font-size: 10.5px;
  color: var(--text-dim);
}

.rep-val {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}

.rep-val.gold {
  color: var(--gold);
}

.rep-val.flame {
  color: #ff8c42;
}

.report-best {
  font-size: 11.5px;
  color: #9be7ff;
  background: rgba(77, 226, 255, 0.1);
  border: 1px solid rgba(77, 226, 255, 0.22);
  border-radius: 10px;
  padding: 7px 10px;
}

/* 底部触控方向键 + 投掷炸弹 */
.controls-dock {
  flex: 0 0 auto;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #151929 0%, #0f1220 100%);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: stretch;
  gap: 8px;
  z-index: 15;
  touch-action: none;
}

.dpad-group {
  flex: 1.9;
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 7px;
}

.ctrl-btn {
  position: relative;
  overflow: hidden;
  height: 58px;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, #27304d 0%, #1c2238 100%);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 0 #0d101c;
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s, border-color 0.12s;
  touch-action: none;
}

.ctrl-btn.pressed,
.ctrl-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0d101c;
  border-color: var(--gold);
  background: linear-gradient(180deg, #3c4972 0%, #273152 100%);
}

.ctrl-down {
  border-color: rgba(255, 209, 92, 0.35);
  background: linear-gradient(180deg, #3a3225 0%, #241f18 100%);
}

.ctrl-down.pressed,
.ctrl-down:active {
  background: linear-gradient(180deg, #5e4c2a 0%, #3d311a 100%);
}

.ctrl-bomb {
  flex: 0.92;
  border-color: rgba(255, 107, 53, 0.55);
  background: linear-gradient(180deg, #59261d 0%, #3a1714 100%);
  box-shadow: 0 4px 0 #1f0a09;
}

.ctrl-bomb.ready {
  border-color: #ff8c42;
  box-shadow: 0 4px 0 #1f0a09, 0 0 16px rgba(255, 107, 53, 0.35);
}

.ctrl-bomb.cooling {
  opacity: 0.72;
  border-color: rgba(255, 255, 255, 0.12);
}

.bomb-cd-fill {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0%;
  background: rgba(255, 107, 53, 0.25);
  pointer-events: none;
  transition: height 0.1s linear;
}

.ctrl-ico {
  position: relative;
  z-index: 1;
  font-size: 18px;
  line-height: 1;
}

.ctrl-txt {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

@keyframes o2Pulse {
  from { box-shadow: 0 0 6px rgba(255, 71, 87, 0.25); }
  to { box-shadow: 0 0 16px rgba(255, 71, 87, 0.65); }
}

@keyframes pulseBtn {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

@keyframes pulseText {
  from { opacity: 0.7; }
  to { opacity: 1; }
}
