/* =============================================================================
 * style.css —— 页面外壳、HUD、响应式布局、提示条、通关浮层
 * 说明：图片本身（两个对比视区）全部画在 canvas 上，这里只负责「画布外」的东西。
 * ============================================================================= */

/* ---------- 1. 主题变量：想换配色基本只改这里 ---------- */
:root {
  --bg: #0f1220;
  --bg-soft: #171b2e;
  --fg: #e8eaf6;
  --fg-dim: rgba(232, 234, 246, 0.6);
  --line: rgba(255, 255, 255, 0.12);
  --ok: #34d399;
  --bad: #fb7185;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

/* 手机浏览器的地址栏会缩起来，用 dvh 才能拿到真实的可用高度（不支持的浏览器自动退回 100%） */
@supports (height: 100dvh) {
  body { height: 100dvh; }
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 500 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 手机上不要让整页跟着手指滚 / 回弹，否则点击会变成滚动 */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* ---------- 2. 顶部 HUD ---------- */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
}

.hud__brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.hud__hint {
  margin-left: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-dim);
}

.hud__stats {
  display: flex;
  gap: 2px;
  margin-left: auto;   /* 把统计推到右侧 */
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px;
  border-left: 1px solid var(--line);
}

.stat:first-child { border-left: 0; }

.stat__k {
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}

.stat__v {
  font-size: 17px;
  /* 数字等宽：秒数/分数变化时不会左右抖动 */
  font-variant-numeric: tabular-nums;
}

.stat__v b { font-weight: 700; }
.stat__v i { font-style: normal; color: var(--fg-dim); margin: 0 1px; }

/* ---------- 3. 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #222741;
  color: var(--fg);
  padding: 8px 14px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}

.btn:hover { background: #2a3050; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(180deg, #ff5c94, #e91e63);
  border-color: #ff7aa8;
  color: #fff;
}

.btn--primary:hover { background: linear-gradient(180deg, #ff6da0, #f0306f); }

/* ---------- 4. 画布舞台 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;      /* flex 子项允许收缩，否则 canvas 会把页面撑高 */
}

#board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  /* touch-action:none 是必须的：否则手机上按住拖动会滚页面，pointerdown 会被打断 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;  /* 桌面端提示「这里可以点」 */
}

/* ---------- 5. 命中/失误提示条 ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  background: rgba(23, 27, 46, 0.94);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  opacity: 0;
  pointer-events: none;                 /* 别挡住点击 */
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.toast--ok   { color: var(--ok);  border-color: rgba(52, 211, 153, 0.45); }
.toast--bad  { color: var(--bad); border-color: rgba(251, 113, 133, 0.45); }
.toast--info { color: var(--fg); }

/* ---------- 6. 通关浮层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 10, 20, 0.74);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

/* 注意：display:grid 会覆盖 [hidden] 的默认 display:none，必须显式关掉 */
.overlay[hidden] { display: none; }

.overlay__card {
  width: min(340px, 100%);
  padding: 22px 20px 20px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #1b2036, #141827);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.overlay__title { margin: 0 0 10px; font-size: 22px; }
.overlay__line  { margin: 0 0 6px; font-size: 14px; color: var(--fg-dim); }

.overlay__score {
  margin: 10px 0 4px;
  font-size: 40px;
  font-weight: 800;
  color: #ffd166;
  font-variant-numeric: tabular-nums;
}

.overlay__score span {
  margin-left: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-dim);
}

.overlay__detail {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--fg-dim);
}

/* ---------- 7. 窄屏（手机竖屏）微调 ---------- */
@media (max-width: 560px) {
  .hud { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .hud__brand { font-size: 15px; }
  .hud__hint { display: none; }      /* 太挤就不显示提示文案 */
  .stat { padding: 0 8px; }
  .stat__v { font-size: 15px; }
  .btn { padding: 7px 10px; font-size: 13px; }
}

/* 极窄屏（小屏手机横屏）：HUD 进一步压缩，把高度让给画面 */
@media (max-height: 420px) {
  .hud { padding-top: 6px; padding-bottom: 6px; }
  .stat__k { display: none; }
  .overlay__score { font-size: 32px; }
}

/* 尊重系统的「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
  .toast, .btn { transition: none; }
}

/* ---------- 8. 选关首页（#menu）与关卡网格 ---------- */
/* 5 列 × 4 行：20 关正好铺满一屏（以后关卡变多会自动换行）。
   卡片默认 340px 太窄，选关页单独放宽到 440px，格子里才放得下数字和角标。 */
#menu .overlay__card { width: min(440px, 100%); }

.menu__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0 12px;
}

/* 一个关卡格子：正方形（aspect-ratio 保证数字永远居中），最小 44px 保证手指能点 */
.lv {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #222741;
  color: var(--fg);
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}

