/* style.css —— 深紫夜空 + 糖果浮雕方块（按 UI 规格书实测参数复刻）
   方块与星星全部由 Canvas 绘制；本文件只负责页面背景与 HUD。 */

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  /* 规格书实测：顶部 #332846 → 下方 #2C2042 的向下渐变 */
  background: linear-gradient(180deg, #332846 0%, #2f2644 45%, #2c2042 100%);
  color: #fff;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  /* 连点消除很密集:双击缩放交给 touch-action 拦,不禁用户缩放(无障碍) */
  touch-action: manipulation;
}

/* 夜空星点（细小白色光点） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .85;
  background-image:
    radial-gradient(1.6px 1.6px at 8% 12%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 16% 34%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(2px 2px at 24% 8%, #ffe9c4 50%, rgba(255,233,196,0) 51%),
    radial-gradient(1.4px 1.4px at 33% 26%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 42% 14%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.8px 1.8px at 55% 6%, #d6c4ff 50%, rgba(214,196,255,0) 51%),
    radial-gradient(1.4px 1.4px at 63% 30%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 71% 16%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(2px 2px at 80% 9%, #ffe9c4 50%, rgba(255,233,196,0) 51%),
    radial-gradient(1.4px 1.4px at 89% 22%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 95% 40%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.6px 1.6px at 12% 60%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 20% 78%, #d6c4ff 50%, rgba(214,196,255,0) 51%),
    radial-gradient(1.8px 1.8px at 4% 44%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.4px 1.4px at 48% 52%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 52% 76%, #ffe9c4 50%, rgba(255,233,196,0) 51%),
    radial-gradient(1.6px 1.6px at 60% 64%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.4px 1.4px at 68% 88%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 76% 56%, #d6c4ff 50%, rgba(214,196,255,0) 51%),
    radial-gradient(1.8px 1.8px at 84% 70%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.4px 1.4px at 92% 86%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.2px 1.2px at 96% 58%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.6px 1.6px at 40% 92%, #ffe9c4 50%, rgba(255,233,196,0) 51%),
    radial-gradient(1.2px 1.2px at 28% 48%, #fff 50%, rgba(255,255,255,0) 51%),
    radial-gradient(1.4px 1.4px at 36% 68%, #fff 50%, rgba(255,255,255,0) 51%);
}

.app {
  position: relative;
  width: min(96vw, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  user-select: none;
}

/* ---------- 顶部 HUD ---------- */

.hud {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* 左上：关卡 / 目标 一行白色粗体（正版同款排布） */
.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 26px;
}

.lv-line {
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  line-height: 1.45;
  text-align: left;
  text-shadow: 0 2px 3px rgba(0, 0, 0, .55);
  letter-spacing: .5px;
}

