* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-touch-callout: none;
}
body {
  background: #0b1120;
  color: #f8fafc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}
#game-header {
  width: 800px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 0 4px;
}
.game-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #fde047 0%, #ca8a04 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(234, 179, 8, 0.2);
}
.header-ctrls {
  display: flex;
  gap: 8px;
}
.ctrl-btn {
  background: #1e293b;
  border: 1px solid #475569;
  color: #cbd5e1;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}
.ctrl-btn:hover {
  background: #334155;
  color: #38bdf8;
  border-color: #38bdf8;
}
.btn-danger:hover {
  background: #450a0a;
  color: #f87171;
  border-color: #ef4444;
}

#game-container {
  position: relative;
  width: 800px;
  height: 600px;
  border: 3px solid #334155;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  background: #000;
  overflow: hidden;
  cursor: crosshair;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 52px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid #475569;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  font-size: 13px;
  font-weight: 700;
  z-index: 10;
}
.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hud-label { color: #94a3b8; font-size: 12px; }
.hud-value { font-family: "Courier New", monospace; font-size: 17px; }
.val-gold { color: #facc15; }
.val-time { color: #f87171; }
.val-target { color: #38bdf8; }
.val-level { color: #4ade80; }

/* 最后 10 秒：时间跳动告警 */
.val-time.is-urgent {
  color: #ef4444;
  transform: scale(1.18);
}
@media (prefers-reduced-motion: reduce) {
  .val-time.is-urgent { transform: none; }
}
.val-dynamite { color: #fb923c; }
.val-record { color: #a78bfa; }
.buff-tag {
  background: #854d0e;
  color: #fef08a;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.modal-box {
  background: #1e293b;
  border: 2px solid #38bdf8;
  border-radius: 16px;
  padding: 28px 40px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  max-width: 620px;
  width: 90%;
}
.modal-title { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.title-win { color: #facc15; }
.title-lose { color: #f87171; }
.modal-desc { color: #94a3b8; font-size: 14px; margin-bottom: 16px; line-height: 1.5; }

.shop-wallet {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #0f172a;
  border: 1px solid #eab308;
  padding: 6px 18px;
  border-radius: 20px;
  margin-bottom: 20px;
  color: #94a3b8;
  font-size: 13px;
}
.shop-wallet-amount {
  color: #facc15;
  font-family: "Courier New", monospace;
  font-size: 20px;
  font-weight: 800;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 10px 32px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover { background: #1d4ed8; transform: translateY(-2px); }

.shop-items {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 22px;
}
.shop-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 16px 12px;
  width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s;
}
.shop-card:hover { border-color: #38bdf8; }
.shop-icon { font-size: 30px; }
.shop-name { font-size: 13px; font-weight: 700; color: #f1f5f9; }
.shop-price { color: #facc15; font-family: monospace; font-weight: bold; font-size: 15px; }
.shop-desc { font-size: 11px; color: #64748b; min-height: 32px; line-height: 1.3; }
.shop-buy-btn {
  background: #10b981;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s;
}
.shop-buy-btn:disabled {
  background: #334155;
  color: #64748b;
  cursor: not-allowed;
  opacity: 0.7;
}

#footer-tip {
  margin-top: 12px;
  color: #64748b;
  font-size: 13px;
  display: flex;
  gap: 16px;
}
.key-tag {
  background: #1e293b;
  border: 1px solid #475569;
  padding: 2px 6px;
  border-radius: 4px;
  color: #cbd5e1;
  font-weight: bold;
}

/* 返回首页：复用控件按钮外观 */
a.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

/* 轻提示：替代阻塞式 alert，不打断主循环 */
.toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 10px);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #f8fafc;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 40;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 移动端：舞台等比缩放，画布内部坐标系始终 800×600 */
@media (max-width: 840px) {
  #game-header,
  #game-container {
    width: calc(100vw - 20px);
    max-width: 800px;
  }
  #game-container {
    height: auto;
    aspect-ratio: 4 / 3;
  }
  #footer-tip {
    flex-direction: column;
    gap: 6px;
    padding: 0 10px;
    text-align: center;
  }
}
@media (max-width: 560px) {
  .game-logo { font-size: 15px; }
  .ctrl-btn { padding: 4px 7px; font-size: 11px; }
  #back-label,
  #sound-label,
  #reset-label { display: none; }
  #hud { padding: 0 6px; }
  .hud-item { gap: 3px; }
  .hud-label { font-size: 9px; }
  .hud-value { font-size: 11px; }
  .buff-tag { font-size: 9px; padding: 1px 5px; }
  .shop-items { flex-wrap: wrap; gap: 10px; }
  .shop-card { width: 132px; padding: 12px 8px; }
  .modal-box { padding: 20px 16px; }
  .modal-title { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
