/* ============================================================
   推箱子 — 样式（Chrome 61 基线，明快儿童友好配色）
   规范：
   - 无 flex gap / aspect-ratio / clamp() / 逻辑属性 / :has / dvh
   - 动画双写 @-webkit-keyframes + @keyframes；温和（<=400ms，无频闪）
   - flex 三重前缀（-webkit-box / -webkit-flex / flex）
   - 棋盘按关卡 w×h 自适应：padding-bottom = h/w*100%（正方形格子）
   - 安全区 env(safe-area-inset-*) 组合
   ============================================================ */

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f7f3ea;
  color: #4a453c;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--app-height, 100vh));
  overflow: hidden;
}

/* ---------- 三段式骨架 ---------- */

.app-header {
  padding-top: calc(6px + var(--safe-area-inset-top, 0px));
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
}

.ver-badge {
  display: block;
  padding-left: 16px;
  font-size: 11px;
  color: #b5ab97;
}

.app-main {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app-footer {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 auto;
  flex: 0 0 auto;
  padding: 6px 16px calc(8px + var(--safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 12px;
  color: #b5ab97;
}

.view {
  max-width: 480px;
  margin: 0 auto;
  padding: 6px 16px 20px;
  width: 100%;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: 12px;
  min-height: 40px;
}

.topbar .level-title {
  -webkit-box-flex: 1;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: #4a453c;
}

.topbar .best-num {
  font-size: 12px;
  color: #8f7a66;
  font-weight: 600;
  min-width: 64px;
  text-align: right;
}

.btn-ghost-sm {
  padding: 8px 14px;
  min-height: 36px;
  border: none;
  border-radius: 10px;
  background: #efe7d3;
  color: #6b6252;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost-sm:active { background: #e2d5c5; }

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

.board {
  position: relative;
  width: 100%;
  height: 0;
  background: #efe7d3;
  border-radius: 10px;
  padding-bottom: 100%; /* 由 JS 按关卡 w×h 覆盖 */
  touch-action: none;
}

.cell {
  position: absolute;
  border-radius: 3px;
}

/* 地板 */
.cell {
  background: #f7f2e4;
}

/* 墙（灰蓝 + 微立体） */
.cell.wall {
  background: #8d99a6;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.22),
              inset -2px -2px 0 rgba(0, 0, 0, 0.14);
  border-radius: 4px;
}

/* 目标点（黄圆） */
.cell.goal::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34%;
  height: 34%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #f9c74f;
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.18);
}

/* 箱子（木棕圆角块，垫在目标点上时不显示 ::after） */
.cell.box {
  background: #c97b4a;
  border-radius: 16%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16),
              inset 3px 0 0 rgba(255, 255, 255, 0.14);
}

/* 箱子在目标上（完成绿） */
.cell.boxgoal {
  background: #57a773;
  border-radius: 16%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16),
              inset 3px 0 0 rgba(255, 255, 255, 0.14);
}

/* 箱子遮盖目标点：box/boxgoal 时隐藏圆点 */
.cell.box::after, .cell.boxgoal::after { display: none; }

