/* ============================================================
   扫雷大作战 · 棋盘
   ============================================================ */

.board {
  --cell-gap: 2px;
  --board-pad: 6px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), var(--cell-size, 30px));
  grid-auto-rows: var(--cell-size, 30px);
  gap: var(--cell-gap);
  width: max-content;
  padding: var(--board-pad);
  background: var(--cover-3);
  border: 2px solid var(--line);
  border-radius: var(--radius-board);
  box-shadow: 0 5px 0 var(--shadow-strong);
  touch-action: none;
  outline: none;
}

.cell {
  position: relative;
  width: var(--cell-size, 30px);
  height: var(--cell-size, 30px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-cell);
  background: linear-gradient(155deg, var(--cover-3), var(--cover));
  box-shadow:
    inset 0 -3px 0 var(--cover-2),
    inset 0 2px 0 color-mix(in srgb, var(--surface) 45%, transparent),
    0 1px 0 var(--shadow-soft);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: calc(var(--cell-size, 30px) * 0.48);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter 90ms ease, transform 100ms ease, background-color 100ms ease;
}

.cell:focus {
  outline: none;
}

@media (hover: hover) and (pointer: fine) {
  .cell:not(.is-open):hover {
    filter: brightness(1.05);
  }
}

.cell:active:not(.is-open):not(.is-flagged) {
  transform: translateY(1px);
  filter: brightness(0.97);
}

.cell.is-open {
  background: var(--open);
  box-shadow: inset 0 0 0 1px var(--grid-line);
  border-radius: calc(var(--radius-cell) * 0.58);
  cursor: default;
}

.cell.is-open.just-opened {
  animation: cellReveal 170ms var(--ease-out);
}

.cell.is-open:active,
.cell.is-open:hover {
  transform: none;
  filter: none;
}

.cell.is-flagged {
  background: linear-gradient(155deg, var(--cover-3), var(--flag-soft));
}

.cell.is-question {
  color: var(--accent-2);
  font-size: calc(var(--cell-size, 30px) * 0.52);
}

.cell.is-mine {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--grid-line);
  color: var(--fg);
}

.cell.is-mine .mine-svg {
  color: var(--fg);
}

.cell.is-exploded {
  background: var(--danger);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pal-ink) 20%, transparent);
  color: var(--pal-paper);
  animation: explode 280ms var(--ease-out);
}

.cell.is-exploded .mine-svg {
  color: var(--pal-paper);
}

.cell.is-wrong {
  background: var(--danger-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 35%, transparent);
}

.cell.is-wrong::after {
  content: "";
  position: absolute;
  inset: 17%;
  background:
    linear-gradient(45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%);
  opacity: 0.9;
  pointer-events: none;
}

.cell.is-hint {
  z-index: 2;
  animation: hintPulse 900ms ease-in-out infinite;
}

.cell.is-hint::before {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid var(--accent-2);
  border-radius: inherit;
  pointer-events: none;
}

.board.is-keyboard .cell.is-cursor::after {
  content: "";
  position: absolute;
  inset: -3px;
  z-index: 4;
  border: 3px solid var(--accent-2);
  border-radius: inherit;
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
}

.cell.is-flash-safe {
  animation: safeFlash 420ms var(--ease-out);
}

.cell.is-flag-pop .flag-glyph,
.cell.is-flag-pop .question-glyph {
  animation: flagPop 240ms var(--ease-bounce);
}

.cell.is-nudge {
  animation: nudge 260ms ease;
}

.mine-svg {
  width: 64%;
  height: 64%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.flag-glyph {
  display: block;
  color: var(--flag-color);
  font-family: var(--font-body);
  font-size: calc(var(--cell-size, 30px) * 0.55);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 1px 0 var(--surface);
  pointer-events: none;
  transform-origin: 20% 90%;
}

.question-glyph {
  display: block;
  font-family: var(--font-display);
  font-size: calc(var(--cell-size, 30px) * 0.52);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }

/* 键盘模式提示 */
.board.is-keyboard {
  box-shadow:
    0 0 0 2px var(--accent-soft),
    0 5px 0 var(--shadow-strong);
}

/* ============================================================
   主题差异 · 糖果像素
   ============================================================ */

:root[data-theme="candy"] .board {
  --cell-gap: 3px;
  --board-pad: 7px;
  background: var(--cover-3);
}

:root[data-theme="candy"] .cell {
  border-radius: 9px;
  box-shadow:
    inset 0 -4px 0 var(--cover-2),
    inset 0 2px 0 color-mix(in srgb, var(--surface) 55%, transparent),
    0 1px 0 var(--shadow-soft);
}

:root[data-theme="candy"] .cell.is-open {
  border-radius: 6px;
  background: var(--open-2);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--accent) 16%, transparent),
    inset 0 1px 0 var(--surface);
}

:root[data-theme="candy"] .cell.is-open.n1,
:root[data-theme="candy"] .cell.is-open.n2,
:root[data-theme="candy"] .cell.is-open.n3,
:root[data-theme="candy"] .cell.is-open.n4,
:root[data-theme="candy"] .cell.is-open.n5,
:root[data-theme="candy"] .cell.is-open.n6,
:root[data-theme="candy"] .cell.is-open.n7,
:root[data-theme="candy"] .cell.is-open.n8 {
  text-shadow: 0 1px 0 var(--surface);
}