.lv:hover { background: #2a3050; }
.lv:active { transform: translateY(1px); }

/* 已通关：绿色数字 + 右上角小勾 */
.lv--cleared { color: var(--ok); border-color: rgba(52, 211, 153, 0.45); }
.lv--cleared::after {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 5px;
  font-size: 11px;
}

/* 未解锁：灰底灰字 + 右上角锁。
   ⚠️ 注意这里【没有】pointer-events:none 也没有 disabled —— 格子必须能点开解锁弹窗 */
.lv--locked {
  background: #1a1f36;
  border-color: rgba(255, 255, 255, 0.06);
  color: var(--fg-dim);
}
.lv--locked::after {
  content: '🔒';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
}

/* 已解锁未通关：就是 .lv 的默认样子，只显示编号 */

.menu__alt {
  width: 100%;
  font-size: 12px;
}

/* 幽灵按钮：次要操作（返回选关 / 程序生成模式入口） */
.btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
}

.btn--ghost:hover { color: var(--fg); }

/* 通关浮层：重玩 / 下一关 一行两个按钮 */
.overlay__btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.overlay__btns .btn { flex: 1; }

.overlay__home {
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  font-size: 13px;
}

/* ---------- 9. 音效开关按钮（HUD 左侧的喇叭图标） ---------- */
.btn--icon {
  flex: 0 0 auto;
  padding: 6px 9px;
  font-size: 15px;
  line-height: 1;
}

/* 静音状态：变暗，一眼能看出现在是关着的 */
.btn--icon.is-off {
  background: #1a1f36;
  color: var(--fg-dim);
}

/* ---------- 10. 窄屏保护：HUD 多了喇叭按钮后，别把右侧按钮挤出屏幕 ---------- */
/* flex 子项默认不会缩到比内容更窄（品牌文字是 nowrap），这里显式允许它收缩并省略 */
@media (max-width: 560px) {
  .hud__brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .btn--icon { padding: 5px 8px; font-size: 14px; }
}

/* 小屏手机上品牌文字直接不显示（选关浮层里还有标题，不缺这点信息） */
@media (max-width: 420px) {
  .hud__brand { display: none; }
}

/* ---------- 11. 提示按钮（游戏页右下角的浮动胶囊） ---------- */
.hint {
  position: absolute;
  right: 14px;
  /* 抬到 60px 是为了避开底部居中的 .toast（它在 bottom:14px、高约 34px） */
  bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 999px;
  background: rgba(23, 27, 46, 0.92);
  color: #ffd166;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
}

.hint:hover { background: rgba(40, 45, 70, 0.95); }
.hint:active { transform: translateY(1px); }
.hint[hidden] { display: none; }

/* 禁用态：没有可提示的了（全部找到 / 全部提示过） */
.hint:disabled {
  opacity: 0.45;
  cursor: default;
  color: var(--fg-dim);
  border-color: var(--line);
}

/* 本局还有免费的那一次：右上角挂一个「免费」小角标（纯装饰，不加 DOM） */
.hint.is-free::after {
  content: '免费';
  position: absolute;
  top: -8px;
  right: -6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--ok);
  color: #06231a;
  font-size: 10px;
  font-weight: 800;
}

@media (max-width: 560px) {
  .hint { right: 10px; bottom: calc(56px + env(safe-area-inset-bottom, 0px)); padding: 8px 12px; font-size: 13px; }
}

/* ---------- 12. 激励广告占位屏（#ad，由 js/ad.js 驱动） ---------- */
.overlay--ad { z-index: 5; }   /* 盖住提示按钮（z-index:2）与 toast */

.ad__badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 3px 10px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}

.ad__title { margin: 0 0 8px; font-size: 17px; font-weight: 700; }

.ad__count {
  margin: 4px 0 10px;
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  color: #ffd166;
  font-variant-numeric: tabular-nums;   /* 数字等宽，倒计时跳动时不抖 */
}

.ad__track {
  height: 6px;
  margin: 0 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.ad__bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, #ff9f1c);
  transition: width 0.2s linear;
}

.ad__line { margin: 0 0 16px; font-size: 12px; color: var(--fg-dim); }

.ad__skip { width: 100%; }

/* ---------- 13. 解锁弹窗（#lock：点了未解锁的关卡弹出来） ---------- */
.overlay--lock { z-index: 4; }   /* 压在选关页之上、广告占位屏（z-index:5）之下 */

.lock__title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
}

/* ---------- 14. 选关网格窄屏适配 ---------- */
/* 手机竖屏：5 列降成 4 列 —— 20 关一样一屏看全，但每格从 ~57px 涨到 ~73px，拇指点得准 */
@media (max-width: 560px) {
  #menu .overlay__card { padding: 18px 14px 16px; }
  .menu__grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .lv { font-size: 16px; border-radius: 10px; }
}


