@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700;900&display=swap');

:root {
  --bg-deep: #1A0F0A;
  --bg-cave: #2D1B12;
  --bg-panel: #3D2B1E;
  --gold: #C8A951;
  --gold-bright: #F5C542;
  --blue-comp: #2563EB;
  --red-danger: #DC2626;
  --text-light: #E8D5B7;
  --wood: #6B4C3B;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  position: fixed;
  font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-deep);
  color: var(--text-light);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#gameContainer {
  width: 100vw; height: 100vh;
  position: relative;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ===== Canvas ===== */
#gameCanvas {
  display: block;
  width: 100%; height: 100%;
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ===== Screen layers ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.screen.active { display: flex; }

/* ===== 主菜单 ===== */
#menuScreen { z-index: 20; }
.menu-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #3D2B1E 0%, #2D1B12 40%, #1A0F0A 100%);
}
.menu-bg::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 120px; height: 40%;
  background: radial-gradient(ellipse at center, rgba(245,197,66,0.12) 0%, transparent 70%);
}
.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 3vh, 22px);
  padding-top: env(safe-area-inset-top);
}
.menu-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.logo-icon { font-size: clamp(36px, 10vw, 56px); }
.logo-text {
  font-size: clamp(26px, 7vw, 40px);
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 2px 16px rgba(245,197,66,0.5);
  letter-spacing: 4px;
}
.logo-sub {
  font-size: clamp(10px, 2.5vw, 14px);
  color: var(--text-light);
  opacity: 0.7;
  letter-spacing: 5px;
}
.menu-miner {
  font-size: clamp(48px, 15vw, 72px);
  filter: drop-shadow(0 4px 20px rgba(245,197,66,0.3));
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.menu-quote {
  font-size: clamp(10px, 2.5vw, 12px);
  color: var(--text-light);
  opacity: 0.4;
  max-width: 240px;
  text-align: center;
  line-height: 1.6;
  padding-top: 8px;
  border-top: 1px solid rgba(200,169,81,0.12);
}

/* ===== 按钮 ===== */
.btn {
  border: none;
  border-radius: clamp(10px, 2.5vw, 14px);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn-gold {
  padding: 14px 48px;
  background: linear-gradient(180deg, #C8A951 0%, #A8883A 100%);
  border: 2px solid #D4B861;
  color: var(--bg-deep);
  font-size: clamp(16px, 4vw, 20px);
  box-shadow: 0 4px 20px rgba(200,169,81,0.25), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-outline {
  padding: 10px 32px;
  background: transparent;
  border: 2px solid rgba(200,169,81,0.35);
  color: var(--gold);
  font-size: clamp(13px, 3vw, 15px);
  font-weight: 400;
}
.btn-blue {
  padding: 12px 40px;
  background: linear-gradient(180deg, var(--blue-comp), #1D4ED8);
  border: none;
  color: white;
  font-size: clamp(14px, 3.5vw, 17px);
  border-radius: 12px;
}
.btn-text {
  background: none;
  border: none;
  color: var(--text-light);
  opacity: 0.5;
  font-size: clamp(11px, 2.5vw, 13px);
  font-weight: 400;
  padding: 8px 16px;
}
.btn-sm { min-height: 40px; padding: 8px 24px; font-size: 13px; }

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 15;
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 8px clamp(8px, 3vw, 16px);
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(26,15,10,0.95) 0%, rgba(45,27,18,0.8) 100%);
  border-bottom: 2px solid rgba(200,169,81,0.2);
  gap: 8px;
}
#hud.active { display: flex; }
.hud-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: clamp(12px, 3vw, 15px);
  font-weight: 700;
  white-space: nowrap;
}
.hud-item span { font-weight: 900; }
.hud-time span { color: #F87171; }
.hud-level span { color: #93C5FD; }
.hud-target span { color: var(--gold-bright); }
.hud-score span { color: #FCD34D; }
.hud-btn {
  background: rgba(200,169,81,0.15);
  border: 2px solid rgba(200,169,81,0.35);
  color: var(--gold-bright);
  border-radius: 10px;
  width: 44px; height: 44px;
  font-size: 22px;
  cursor: pointer;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hud-btn:active { background: rgba(200,169,81,0.3); transform: scale(0.93); }

/* ===== 道具栏 ===== */
#itemBar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 15;
  display: none;
  justify-content: center;
  gap: clamp(8px, 2vw, 14px);
  padding: 8px 16px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(26,15,10,0.95) 0%, rgba(45,27,18,0.8) 100%);
  border-top: 2px solid rgba(200,169,81,0.2);
}
#itemBar.active { display: flex; }
.powerup-slot {
  width: clamp(40px, 10vw, 50px);
  height: clamp(40px, 10vw, 50px);
  background: var(--bg-panel);
  border: 2px solid rgba(200,169,81,0.2);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
  transition: border-color 0.15s, transform 0.15s;
}
.powerup-slot:active { transform: scale(0.93); }
.powerup-slot.active-powerup { border-color: var(--blue-comp); box-shadow: 0 0 12px rgba(37,99,235,0.4); }
.powerup-slot.empty { opacity: 0.35; pointer-events: none; }
.pu-icon { font-size: clamp(18px, 5vw, 24px); }
.pu-count {
  position: absolute;
  bottom: 0; right: -2px;
  font-size: 11px;
  font-weight: 700;
  background: var(--gold);
  color: var(--bg-deep);
  border-radius: 6px;
  padding: 0 5px;
}

/* ===== 弹窗 ===== */
.modal {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(26,15,10,0.92);
  padding: 20px;
}
.modal.active { display: flex; }
.modal-box {
  background: var(--bg-panel);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 28px);
  width: 90%;
  max-width: 320px;
  border: 2px solid rgba(200,169,81,0.2);
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.modal-box h3 { color: var(--gold-bright); font-size: clamp(16px, 4vw, 19px); }
.modal-box h2 { color: var(--gold-bright); font-size: clamp(18px, 5vw, 24px); }
.modal-box .btn { width: 100%; }

/* ===== 规则弹窗 ===== */
.rules-box { align-items: stretch; max-height: 80vh; overflow-y: auto; }
.rules-box h3 { align-self: center; }
.rules-list { text-align: left; font-size: clamp(12px, 3vw, 14px); }
.rule {
  display: flex; gap: 8px;
  padding: 6px 0;
  align-items: flex-start;
  line-height: 1.5;
}
.rule span { flex: 1; color: var(--text-light); opacity: 0.85; }
.rule.divider {
  height: 1px;
  background: rgba(200,169,81,0.1);
  margin: 4px 0;
  padding: 0;
}

/* ===== 商店 ===== */
#shopScreen { z-index: 20; }
.shop-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, #3D2B1E 0%, #2D1B12 50%, #1A0F0A 100%);
}
.shop-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 16px);
  width: 90%;
  max-width: 360px;
  padding: clamp(12px, 3vh, 24px) 0;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.shop-content h2 {
  color: var(--gold-bright);
  font-size: clamp(18px, 5vw, 24px);
  letter-spacing: 2px;
}
.shop-content > p { font-size: 13px; opacity: 0.6; }
.shop-balance {
  padding: 10px 24px;
  background: rgba(0,0,0,0.3);
  border-radius: 20px;
  border: 1px solid rgba(200,169,81,0.2);
  font-size: 16px;
  color: var(--gold-bright);
}
.shop-balance strong { color: #FCD34D; }
.shop-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.shop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-panel);
  border-radius: 12px;
  border: 1px solid rgba(200,169,81,0.12);
}
.shop-card .sc-icon {
  width: 42px; height: 42px;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.shop-card .sc-info { flex: 1; min-width: 0; }
.shop-card .sc-name { font-size: 14px; font-weight: 700; }
.shop-card .sc-desc { font-size: 11px; opacity: 0.5; margin-top: 2px; }
.shop-card .sc-price { font-size: 14px; font-weight: 700; color: var(--gold-bright); white-space: nowrap; }
.shop-card .sc-btn {
  padding: 8px 18px;
  background: linear-gradient(180deg, #C8A951, #A8883A);
  border: none;
  border-radius: 8px;
  color: var(--bg-deep);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
}
.shop-card.sold-out { opacity: 0.5; }
.shop-card.sold-out .sc-btn { background: #555; color: #999; pointer-events: none; }

/* ===== 结算 ===== */
.result-icon { font-size: 48px; }
.result-score {
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 2px 12px rgba(245,197,66,0.4);
}
.result-detail {
  font-size: 12px;
  opacity: 0.55;
  line-height: 1.8;
}

/* ===== 排行榜 ===== */
.lb-box { align-items: stretch; }
.lb-list { max-height: 40vh; overflow-y: auto; }
.lb-row {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 2px;
}
.lb-row.me { background: rgba(200,169,81,0.1); border: 1px solid rgba(200,169,81,0.15); }
.lb-rank { width: 24px; text-align: center; font-weight: 700; flex-shrink: 0; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--gold-bright); flex-shrink: 0; }
.lb-rank.gold { color: #FFD700; }
.lb-rank.silver { color: #C0C0C0; }
.lb-rank.bronze { color: #CD7F32; }

/* ===== 知识彩蛋 ===== */
#knowledgePopup {
  position: absolute;
  z-index: 20;
  left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  display: none;
  pointer-events: none;
}
#knowledgePopup.show {
  display: block;
  animation: kpFade 3s ease-in-out forwards;
}
@keyframes kpFade {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(0.9); }
}
.knowledge-card {
  background: var(--bg-panel);
  border: 2px solid rgba(37,99,235,0.4);
  border-radius: 14px;
  padding: 16px 20px;
  text-align: center;
  max-width: 260px;
  box-shadow: 0 0 30px rgba(37,99,235,0.12);
}
.knowledge-icon { font-size: 28px; margin-bottom: 6px; }
.knowledge-label { font-size: 11px; color: var(--blue-comp); font-weight: 700; margin-bottom: 6px; }
.knowledge-text { font-size: 12px; color: var(--text-light); line-height: 1.7; }

/* ===== 输入框 ===== */
.input-nickname {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-cave);
  border: 2px solid rgba(200,169,81,0.2);
  border-radius: 10px;
  color: var(--text-light);
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  outline: none;
}
.input-nickname:focus { border-color: var(--gold); }
.input-nickname::placeholder { color: rgba(232,213,183,0.3); }

/* ===== 关卡通知 ===== */
#levelNotify {
  position: absolute;
  z-index: 18;
  left: 50%; top: 18%;
  transform: translate(-50%, -50%);
  display: none;
  pointer-events: none;
}
#levelNotify.show {
  display: block;
  animation: lnShow 2s ease-out forwards;
}
@keyframes lnShow {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -65%) scale(0.9); }
}
.level-notify-text {
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 20px rgba(245,197,66,0.6), 0 2px 8px rgba(0,0,0,0.5);
  letter-spacing: 4px;
  white-space: nowrap;
}
