/*
 * 扫雷样式 —— 零依赖，无第三方字体/图标/图片。
 * 地雷和旗子全部用 CSS 图形 + Unicode 字符绘制，版权 100% 自有。
 * 配色刻意避开 Windows 扫雷的灰色浮雕美术，走干净现代的中性色板。
 */

.ms {
  /* 所有可调项集中在这里，方便攻略站按主题覆写 */
  --ms-tile: 30px;
  --ms-gap: 2px;
  --ms-radius: 4px;
  --ms-bg: #eef1f6;
  --ms-panel: #ffffff;
  --ms-hidden: #b9c3d4;
  --ms-hidden-hi: #cfd7e4;
  --ms-open: #e6eaf1;
  --ms-line: #9aa7bd;
  --ms-text: #26303f;

  display: inline-block;
  max-width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: var(--ms-bg);
  color: var(--ms-text);
  /* 只用系统字体栈，不引任何 web font */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  /* 移动端双击和弦时不要触发浏览器的双击缩放 */
  touch-action: manipulation;
}

/* ---------- 顶部状态栏 ---------- */
.ms-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--ms-panel);
}

.ms-counter {
  min-width: 3.4em;
  padding: 4px 8px;
  border-radius: 6px;
  background: #26303f;
  color: #7ef2c4;
  /* 等宽字体保证数字跳动时宽度不抖 */
  font: 600 18px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.ms-reset {
  width: 36px;
  height: 36px;
  border: 1px solid var(--ms-line);
  border-radius: 8px;
  background: var(--ms-hidden-hi);
  color: var(--ms-text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease, transform .08s ease;
}
.ms-reset:hover { background: var(--ms-hidden); }
.ms-reset:active { transform: scale(.94); }

/* ---------- 棋盘 ---------- */
/*
 * expert 是 30 列宽盘，窄屏放不下。让滚动发生在这个内层容器上，
 * 页面整体布局就不会被撑破（overflow 交给它，不外溢到 body）。
 */
.ms-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.ms-grid {
  display: grid;
  /* --ms-cols 由 JS 按难度写入，CSS 不必知道具体难度 */
  grid-template-columns: repeat(var(--ms-cols, 9), var(--ms-tile));
  gap: var(--ms-gap);
  /* 防止 grid 被 flex/scroll 容器压缩，保证格子始终是正方形 */
  width: max-content;
}

.ms-cell {
  width: var(--ms-tile);
  height: var(--ms-tile);
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--ms-radius);
  background: var(--ms-hidden);
  color: transparent;
  font: 700 15px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  cursor: pointer;
  position: relative;
  /* 顶部高光模拟微凸起，比拟物浮雕更克制 */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55);
  transition: background .1s ease;
}

.ms-cell:hover:not(.is-open) { background: var(--ms-hidden-hi); }

/* 键盘焦点必须清晰可见 —— 这是键盘可玩性的前提 */
.ms-cell:focus-visible {
  outline: 3px solid #2f6bff;
  outline-offset: -3px;
  z-index: 1;
}

.ms-cell.is-open {
  background: var(--ms-open);
  box-shadow: none;
  cursor: default;
}

/*
 * 经典数字配色（1蓝 2绿 3红 4深蓝 5棕 6青 7黑 8灰）。
 * 这是几十年沿用的功能性色码 —— 玩家靠颜色瞬间读盘，属于玩法而非美术抄袭。
 * 注意 .n0 故意不设颜色：0 格不显示数字。
 */
.ms-cell.n1 { color: #1976d2; }
.ms-cell.n2 { color: #2e7d32; }
.ms-cell.n3 { color: #d32f2f; }
.ms-cell.n4 { color: #1a237e; }
.ms-cell.n5 { color: #8d4e2a; }
.ms-cell.n6 { color: #00838f; }
.ms-cell.n7 { color: #1c1c1c; }
.ms-cell.n8 { color: #6b7280; }

/*
 * 可见数字用伪元素渲染（避免文本节点影响布局）。
 * 必须排除 .is-mine：雷格的 ::after 要留给地雷圆形，两者不能抢同一个伪元素。
 * 0 格没有 data-n 属性，天然不渲染。
 */
.ms-cell.is-open:not(.is-mine)::after {
  content: attr(data-n);
}

/* ---------- 旗子：纯 CSS 三角旗 + 旗杆 ---------- */
.ms-cell.is-flag::before {
  content: "";
  position: absolute;
  left: 34%;
  top: 22%;
  width: 0;
  height: 0;
  /* 用 border 技巧画三角形，不依赖任何图片资源 */
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid #e53935;
}
.ms-cell.is-flag::after {
  content: "";
  position: absolute;
  left: 33%;
  top: 22%;
  width: 2px;
  height: 56%;
  border-radius: 1px;
  background: #37474f;
}

/* ---------- 地雷：纯 CSS 圆形 + 高光 ---------- */
.ms-cell.is-mine::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52%;
  height: 52%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #6b7280 0 18%, #1f2530 60%);
}

/* 踩中的那颗雷用红底突出，和"局终揭示的其他雷"区分开 */
.ms-cell.is-open.is-mine { background: #ff8a80; }

/* 局终揭示的未踩中的雷：底色保持隐藏态，暗示"你没点到这里" */
.ms-cell.is-revealed-mine { background: var(--ms-hidden-hi); }

/*
 * 插错的旗：局终时旗下无雷。画一道红叉盖在旗上，
 * 让玩家复盘时一眼看到自己的判断失误发生在哪。
 */
.ms-cell.is-wrong::before {
  content: "";
  position: absolute;
  inset: 18%;
  border: none;
  background:
    linear-gradient(45deg, transparent 44%, #c62828 44% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, #c62828 44% 56%, transparent 56%);
}
.ms-cell.is-wrong::after { display: none; }

/* ---------- 状态播报 ---------- */
.ms-status {
  margin-top: 8px;
  min-height: 1.2em;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* ---------- 响应式 ---------- */
/* 窄屏缩小格子，让 beginner/intermediate 尽量整盘可见；expert 仍靠横向滚动 */
@media (max-width: 640px) {
  .ms { --ms-tile: 26px; padding: 8px; }
}
@media (max-width: 380px) {
  .ms { --ms-tile: 23px; }
}

/* 尊重系统的减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  .ms-cell, .ms-reset { transition: none; }
}
