/* =====================================================================
   数字华容道 · 棋盘与方块
   外层 .tile 只负责百分比定位，内层 .tile__face 负责外观与手感
   ===================================================================== */

.board-shell {
  position: relative;
  aspect-ratio: 1;
  padding: clamp(7px, 1.6vmin, 14px);
  background: var(--paper-warm);
  border: 3px solid var(--ink);
  border-radius: clamp(20px, 3.6vmin, 30px);
  box-shadow: 0 7px 0 var(--paper-deep), 0 9px 0 var(--ink), var(--shadow-card);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.board {
  --bsize: 4;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: clamp(12px, 2.2vmin, 20px);
  background:
    repeating-linear-gradient(0deg, rgba(90, 74, 58, 0.055) 0 1px, transparent 1px calc(100% / var(--bsize))),
    repeating-linear-gradient(90deg, rgba(90, 74, 58, 0.055) 0 1px, transparent 1px calc(100% / var(--bsize))),
    var(--paper);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  container-type: inline-size;
  -webkit-touch-callout: none;
}
.board[data-size="3"] { --bsize: 3; }
.board[data-size="4"] { --bsize: 4; }
.board[data-size="5"] { --bsize: 5; }

.board:focus { outline: none; }
.board:focus-visible {
  outline: 3px dashed var(--pumpkin);
  outline-offset: 5px;
}

/* 空位提示：虚线小格子，帮助小朋友找到“洞” */
.board__hole {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--bsize));
  height: calc(100% / var(--bsize));
  transform: translate(calc(var(--col) * 100%), calc(var(--row) * 100%));
  transition: transform var(--dur-fast) var(--ease-bounce);
  pointer-events: none;
  z-index: 0;
}
.board__hole::after {
  content: "";
  position: absolute;
  inset: clamp(2px, 3.2%, 5px);
  border: 2px dashed rgba(90, 74, 58, 0.20);
  border-radius: clamp(9px, 14%, 20px);
  background: rgba(90, 74, 58, 0.035);
}

/* —— 外层：仅做定位 —— */
.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--bsize));
  height: calc(100% / var(--bsize));
  padding: 0;
  border: none;
  background: none;
  transform: translate(calc(var(--col) * 100%), calc(var(--row) * 100%));
  transition: transform var(--dur-fast) var(--ease-bounce);
  cursor: pointer;
  z-index: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* —— 内层：方块外观 —— */
.tile__face {
  position: absolute;
  inset: clamp(2px, 3.2%, 5px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: clamp(2px, 0.55cqw, 3px) solid var(--ink);
  border-radius: clamp(9px, 14%, 20px);
  background: var(--tile-c, var(--orange-soft));
  color: var(--ink-tile);
  font-family: var(--font-num);
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12), 0 3px 0 rgba(90, 74, 58, 0.4);
  transition: transform var(--dur-fast) var(--ease-bounce), filter var(--dur-fast), box-shadow var(--dur-fast);
  pointer-events: none;
}

/* 字号随棋盘尺寸缩放（按阶数分别设定） */
.board[data-size="3"] .tile__face {
  font-size: clamp(18px, 9vmin, 44px);
  font-size: clamp(26px, 13cqw, 64px);
}
.board[data-size="4"] .tile__face {
  font-size: clamp(16px, 7.2vmin, 40px);
  font-size: clamp(20px, 10.2cqw, 52px);
}
.board[data-size="5"] .tile__face {
  font-size: clamp(14px, 5.8vmin, 34px);
  font-size: clamp(17px, 8.4cqw, 44px);
}

@media (hover: hover) {
  .tile:hover .tile__face {
    transform: translateY(-3px) scale(1.025);
    filter: brightness(1.05);
  }
}
.tile:active .tile__face {
  transform: translateY(1px) scale(0.98);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.10), 0 1px 0 rgba(90, 74, 58, 0.35);
}
.tile:focus { outline: none; }
.tile:focus-visible .tile__face {
  outline: 3px dashed var(--pumpkin);
  outline-offset: -7px;
}

/* —— 无解点击时的轻推反馈 —— */
.board.is-bump { animation: boardBump 0.32s var(--ease-soft); }
@keyframes boardBump {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

/* —— 完成时的波浪欢呼 —— */
.board.is-solved .tile__face {
  animation: tileCheer 0.72s var(--ease-bounce) both;
  animation-delay: var(--cheer-delay, 0s);
}
@keyframes tileCheer {
  0%   { transform: translateY(0) scale(1) rotate(0); }
  32%  { transform: translateY(-9%) scale(1.06) rotate(-2deg); }
  62%  { transform: translateY(2%) scale(0.975) rotate(1deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}

/* —— 拖动中：稍微收起 hover 效果 —— */
.board.is-dragging .tile__face { filter: none; }

/* 极窄屏：压缩纵向间距，给左下角版本号腾出一行 */
@media (max-width: 380px) {
  .screen--start { padding-bottom: 26px; }
  .app-version { left: 8px; bottom: 5px; font-size: 9px; padding: 1px 5px; }
  .setup { gap: 3px; }
  .setup__block { padding: 6px; gap: 4px; }
  .diff-list { gap: 5px; }
  .diff { min-height: 40px; padding: 4px 8px; }
  .diff__name small, .setup__label-note { display: none; }
  .app-title { font-size: clamp(26px, 8vw, 32px); }
  .btn--lg { min-height: 52px; }
  .hero__card { width: min(150px, 44vw); padding: 7px; }
  .hero__caption, .hero__float { display: none; }
  .subtitle { display: none; }
}

/* 极窄屏：难度卡进一步压缩 */
@media (max-width: 340px) {
  .diff { min-height: 40px; padding: 4px 8px; gap: 8px; }
  .diff__mini { width: 26px; height: 26px; border-radius: 7px; }
  .diff__name { font-size: var(--fs-sm); }
  .diff__best { font-size: 10px; }
}
