/* ============================================================
 *  数字连连消 - 样式
 * ============================================================ */

:root {
  --bg: #0f172a;
  --board-bg: #1e293b;
  --block-bg: #334155;
  --block-border: #475569;
  --block-hover: #64748b;
  --selected: #22d3ee;
  --selected-glow: rgba(34, 211, 238, 0.6);
  --path-color: #f59e0b;
  --target-color: #fbbf24;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --success: #22c55e;
  --error: #ef4444;
  --btn-primary: #3b82f6;
  --btn-hover: #2563eb;
  --radius: 12px;
  --block-radius: 10px;
  --gap: 4px;
  --block-size: clamp(42px, 8vw, 64px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  padding-bottom: 40px;
}

.game-header {
  width: 100%;
  max-width: 520px;
  text-align: center;
  margin-bottom: 12px;
}

.game-header h1 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 5vw, 2rem);
  background: linear-gradient(135deg, var(--selected), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: clamp(0.9rem, 3vw, 1.1rem);
}

.header-stats .stat span {
    color: var(--target-color);
    font-weight: 700;
    margin-left: 4px;
  }
}

.game-header {
  position: relative;
}

#pauseBtn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.2rem;
}

.game-main {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.board-wrap {
  position: relative;
  background: var(--board-bg);
  border-radius: var(--radius);
  padding: var(--gap);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 520px;
}

.board-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--radius) - 4px);
  background: #0f172a;
}

.overlay {
  position: absolute;
  inset: var(--gap);
  border-radius: calc(var(--radius) - 4px);
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  display: none;
  background: var(--block-bg);
  border: 1px solid var(--block-border);
  border-radius: var(--radius);
  padding: 24px 32px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 只有带 .show 的弹窗才显示。
   此前缺少这条规则，而 JS 是把 show 加在弹窗的父节点（遮罩）上，
   导致三个弹窗会同时出现在遮罩内互相叠放，按钮相互遮挡。 */
.modal.show {
  display: block;
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 { margin: 0 0 12px; font-size: 1.4rem; }
.modal p { margin: 0 0 20px; color: var(--text-dim); }
.modal .btn { min-width: 120px; }

.pause-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pause-menu .btn { width: 100%; }

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 520px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}

.btn.primary {
  background: var(--btn-primary);
  color: white;
}

.btn.primary:hover { background: var(--btn-hover); }
.btn.primary:active { transform: scale(0.97); }

.btn.secondary {
  background: var(--block-bg);
  color: var(--text);
  border: 1px solid var(--block-border);
}

.btn.secondary:hover { background: var(--block-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.help-text {
  margin: 8px 0 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  max-width: 520px;
  line-height: 1.5;
}

/* Block highlight animation */
@keyframes matchFlash {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

@keyframes fallDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.shake { animation: shake 0.3s ease; }
.falling { animation: fallDown 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); }
.matched { animation: matchFlash 0.4s ease-out; }

/* Responsive */
@media (max-width: 480px) {
  .header-stats { gap: 12px; font-size: 0.85rem; }
  .controls { gap: 8px; }
  .btn { padding: 8px 14px; font-size: 0.85rem; }
  .modal { padding: 20px 24px; }
}
/* 难度指示 */
.difficulty-stat {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.difficulty-stat #difficulty {
  color: var(--primary);
  font-weight: 600;
  margin-left: 2px;
}
@media (max-width: 520px) {
  .difficulty-stat { display: none; }
}

/* ---- 模式选择 ---- */
.mode-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  text-align: left;
  padding: 14px 18px;
  background: var(--block-bg);
  border: 1px solid var(--block-border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.mode-card:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
}
.mode-card:active { transform: scale(0.98); }
.mode-card strong { font-size: 1.05rem; }
.mode-card span {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ---- 顶栏模式 / 倒计时 ---- */
.mode-stat,
.timer-stat {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.mode-stat #mode { color: var(--primary); font-weight: 600; margin-left: 2px; }

.timer-stat { font-variant-numeric: tabular-nums; }
.timer-stat #timer {
  color: var(--success);
  font-weight: 700;
  font-size: 14px;
  margin-left: 2px;
}
.timer-stat #timer.warning { color: #f59e0b; }
.timer-stat #timer.urgent {
  color: var(--error);
  animation: timerPulse 0.7s ease-in-out infinite;
}
@keyframes timerPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(1.12); }
}

.timer-result {
  margin: -8px 0 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

@media (max-width: 520px) {
  .difficulty-stat { display: none; }
  .mode-stat, .timer-stat { font-size: 11px; }
  .timer-stat #timer { font-size: 13px; }
}

/* ---- 轻量提示 toast（替代阻塞式 alert）---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  max-width: min(88vw, 380px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: #f1f5f9;
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;   /* 不挡住棋盘点击 */
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
