.m-board {
  --w: 12;
  --h: 12;
  --m-tray: color-mix(in srgb, var(--text) 10%, var(--surface));
  --m-tile-top: color-mix(in srgb, var(--game) 14%, var(--surface));
  --m-tile-bottom: color-mix(in srgb, var(--game) 30%, var(--surface));
  --m-tile-edge: color-mix(in srgb, var(--game) 55%, var(--text));
  --m-open: var(--surface);
  --m-open-line: color-mix(in srgb, var(--text) 9%, var(--surface));
  --m-1: #1f5fe0;
  --m-2: #14873a;
  --m-3: #e0292f;
  --m-4: #2a1f8f;
  --m-5: #8c1d1d;
  --m-6: #0e8a8c;
  --m-7: #1c1847;
  --m-8: #6b6b80;
  --m-gap: max(1.5px, calc(100cqw * .006));
  container-type: inline-size;
  width: 100%;
  aspect-ratio: var(--w) / var(--h);
  display: grid;
  grid-template-columns: repeat(var(--w), 1fr);
  grid-template-rows: repeat(var(--h), 1fr);
  gap: var(--m-gap);
  padding: var(--m-gap);
  border-radius: 14px;
  background: var(--m-tray);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .12);
  color: var(--text);
  touch-action: none;
}
@media (prefers-color-scheme: dark) {
  .m-board {
    --m-tray: color-mix(in srgb, #000 30%, var(--surface));
    --m-tile-top: color-mix(in srgb, var(--game) 34%, var(--surface));
    --m-tile-bottom: color-mix(in srgb, var(--game) 18%, var(--surface));
    --m-tile-edge: color-mix(in srgb, #000 45%, var(--surface));
    --m-open: color-mix(in srgb, #000 12%, var(--surface));
    --m-open-line: color-mix(in srgb, #fff 6%, var(--surface));
    --m-1: #7fb0ff;
    --m-2: #5fd98a;
    --m-3: #ff7b7f;
    --m-4: #b9a8ff;
    --m-5: #ffab70;
    --m-6: #5fe0e0;
    --m-7: #f2f0ff;
    --m-8: #b3b1cc;
  }
}

.m-tile {
  position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0;
  border-radius: max(3px, calc(100cqw / var(--w) * .2));
  font-family: var(--display); font-weight: 700; line-height: 1;
  font-size: calc(100cqw / var(--w) * .5);
  cursor: pointer;
  /* Hidden: a raised, slightly glossy key. */
  background: linear-gradient(180deg, var(--m-tile-top), var(--m-tile-bottom));
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, .55),
    inset 0 -2px 0 color-mix(in srgb, var(--m-tile-edge) 45%, transparent),
    0 1px 1.5px rgba(0, 0, 0, .14);
  transition: transform .06s, filter .1s;
}
@media (hover: hover) {
  .m-board:not(.m-locked) .m-tile:not(.m-open):hover { filter: brightness(1.06) saturate(1.1); }
}
.m-tile.m-press, .m-tile.m-pending { transform: scale(.9); filter: brightness(.95); }
.m-tile.m-pending { animation: m-pulse .7s ease-in-out infinite alternate; }
@keyframes m-pulse { to { filter: brightness(.85); } }

.m-tile.m-open {
  cursor: default;
  background: var(--m-open);
  box-shadow: inset 0 0 0 1px var(--m-open-line);
}
.m-tile.m-open.m-fresh { animation: m-flip .22s ease-out both; }
@keyframes m-flip { from { transform: scale(.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.m-tile.m-n1 { color: var(--m-1); }
.m-tile.m-n2 { color: var(--m-2); }
.m-tile.m-n3 { color: var(--m-3); }
.m-tile.m-n4 { color: var(--m-4); }
.m-tile.m-n5 { color: var(--m-5); }
.m-tile.m-n6 { color: var(--m-6); }
.m-tile.m-n7 { color: var(--m-7); }
.m-tile.m-n8 { color: var(--m-8); }
.m-board:not(.m-locked) .m-tile.m-num { cursor: pointer; }
.m-tile.m-nope { animation: m-nope .3s ease-in-out; }
@keyframes m-nope { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

/* Flags and mines (emoji, sized a bit smaller than digits). */
.m-tile.m-flag, .m-tile.m-mine, .m-tile.m-boom { font-family: var(--body); font-size: calc(100cqw / var(--w) * .46); }
.m-tile.m-flag { animation: m-plant .18s ease-out; }
@keyframes m-plant { from { transform: translateY(-18%) scale(1.2); } to { transform: none; } }
.m-tile.m-mine { background: var(--m-open); box-shadow: inset 0 0 0 1px var(--m-open-line); animation: m-flip .25s ease-out both; }
.m-tile.m-boom {
  background: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 35%, transparent);
  animation: m-boom .45s ease-out both; z-index: 1;
}
@keyframes m-boom { 0% { transform: scale(.6); } 55% { transform: scale(1.25); } 100% { transform: scale(1); } }
.m-tile.m-wrong::after {
  content: ""; position: absolute; inset: 14%; pointer-events: none;
  background:
    linear-gradient(45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, var(--danger) 44% 56%, transparent 56%);
}
.m-tile.m-cursor { outline: 2.5px solid var(--game); outline-offset: 1px; z-index: 2; }
.board-frame.m-exploded .m-board { animation: m-shake .35s ease-in-out; }
@keyframes m-shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
.m-board.m-busy .m-tile { cursor: progress; }
.m-board.m-locked .m-tile { cursor: default; }

/* Controls under the board. */
.m-bar {
  width: min(600px, calc(100vw - 32px)); display: flex; align-items: center; justify-content: space-between; gap: 10px;
  user-select: none; -webkit-user-select: none;
}
.m-count { display: flex; align-items: baseline; gap: 7px; font-weight: 600; color: var(--muted); }
.m-count-icon { font-size: 1.15rem; align-self: center; }
.m-count b { font-family: var(--display); font-size: 1.45rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; min-width: 1.6em; }
.m-count b.m-neg { color: var(--danger); }
.m-count-label { font-size: .85rem; }
.m-flagbtn { padding: 9px 14px; touch-action: manipulation; white-space: nowrap; }
.m-flagbtn.m-on { background: var(--game); border-color: var(--game); color: #fff; }
.m-toggle { font-size: .7rem; font-weight: 800; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.m-flagbtn.m-on .m-toggle { background: rgba(255, 255, 255, .25); color: #fff; }
.m-bar.m-locked .m-flagbtn { opacity: .55; pointer-events: none; }
@media (max-width: 380px) { .m-count-label { display: none; } }
