/* ==========================================================================
   Q-Runner 样式表 —— 卡通轻量风
   ========================================================================== */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #bfe8ff;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none; /* 禁止移动端下拉刷新/回弹 */
}

/* 画布铺满全屏，禁用触摸默认行为 */
#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ------------------------------ HUD ------------------------------ */

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
}

.hud-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid rgba(60, 90, 60, 0.25);
  border-radius: 12px;
  padding: 6px 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.hud-label {
  font-size: 13px;
  color: #556b4f;
  font-weight: 600;
}

.hud-value {
  font-size: 20px;
  font-weight: 800;
  color: #2f4f2f;
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --------------------------- 全屏遮罩层 --------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 40, 60, 0.35);
  backdrop-filter: blur(3px);
}

.panel {
  background: #fffdf6;
  border-radius: 22px;
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.18), 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: min(92vw, 420px);
}

.game-title {
  font-size: 44px;
  letter-spacing: 3px;
  color: #2f8f4e;
  text-shadow: 0 3px 0 #1c5c31;
  margin-bottom: 4px;
}

.subtitle {
  color: #7a8a72;
  font-size: 15px;
  margin-bottom: 22px;
  letter-spacing: 2px;
}

.controls-help {
  background: #f2f7ee;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 24px;
}

.controls-help p {
  font-size: 14px;
  color: #4a5a44;
  line-height: 1.9;
}

.controls-help b {
  color: #2f8f4e;
}

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  background: #37a85a;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 13px 44px;
  border-radius: 999px;
  box-shadow: 0 5px 0 #247a3e;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  font-family: inherit;
}

.btn:hover { transform: translateY(-1px); }

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #247a3e;
}

.hint {
  margin-top: 14px;
  font-size: 12px;
  color: #9aa793;
}

/* --------------------------- 剧情卡 --------------------------- */

.story-card {
  background: #fbf3df;
  border: 1px dashed #d8c48e;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  text-align: left;
}

.story-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #a3822e;
  margin-bottom: 5px;
}

.story-text {
  font-size: 12.5px;
  line-height: 1.8;
  color: #7c6a3c;
  text-align: justify;
}

/* --------------------------- 难度选择 --------------------------- */

.difficulty-row {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
}

.diff-btn {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px;
  border-radius: 12px;
  border: 2px solid #cfdcc8;
  background: #ffffff;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.diff-btn:hover { transform: translateY(-1px); }

.diff-btn.active {
  background: #37a85a;
  border-color: #2f8f4e;
  box-shadow: 0 4px 0 #247a3e;
}

.diff-name {
  font-size: 15px;
  font-weight: 800;
  color: #4a5a44;
}

.diff-btn.active .diff-name { color: #ffffff; }

.diff-desc {
  font-size: 10.5px;
  line-height: 1.3;
  color: #93a38c;
  text-align: center;
}

.diff-btn.active .diff-desc { color: rgba(255, 255, 255, 0.9); }

/* 手机竖屏：压缩面板与字号，保证三颗胶囊一行且不挡按钮 */
@media (max-width: 480px) {
  .panel { padding: 24px 20px; }
  .game-title { font-size: 32px; }
  .difficulty-row { gap: 6px; }
  .diff-name { font-size: 14px; }
  .diff-desc { font-size: 9.5px; }
  .btn { padding: 12px 34px; font-size: 17px; }
}

/* --------------------------- 游戏结束 --------------------------- */

.game-over-title {
  font-size: 34px;
  color: #d84a3a;
  text-shadow: 0 3px 0 #8f2a1e;
  margin-bottom: 18px;
}

.final-line {
  font-size: 17px;
  color: #4a5a44;
  margin: 6px 0;
}

.final-line span {
  font-weight: 800;
  color: #2f4f2f;
  font-variant-numeric: tabular-nums;
}

.new-best {
  margin: 12px 0 2px;
  font-size: 18px;
  font-weight: 800;
  color: #e8a020;
  animation: pop 0.5s ease infinite alternate;
}

@keyframes pop {
  from { transform: scale(1); }
  to   { transform: scale(1.12); }
}

/* ----------------------------- 加载中 ----------------------------- */

.loading-box {
  text-align: center;
  color: #fff;
}

.loading-box p {
  margin-top: 16px;
  font-size: 15px;
  letter-spacing: 1px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffd24a;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   CG 演出层（开局亮相 / 死亡战败）
   —— 压暗、暗角、字幕全部纯 CSS，opacity 由 main.js 逐帧 damp 写入
   ========================================================================== */

/* 压暗层：纯色盖在画布上 */
#cg-dark,
#cg-vignette {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none; /* 绝不能拦截「开始奔跑」「重新开始」等按钮 */
  will-change: opacity;
}

#cg-dark {
  z-index: 12;
  background: #05080c;
}

/* 暗角层：径向渐变遮罩（中间透、四周黑） */
#cg-vignette {
  z-index: 13;
  background: radial-gradient(
    ellipse 78% 78% at 50% 45%,
    rgba(0, 0, 0, 0) 30%,
    rgba(0, 0, 0, 0.42) 66%,
    rgba(0, 0, 0, 0.9) 100%
  );
}

/* CG 字幕：绝对定位 + 淡入淡出，不参与布局、不挡点击 */
#cg-subtitle {
  position: fixed;
  left: 50%;
  bottom: 24%;
  z-index: 15;
  width: max-content;
  max-width: 88vw;
  padding: 0 16px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.6);
}

#cg-subtitle.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

#cg-subtitle p {
  color: #ffffff;
  font-weight: 600;
  line-height: 1.85;
  letter-spacing: 4px;
  font-size: 14.5px;
}

#cg-sub-line1 {
  font-size: 18px;
  letter-spacing: 6px;
  margin-bottom: 2px;
}

/* 面板淡入（开局亮相结束后、战败定格结束后） */
@keyframes cgFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay.fade-in {
  animation: cgFadeIn 0.55s ease both;
}

/* HUD 在 CG 期间压暗（opacity 由 main.js 写入） */
#hud {
  transition: opacity 0.35s ease;
}

@media (max-width: 480px) {
  #cg-subtitle { bottom: 26%; }
  #cg-sub-line1 { font-size: 16px; letter-spacing: 4px; }
  #cg-subtitle p { font-size: 13px; letter-spacing: 2px; }
}