:root[data-theme="candy"] .cell.is-hint::before {
  border-style: dashed;
}

/* ============================================================
   主题差异 · 校园涂鸦
   ============================================================ */

:root[data-theme="doodle"] .board {
  --cell-gap: 2px;
  --board-pad: 7px;
  border-width: 3px;
  background:
    repeating-linear-gradient(
      -45deg,
      transparent 0 7px,
      color-mix(in srgb, var(--line) 5%, transparent) 7px 8px
    ),
    var(--cover-3);
  box-shadow: 3px 5px 0 var(--shadow-strong);
}

:root[data-theme="doodle"] .cell {
  border-radius: 7px 9px 6px 10px / 9px 6px 10px 7px;
  background: var(--cover-3);
  box-shadow:
    inset 0 -3px 0 var(--cover-2),
    1px 2px 0 var(--shadow-strong);
}

:root[data-theme="doodle"] .cell:nth-child(7n + 2) {
  transform: rotate(-0.7deg);
}

:root[data-theme="doodle"] .cell:nth-child(11n + 4) {
  transform: rotate(0.6deg);
}

:root[data-theme="doodle"] .cell.is-open {
  border-radius: 6px 8px 5px 9px / 8px 5px 9px 6px;
  background: var(--open-2);
  box-shadow: inset 0 0 0 1px var(--grid-line);
  transform: none;
}

:root[data-theme="doodle"] .cell.is-open.n1,
:root[data-theme="doodle"] .cell.is-open.n2,
:root[data-theme="doodle"] .cell.is-open.n3,
:root[data-theme="doodle"] .cell.is-open.n4,
:root[data-theme="doodle"] .cell.is-open.n5,
:root[data-theme="doodle"] .cell.is-open.n6,
:root[data-theme="doodle"] .cell.is-open.n7,
:root[data-theme="doodle"] .cell.is-open.n8 {
  font-family: var(--font-display);
  font-weight: 900;
}

:root[data-theme="doodle"] .cell.is-hint::before {
  border-style: dashed;
  border-radius: 10px 6px 11px 7px;
}

/* ============================================================
   主题差异 · 清爽科技
   ============================================================ */

:root[data-theme="tech"] .board {
  --cell-gap: 1px;
  --board-pad: 5px;
  border-width: 1px;
  background: var(--cover);
  box-shadow: 0 10px 30px -22px var(--shadow-strong);
}

:root[data-theme="tech"] .cell {
  border-radius: 5px;
  background: var(--cover);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 18%, transparent);
  font-size: calc(var(--cell-size, 30px) * 0.5);
}

@media (hover: hover) and (pointer: fine) {
  :root[data-theme="tech"] .cell:not(.is-open):hover {
    background: color-mix(in srgb, var(--accent) 18%, var(--cover));
    box-shadow: inset 0 0 0 1px var(--accent-line);
  }
}

:root[data-theme="tech"] .cell.is-open {
  background: var(--open);
  box-shadow: inset 0 0 0 1px var(--grid-line);
  border-radius: 3px;
}

:root[data-theme="tech"] .cell.is-flagged {
  background: color-mix(in srgb, var(--flag-soft) 55%, var(--cover));
}

:root[data-theme="tech"] .cell.is-hint::before {
  border-width: 2px;
}

/* ============================================================
   动效
   ============================================================ */

@keyframes cellReveal {
  from {
    opacity: 0.4;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes flagPop {
  0% { transform: scale(0.55) rotate(-10deg); }
  60% { transform: scale(1.16) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes hintPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.16); }
}

@keyframes safeFlash {
  0% { box-shadow: inset 0 0 0 3px var(--good); }
  100% { box-shadow: inset 0 0 0 1px var(--grid-line); }
}

@keyframes explode {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.12); filter: brightness(1.5); }
  100% { transform: scale(1); filter: brightness(1); }
}

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

@keyframes boardShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, -1px); }
  80% { transform: translate(3px, 1px); }
}

.game-card.is-shaking {
  animation: boardShake 320ms ease;
}

.face-btn.is-worried .face-icon {
  animation: faceWobble 420ms ease;
}

.face-btn.is-happy .face-icon {
  animation: faceBounce 480ms var(--ease-bounce);
}

@keyframes faceWobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-8deg); }
  55% { transform: rotate(7deg); }
  80% { transform: rotate(-3deg); }
}

@keyframes faceBounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12) rotate(-3deg); }
  70% { transform: scale(0.96) rotate(2deg); }
}

/* 手机端进一步增大可点区域，视觉尺寸由 JS 的格子档位控制 */
@media (pointer: coarse) {
  .cell {
    min-width: 0;
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell,
  .cell.is-open,
  .face-icon {
    animation: none !important;
    transition: none !important;
  }

  .cell:nth-child(7n + 2),
  .cell:nth-child(11n + 4) {
    transform: none;
  }
}
