/* 扫雷 · 独立样式（选择器统一前缀 .g-minesweeper） */

.g-minesweeper {
  justify-content: center;
}

/* ---------------- 顶部：难度分段 ---------------- */

.g-minesweeper .ms-head {
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.g-minesweeper .ms-head .grow { width: 100%; }

.g-minesweeper .ms-head .seg { width: 100%; padding: 4px; }
.g-minesweeper .ms-head .seg-item {
  min-height: 40px;
  font-size: 12.5px;
}

/* ---------------- 数据 --------------- */

.g-minesweeper .stats { gap: 8px; }
.g-minesweeper .stat { padding: 9px 6px; }
.g-minesweeper .stat-v { font-size: 17px; }
.g-minesweeper .stat-v.warn { color: var(--warn); }

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

.g-minesweeper .ms-boardwrap {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.g-minesweeper .ms-board {
  position: relative;
  width: min(100%, max(324px, calc(100dvh - 402px)));
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #101820;
  border: 1px solid var(--line-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 22px 54px -34px rgba(0, 0, 0, 0.95);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  font-size: 22px;
}

.g-minesweeper .ms-cells {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 0;
  border-radius: inherit;
  overflow: hidden;
}

.g-minesweeper .ms-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  font-size: 0.52em;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: transparent;
  background: linear-gradient(160deg, #2c4047, #1d2c32);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 1px 0 0 rgba(255, 255, 255, 0.035);
  border-right: 1px solid rgba(0, 0, 0, 0.38);
  border-bottom: 1px solid rgba(0, 0, 0, 0.38);
  transition: background 0.12s ease, filter 0.1s ease;
}

.g-minesweeper .ms-cell:not(.revealed):active { filter: brightness(1.3); }

.g-minesweeper .ms-cell.revealed {
  background: rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  border-color: transparent;
}

/* 经典数字配色（深色底微调亮度，保证可读） */
.g-minesweeper .ms-cell.revealed.n1 { color: #6f9bff; }
.g-minesweeper .ms-cell.revealed.n2 { color: #4fe0a7; }
.g-minesweeper .ms-cell.revealed.n3 { color: #ff6b7a; }
.g-minesweeper .ms-cell.revealed.n4 { color: #8f9cff; }
.g-minesweeper .ms-cell.revealed.n5 { color: #d08a4e; }
.g-minesweeper .ms-cell.revealed.n6 { color: #35c7d8; }
.g-minesweeper .ms-cell.revealed.n7 { color: #e7ecf6; }
.g-minesweeper .ms-cell.revealed.n8 { color: #94a0b4; }

/* 旗子：旗杆 + 三角旗面（按格子百分比绘制，任意尺寸清晰） */
.g-minesweeper .ms-cell.flag::after {
  content: "";
  position: absolute;
  left: 47%;
  top: 22%;
  width: 6%;
  height: 52%;
  background: #e6eefb;
  border-radius: 1px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.g-minesweeper .ms-cell.flag::before {
  content: "";
  position: absolute;
  left: 53%;
  top: 21%;
  width: 31%;
  height: 27%;
  background: #ff6b6b;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

/* 错误旗标：旗子 + 红色叉 */
.g-minesweeper .ms-cell.flag.wrong {
  background:
    linear-gradient(45deg, transparent 43%, rgba(255, 92, 108, 0.9) 43%, rgba(255, 92, 108, 0.9) 57%, transparent 57%),
    linear-gradient(-45deg, transparent 43%, rgba(255, 92, 108, 0.9) 43%, rgba(255, 92, 108, 0.9) 57%, transparent 57%),
    linear-gradient(160deg, #2c4047, #1d2c32);
}

/* 地雷 */
.g-minesweeper .ms-cell.mine::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 46%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc4ca, #e03e4e 58%, #8f0f1e);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 8px rgba(255, 60, 80, 0.35);
}

.g-minesweeper .ms-cell.mine::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72%;
  height: 72%;
  transform: translate(-50%, -50%) rotate(45deg);
  background:
    linear-gradient(rgba(255, 150, 160, 0.9), rgba(255, 150, 160, 0.9)) center / 100% 2px no-repeat,
    linear-gradient(rgba(255, 150, 160, 0.9), rgba(255, 150, 160, 0.9)) center / 2px 100% no-repeat;
  opacity: 0.75;
  pointer-events: none;
}

.g-minesweeper .ms-cell.mine.shown {
  background: rgba(255, 92, 108, 0.14);
  border-color: transparent;
}

.g-minesweeper .ms-cell.mine.revealed {
  background: rgba(255, 92, 108, 0.22);
}

.g-minesweeper .ms-cell.boom {
  background: rgba(255, 92, 108, 0.45) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 92, 108, 0.75);
}

/* ---------------- 结算覆盖层 ---------------- */

.g-minesweeper .ms-over {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(8, 11, 18, 0.84);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
  pointer-events: none;
}

.g-minesweeper .ms-over.show { opacity: 1; visibility: visible; }

/* 失败结算：不做模糊，让玩家能看清全部雷与错误旗标 */
.g-minesweeper .ms-over.lose {
  background: rgba(8, 11, 18, 0.52);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.g-minesweeper .ms-over.lose .ms-over-card {
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line-2);
  background: linear-gradient(180deg, #161c2b, #111623);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.g-minesweeper .ms-over-card { pointer-events: auto; }

.g-minesweeper .ms-over-card {
  width: 100%;
  max-width: 250px;
  text-align: center;
}

.g-minesweeper .ms-over-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.g-minesweeper .ms-over-sub {
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
}

.g-minesweeper .ms-over-stats {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.g-minesweeper .ms-over-stat {
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.g-minesweeper .ms-over-stat span {
  display: block;
  font-size: 10px;
  color: var(--faint);
  margin-bottom: 2px;
}

.g-minesweeper .ms-over-stat b {
  display: block;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-minesweeper .ms-over .btn { min-height: 44px; }

/* ---------------- 操作行 / 进度面板 ---------------- */

.g-minesweeper .ms-toolbar { gap: 9px; }
.g-minesweeper .ms-toolbar .btn { min-height: 44px; }
.g-minesweeper .ms-toolbar .ms-flagbtn { flex: 1.25; }

.g-minesweeper .ms-progress { padding: 11px 12px 12px; }
.g-minesweeper .ms-progress-head { align-items: baseline; }
.g-minesweeper .ms-progress-head .hint:first-child {
  color: var(--dim);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.g-minesweeper .ms-progress .progress { height: 5px; }
.g-minesweeper .ms-progress .hint { font-size: 10.8px; line-height: 1.55; }

/* ---------------- 窄屏 ---------------- */

@media (max-width: 359px) {
  .g-minesweeper .ms-head .seg-item { font-size: 11.5px; }
  .g-minesweeper .stat-v { font-size: 16px; }
  .g-minesweeper .ms-toolbar .btn { font-size: 12.5px; }
}