/* 玩家（蓝圆 + 双眼） */
.cell.player {
  background: #4a90d9;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.cell.player::before,
.cell.player::after {
  content: '';
  position: absolute;
  top: 28%;
  width: 12%;
  height: 12%;
  border-radius: 50%;
  background: #ffffff;
}

.cell.player::before { left: 26%; }
.cell.player::after { right: 26%; }

/* 玩家在目标上：圆点被玩家遮住，不显示 */
.cell.playergoal::after { display: none; }

/* ---------- 统计 ---------- */

.stats {
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  color: #6b6252;
}

.stats .stat-num {
  font-size: 16px;
  font-weight: 800;
  color: #e76f51;
}

/* ---------- 十字 D-pad ---------- */

.dpad {
  position: relative;
  width: 184px;
  height: 184px;
  margin: 12px auto 0;
}

.dpad-btn {
  position: absolute;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 12px;
  background: #bbada0;
  color: #ffffff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.dpad-btn:active { background: #9d8f82; }

.dpad-up    { left: 64px; top: 0; }
.dpad-left  { left: 0; top: 64px; }
.dpad-down  { left: 64px; top: 128px; }
.dpad-right { left: 128px; top: 64px; }

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

.btn-row {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-top: 14px;
}

.btn-main {
  padding: 12px 30px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: #8f7a66;
  color: #f9f6f2;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.btn-main:active { background: #776550; }

.btn-ghost {
  padding: 10px 22px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: #efe7d3;
  color: #6b6252;
  font-size: 16px;
  font-weight: 600;
  margin: 0 6px;
  cursor: pointer;
}

.btn-ghost:active { background: #e2d5c5; }

.hint {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: #b5ab97;
  line-height: 1.5;
}

.footer-checkin {
  color: #8f7a66;
  font-weight: 600;
}

/* ---------- 选关页 ---------- */

.pick-grid {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  margin-top: 6px;
}

.pick-btn {
  position: relative;
  width: 48px;
  height: 48px;
  margin: 4px;
  border: none;
  border-radius: 12px;
  background: #efe7d3;
  color: #4a453c;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.pick-btn:active { background: #e2d5c5; }

.pick-btn.locked {
  background: #d8d2c2;
  color: #b0a892;
  font-size: 19px;
}

.pick-btn .pick-stars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  font-size: 9px;
  letter-spacing: 0;
  color: #f2a33c;
}

.credit {
  text-align: center;
  margin-top: 16px;
  font-size: 11px;
  color: #b5ab97;
  line-height: 1.5;
}

/* ---------- 结算浮层 ---------- */

.overlay {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.68);
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  z-index: 50;
}

.overlay-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 26px 24px 24px;
  text-align: center;
  width: 84%;
  max-width: 340px;
  -webkit-animation: cardIn 0.25s ease;
  animation: cardIn 0.25s ease;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}

@-webkit-keyframes cardIn {
  0% { -webkit-transform: scale(0.92); transform: scale(0.92); opacity: 0; }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}
@keyframes cardIn {
  0% { -webkit-transform: scale(0.92); transform: scale(0.92); opacity: 0; }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}

.overlay-title {
  font-size: 26px;
  font-weight: 800;
  color: #4a453c;
}

.overlay-sub {
  margin-top: 6px;
  font-size: 14px;
  color: #8f8a80;
}

.summary {
  margin: 16px 0 18px;
}

.summary .stars-line {
  font-size: 34px;
  letter-spacing: 6px;
  color: #f2a33c;
  margin-bottom: 8px;
  -webkit-animation: starPop 0.35s ease;
  animation: starPop 0.35s ease;
}

@-webkit-keyframes starPop {
  0% { -webkit-transform: scale(0.4); transform: scale(0.4); opacity: 0; }
  60% { -webkit-transform: scale(1.25); transform: scale(1.25); }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}
@keyframes starPop {
  0% { -webkit-transform: scale(0.4); transform: scale(0.4); opacity: 0; }
  60% { -webkit-transform: scale(1.25); transform: scale(1.25); }
  100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}

.summary .checkin-line {
  margin-top: 6px;
  font-size: 13px;
  color: #8f7a66;
  font-weight: 600;
}

.overlay-btns {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

.overlay-btns > * {
  margin: 4px 5px;
}

/* ---------- 响应式：大屏微调 ---------- */

@media (min-width: 400px) {
  .topbar .level-title { font-size: 18px; }
  .dpad { width: 196px; height: 196px; }
  .dpad-btn { width: 58px; height: 58px; }
  .dpad-up    { left: 69px; top: 0; }
  .dpad-left  { left: 0; top: 69px; }
  .dpad-down  { left: 69px; top: 138px; }
  .dpad-right { left: 138px; top: 69px; }
}
