.m-board {
  --w: 12;
  --h: 12;
  --m-tray: #111113;
  --m-tile-top: color-mix(in srgb, var(--game) 30%, #48484c);
  --m-tile-bottom: color-mix(in srgb, var(--game) 30%, #3a3a3c);
  --m-open: #1c1c1e;
  --m-1: #7fb0ff;
  --m-2: #5fd98a;
  --m-3: #ff7b7f;
  --m-4: #c39bff;
  --m-5: #ffab70;
  --m-6: #5fe0e0;
  --m-7: #ffffff;
  --m-8: #a1a1a6;
  --m-gap: max(2px, calc(100cqw * .007));
  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: calc(var(--m-gap) * 2);
  border-radius: 18px;
  background: var(--m-tray);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  color: #fff;
  touch-action: none;
}

.m-tile {
  position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0;
  border-radius: max(4px, calc(100cqw / var(--w) * .22));
  font-family: var(--font); font-weight: 650; line-height: 1; letter-spacing: -0.02em;
  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 1px 0 rgba(255, 255, 255, .14);
  transition: transform .3s var(--ease-spring), filter .15s;
}
@media (hover: hover) {
  .m-board:not(.m-locked) .m-tile:not(.m-open):hover { filter: brightness(1.18); }
}
.m-tile.m-press, .m-tile.m-pending { transform: scale(.86); filter: brightness(1.25); transition-duration: .08s; }
.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: none;
}
.m-tile.m-open.m-fresh { animation: m-flip .42s var(--ease-spring) both; }
@keyframes m-flip { from { transform: scale(.4) rotateX(70deg); opacity: 0; } to { transform: none; 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 { 20%, 60% { transform: translateX(-3px); } 40%, 80% { transform: translateX(3px); } }

/* Flags and mines (emoji, sized a bit smaller than digits). */
.m-tile.m-flag, .m-tile.m-mine, .m-tile.m-boom, .m-tile.m-hit { font-family: var(--font); font-size: calc(100cqw / var(--w) * .46); }
.m-tile.m-flag { animation: m-plant .35s var(--ease-spring); }
@keyframes m-plant { from { transform: translateY(-22%) scale(1.25); } to { transform: none; } }
.m-tile.m-mine { background: var(--m-open); box-shadow: none; animation: m-flip .3s var(--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); } }
/* A mine stepped on with lives left: it stays, marked, and the game goes on. */
.m-tile.m-hit { background: color-mix(in srgb, var(--danger) 38%, var(--m-open)); box-shadow: none; }
.m-tile.m-hit-new { animation: m-boom .45s ease-out both; z-index: 1; }
.board-frame.m-ouch .m-board { animation: m-shake .35s ease-in-out; }
.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: 2px solid var(--accent); 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, 100cqw); 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: 500; color: var(--muted); }
.m-count-icon { font-size: 1.15rem; align-self: center; }
.m-count b { font-family: var(--font); font-size: 1.45rem; font-weight: 600; letter-spacing: -0.03em; color: #fff; min-width: 1.25em; }
.m-count b.m-neg { color: var(--danger); }
.m-count-label { font-size: .85rem; }
.m-lives { display: flex; gap: 2px; font-size: 1.05rem; line-height: 1; }
.m-lives span { display: inline-block; }
.m-lives span:not(.on) { opacity: .55; }
.m-lives .m-lost { animation: m-heart .6s var(--ease-out); }
@keyframes m-heart { 0% { transform: scale(1.6); } 40% { transform: scale(.7) rotate(-12deg); } 100% { transform: none; } }
.m-flagbtn { padding: 9px 14px; touch-action: manipulation; white-space: nowrap; background: rgba(255, 255, 255, .1); color: #fff; }
.m-flagbtn:hover { background: rgba(255, 255, 255, .16); }
.m-flagbtn.m-on, .m-flagbtn.m-on:hover { background: #fff; color: #000; }
.m-toggle { font-size: .68rem; font-weight: 650; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; background: rgba(255, 255, 255, .12); color: var(--muted); }
.m-flagbtn.m-on .m-toggle { background: var(--danger); color: #fff; }
.m-bar.m-locked .m-flagbtn { opacity: .55; pointer-events: none; }
@media (max-width: 440px) { .m-count-label { display: none; } }

/* Server hints: numbers that explain why, the cells to act on, and the shared cells of a pair. */
.m-tile.m-hint-focus { box-shadow: inset 0 0 0 2px var(--warn); }
.m-tile.m-hint-area { outline: 2px dashed rgba(255, 255, 255, .55); outline-offset: -4px; }
.m-tile.m-hint-safe, .m-tile.m-hint-mine, .m-tile.m-hint-bad { z-index: 1; animation: m-hint 1.1s ease-in-out infinite; }
.m-tile.m-hint-safe { --m-hint: var(--good); }
.m-tile.m-hint-mine { --m-hint: var(--warn); }
.m-tile.m-hint-bad { --m-hint: var(--danger); }
@keyframes m-hint {
  0%, 100% { box-shadow: inset 0 0 0 3px var(--m-hint), 0 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 0 3px var(--m-hint), 0 0 0 4px color-mix(in srgb, var(--m-hint) 35%, transparent); }
}
