/* ===== 共享主题样式 · 卡通儿童风 ===== */
@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Fredoka:wght@500;600;700&display=swap');

:root {
  /* 糖果色系 */
  --bg: #fff6e5;
  --bg2: #ffe9f0;
  --panel: #ffffff;
  --panel-light: #fff3d6;
  --text: #5a4a7a;
  --text-dim: #a695c0;
  --accent: #ff7eb6;   /* 糖果粉 */
  --accent2: #4ecdc4;  /* 薄荷绿 */
  --accent3: #ffd93d;  /* 柠檬黄 */
  --purple: #a98eff;   /* 葡萄紫 */
  --orange: #ff9f68;   /* 蜜桃橙 */
  --blue: #5fb8ff;     /* 天空蓝 */
  --good: #6ddf6d;
  --warn: #ffb454;
  /* 卡通：粗边框 + 柔和彩色阴影 */
  --border: 4px solid #ffffff;
  --line: #ffe0ec;
  --shadow: 0 8px 0 rgba(255,126,182,.25), 0 14px 30px rgba(169,142,255,.18);
  --shadow-sm: 0 5px 0 rgba(169,142,255,.22);
  --radius: 28px;
  --radius-sm: 20px;
}

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

html, body { height: 100%; }

body {
  font-family: "Baloo 2", "Fredoka", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 10% -5%, rgba(255,217,61,.35), transparent 55%),
    radial-gradient(800px 460px at 100% 0%, rgba(78,205,196,.3), transparent 55%),
    radial-gradient(700px 500px at 50% 110%, rgba(255,126,182,.28), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 飘浮的卡通装饰点 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.9) 20%, transparent 22%),
    radial-gradient(circle, rgba(255,217,61,.5) 20%, transparent 22%);
  background-size: 90px 90px, 140px 140px;
  background-position: 0 0, 45px 60px;
  opacity: .35;
  z-index: 0;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 18px 60px;
  position: relative;
  z-index: 1;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.topbar .title { display: flex; align-items: center; gap: 12px; }
.topbar h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(169,142,255,.25);
}
.topbar .sub { color: var(--text-dim); font-size: 13px; }

.btn {
  appearance: none;
  border: var(--border);
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  background: var(--purple);
  padding: 11px 20px;
  border-radius: 999px;
  transition: transform .14s cubic-bezier(.34,1.56,.64,1), box-shadow .15s ease, filter .2s;
  box-shadow: var(--shadow-sm);
  user-select: none;
}
.btn:hover { transform: translateY(-3px) rotate(-1deg); filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(.95); box-shadow: 0 2px 0 rgba(169,142,255,.22); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff5fa0); }
.btn.ghost { background: var(--accent2); }
.btn.icon { padding: 11px 15px; font-size: 20px; background: var(--accent3); color: var(--text); }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ===== 计分卡片 ===== */
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  background: var(--panel);
  border: var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  min-width: 96px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat .label {
  font-size: 12px;
  letter-spacing: .5px;
  font-weight: 700;
  color: var(--text-dim);
}
.stat .value {
  font-size: 26px;
  font-weight: 800;
  margin-top: 2px;
  color: var(--purple);
}

/* ===== 游戏面板容器 ===== */
.board-wrap {
  background: var(--panel);
  border: 5px solid #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-top: 18px;
  position: relative;
  overflow: hidden;
}

/* ===== 覆盖层（胜利/失败）===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,246,229,.92);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
  z-index: 20;
  border-radius: var(--radius);
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay .big {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 1px;
  animation: bounceIn .6s cubic-bezier(.34,1.56,.64,1);
}
.overlay .big.win { color: var(--good); text-shadow: 3px 3px 0 #fff; }
.overlay .big.lose { color: var(--accent); text-shadow: 3px 3px 0 #fff; }
.overlay .msg { color: var(--text-dim); font-weight: 700; font-size: 16px; }

/* ===== 关卡/难度选择条 ===== */
.levels { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.level-chip {
  cursor: pointer;
  user-select: none;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  color: var(--text-dim);
  background: var(--panel);
  border: 3px solid var(--line);
  transition: transform .14s cubic-bezier(.34,1.56,.64,1), all .18s ease;
}
.level-chip:hover { color: var(--text); transform: translateY(-2px) rotate(-2deg); }
.level-chip.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent2), #35b5ac);
  border-color: #fff;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--purple);
  margin: 20px 0 10px;
}
.section-title::before { content: "⭐ "; }