.lv-line b {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.lv-line .sep { display: inline-block; width: 14px; }

/* 右上：连消表 —— 金色星 + 橙色倒计时条 + "N+"（正版同款） */
.chainbar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chain-star {
  color: #ffd166;
  font-size: 17px;
  line-height: 1;
  text-shadow: 0 0 8px rgba(255, 209, 102, .65), 0 1px 2px rgba(0, 0, 0, .6);
}
.chain-track {
  position: relative;
  width: 96px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #4a3d6e, #372a58);
  border: 1px solid rgba(255, 255, 255, .22);
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.chain-track i {
  position: absolute;
  inset: 2px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffc94d, #f09a1e);
  transform-origin: left center;
  transform: scaleX(1);
}
.chain-track em {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  font-family: ui-monospace, Consolas, monospace;
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}

.row-mid {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
}

/* 正中：当前得分 —— 大号金色圆体（正版同款），全屏第一视觉焦点 */
.score {
  font-size: 46px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  font-family: "Arial Rounded MT Bold", "Comic Sans MS", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #fff3b0 0%, #ffd166 48%, #f09a1e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(60, 30, 0, .55)) drop-shadow(0 4px 10px rgba(0, 0, 0, .35));
}

/* 中左：暂停键 —— 两道白色竖条，极淡底 */
.pause {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, .08);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
}

.pause i {
  display: block;
  width: 4px;
  height: 15px;
  border-radius: 2px;
  background: #fff;
}

/* 中右：道具圆钮（正版同款：炸弹 / 刷新 / 锤子），带剩余次数角标 */
.props {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 7px;
}
.prop {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22);
  background: radial-gradient(circle at 35% 30%, #6a5b9e, #43356b 60%, #322549);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.prop svg { width: 22px; height: 22px; }
.prop .cnt {
  position: absolute;
  left: -3px; bottom: -3px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: #f09a1e;
  color: #fff;
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  padding: 0 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.prop.armed { border-color: #ffd166; box-shadow: 0 0 0 2px rgba(255, 209, 102, .55), 0 3px 10px rgba(0, 0, 0, .5); transform: translateY(-2px); }
.prop.empty { opacity: .38; }
.prop.empty .cnt { background: #5a5470; }

/* ---------- 进度条 ---------- */

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .16);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(180deg, #eaff5a, #7ed321);
  transition: width .25s ease-out;
}

/* ---------- 棋盘 ---------- */

.stage {
  position: relative;
  width: min(100%, 64vh);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: block;
  touch-action: manipulation;
}

/* ---------- 过关庆祝提示（短暂显示后自动进下一关）---------- */

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 30px;
  border-radius: 20px;
  background: rgba(24, 14, 46, .82);
  border: 2px solid rgba(255, 255, 255, .18);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease, transform .28s cubic-bezier(.2, 1.4, .4, 1);
  z-index: 8;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.toast b {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #8ff0a4;
  text-shadow: 0 2px 0 rgba(20, 100, 50, .9), 0 4px 12px rgba(0, 0, 0, .5);
}

.toast span {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, .8);
}

/* ---------- 弹窗 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 14, 38, .66);
  backdrop-filter: blur(2px);
  z-index: 50;
}

.overlay.active { display: flex; }

.panel {
  width: 88%;
  max-width: 360px;
  padding: 22px 18px 18px;
  text-align: center;
  border-radius: 22px;
  background: linear-gradient(180deg, #3a2b5e, #2a1d47);
  border: 3px solid rgba(255, 255, 255, .14);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
  animation: pop .28s ease-out;
}

@keyframes pop {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.panel h2 {
  font-size: 25px;
  letter-spacing: 2px;
  color: #eaff5a;
  text-shadow: 0 3px 0 rgba(60, 90, 10, .8), 0 4px 12px rgba(0, 0, 0, .45);
}

.overlay[data-kind="win"]  .panel h2 { color: #8ff0a4; text-shadow: 0 3px 0 rgba(20, 100, 50, .8), 0 4px 12px rgba(0, 0, 0, .45); }
.overlay[data-kind="lose"] .panel h2 { color: #ff8a8a; text-shadow: 0 3px 0 rgba(140, 30, 30, .8), 0 4px 12px rgba(0, 0, 0, .45); }

.panel p {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, .72);
  line-height: 1.6;
}

.stats {
  margin: 14px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 7px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .12);
  font-size: 13px;
  color: rgba(255, 255, 255, .72);
}

.stat b {
  font-size: 17px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, .45);
}

/* ---------- 按钮 ---------- */

button {
  font-family: inherit;
  cursor: pointer;
  transition: transform .1s ease, filter .12s ease;
}

button:active { transform: translateY(2px); filter: brightness(.96); }

button.primary {
  width: 100%;
  padding: 13px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd166, #ee7c12);
  box-shadow: 0 5px 0 #a8570a, 0 8px 16px rgba(0, 0, 0, .4);
  text-shadow: 0 2px 0 rgba(150, 70, 10, .35);
}

button.ghost {
  display: none;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, .85);
  border: 2px solid rgba(255, 255, 255, .25);
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
}

button.ghost.show { display: block; }

.tbtn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
}

.tbtn.off { opacity: .55; }

.toolbar { display: flex; gap: 10px; }

/* ---------- 小屏适配 ---------- */

@media (max-width: 420px) {
  .info { font-size: 12px; }
  .score { font-size: 34px; }
  .panel h2 { font-size: 22px; }
  .pause { width: 32px; height: 32px; }
}