/* ===== Toast 提示 ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: var(--purple);
  color: #fff;
  padding: 14px 24px;
  border: 4px solid #fff;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all .3s cubic-bezier(.34,1.56,.64,1);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hint {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  margin-top: 16px;
  line-height: 1.7;
  background: var(--panel-light);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 3px dashed #ffd98c;
}
.hint kbd {
  background: #fff;
  color: var(--purple);
  padding: 3px 9px;
  border-radius: 8px;
  font-family: "Baloo 2", monospace;
  font-weight: 800;
  font-size: 13px;
  border: 2px solid var(--purple);
  box-shadow: 0 2px 0 var(--purple);
}
.hint b { color: var(--accent); }

/* ===== 卡通动画关键帧 ===== */
@keyframes pop {
  0% { transform: scale(0) rotate(-12deg); }
  60% { transform: scale(1.18) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes merge-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.25) rotate(-4deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes shake {
  0%,100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-7px) rotate(-3deg); }
  75% { transform: translateX(7px) rotate(3deg); }
}
.shake { animation: shake .35s ease; }
@keyframes bounceIn {
  0% { transform: scale(0) translateY(40px); opacity: 0; }
  60% { transform: scale(1.15) translateY(-8px); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}
@keyframes wobble {
  0%,100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}
@keyframes floaty {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ===== 手机端全局优化 ===== */
/* 防止长按选中、点击高亮闪烁、双击缩放手势 */
.btn, .level-chip, .numkey, .card, .ptile, .cell, .stat {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;  /* 禁用双击缩放，但保留单击/滚动 */
}
/* 安全区边距（刘海屏 / 底部手势条） */
.wrap {
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-bottom: max(60px, env(safe-area-inset-bottom));
}
/* 游戏盘内禁止触摸时的页面橡皮筋滚动（各游戏盘自身仍可接收手势） */
.board-wrap { overscroll-behavior: contain; }

@media (max-width: 520px) {
  .wrap { padding-top: 16px; }
  .topbar { margin-bottom: 16px; }
  .topbar h1 { font-size: 22px; }
  .stats { gap: 8px; }
  .stat { min-width: 0; flex: 1 1 auto; padding: 9px 10px; }
  .stat .label { font-size: 11px; }
  .stat .value { font-size: 20px; }
  .btn { font-size: 14px; padding: 10px 16px; }
  /* 触摸点最小 44px（含边框），方便儿童手指点击 */
  .btn, .level-chip { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn.icon { min-width: 44px; }
  .board-wrap { padding: 12px; }
  .hint { font-size: 13px; padding: 12px 14px; }
  .section-title { margin: 16px 0 8px; }
  .overlay .big { font-size: 32px; }
  .toolbar { gap: 10px; }
}

/* 超窄屏（iPhone SE 等 ≤360px） */
@media (max-width: 360px) {
  .wrap { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar h1 { font-size: 20px; }
  .btn { font-size: 13px; padding: 9px 13px; }
  .board-wrap { padding: 10px; }
}

/* 横屏矮高度：压缩纵向留白，避免盘面被挤出屏幕 */
@media (max-height: 520px) and (orientation: landscape) {
  .wrap { padding-top: 10px; padding-bottom: 20px; }
  .topbar { margin-bottom: 10px; }
  .section-title { margin: 10px 0 6px; }
  .hint { display: none; }  /* 横屏空间紧张时隐藏提示文字 */
}
