/* Minesweeper (js/games/minesweeper.js). Kit styles: css/game.css.
 * Square size comes from the script: --cell (px) and --cols. Covered squares are a calm
 * slate blue (puzzle art, so its own colours); open squares follow the theme, and each number
 * has its own colour that meets WCAG AA contrast on the open square in both themes. */

.ms-room {
  --ms-cover-1: #5B6E97; --ms-cover-2: #4C5E86; --ms-cover-edge: rgba(255, 255, 255, .16);
  --ms-open: #202020; --ms-open-edge: #2A2A2A;
  --ms-flag: #FFC4CD; --ms-pole: #F2F2F2;
  --ms-n1: #8EB2F2; --ms-n2: #8FD6A8; --ms-n3: #F59A9A; --ms-n4: #C7AEF9;
  --ms-n5: #F2C879; --ms-n6: #7FD6D6; --ms-n7: #EEEEEE; --ms-n8: #B0B0B0;
  position: absolute; inset: 0; overflow: hidden; background: var(--surface-100);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
:root[data-theme="light"] .ms-room {
  --ms-cover-1: #A3BEF0; --ms-cover-2: #8FADE8; --ms-cover-edge: rgba(255, 255, 255, .7);
  --ms-open: #FFFFFF; --ms-open-edge: #E2E2DD;
  --ms-flag: #A3203F; --ms-pole: #1B1B22;
  --ms-n1: #2453B8; --ms-n2: #1E7543; --ms-n3: #B3261E; --ms-n4: #6A3FC0;
  --ms-n5: #8A5A00; --ms-n6: #0E6E6E; --ms-n7: #111111; --ms-n8: #5F5F63;
  background: var(--surface-300);
}

/* the board sits centred in a box that scrolls when the squares don't fit (phones, big boards) */
.ms-scroll { position: absolute; left: 8px; right: 8px; top: 72px; bottom: 8px; display: flex; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.ms-board {
  margin: auto; display: grid; grid-template-columns: repeat(var(--cols, 9), var(--cell, 40px)); grid-auto-rows: var(--cell, 40px); gap: 2px;
  padding: 2px; touch-action: manipulation;
}
.ms-scrolls .ms-board { touch-action: pan-x pan-y; }

.ms-cell {
  position: relative; display: flex; align-items: center; justify-content: center; margin: 0; padding: 0; border: 0;
  width: var(--cell); height: var(--cell); border-radius: max(4px, calc(var(--cell) * .16));
  background: linear-gradient(170deg, var(--ms-cover-1), var(--ms-cover-2));
  box-shadow: inset 0 1.5px 0 var(--ms-cover-edge), inset 0 -2px 0 rgba(0, 0, 0, .14);
  color: var(--ink); font: 700 calc(var(--cell) * .58)/1 var(--font-sans); font-variant-numeric: tabular-nums;
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color .15s ease, transform .12s ease;
}
.ms-cell:not(.is-open):hover { filter: brightness(1.06); }
.ms-cell.is-pressed:not(.is-open) { transform: scale(.94); filter: brightness(.94); }
.ms-cell:focus { outline: none; }
.ms-cell:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 1px; z-index: 2; }
.ms-flagging .ms-cell:not(.is-open) { cursor: crosshair; }

.ms-cell.is-open { background: var(--ms-open); box-shadow: inset 0 0 0 1px var(--ms-open-edge); cursor: default; }
.ms-cell.n1 { color: var(--ms-n1); } .ms-cell.n2 { color: var(--ms-n2); } .ms-cell.n3 { color: var(--ms-n3); } .ms-cell.n4 { color: var(--ms-n4); }
.ms-cell.n5 { color: var(--ms-n5); } .ms-cell.n6 { color: var(--ms-n6); } .ms-cell.n7 { color: var(--ms-n7); } .ms-cell.n8 { color: var(--ms-n8); }
.ms-cell.is-open[class*=" n"] { cursor: pointer; }

/* flags and mines */
.ms-flag { width: 66%; height: 66%; pointer-events: none; }
.ms-flag-pole, .ms-flag-base { fill: none; stroke: var(--ms-pole); stroke-width: 2; stroke-linecap: round; }
.ms-flag-cloth { fill: var(--ms-flag); stroke: var(--ms-flag); stroke-width: 1; stroke-linejoin: round; }
.ms-mine { width: 66%; height: 66%; pointer-events: none; fill: var(--ink); stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.ms-mine-shine { fill: var(--surface-200); stroke: none; }
/* an opened mine: a soft butter square, never a red flash */
.ms-cell.is-boom { background: var(--toy-butter); box-shadow: inset 0 0 0 2px #B9862A; }
.ms-cell.is-boom .ms-mine { fill: #111; stroke: #111; }
.ms-cell.is-boom .ms-mine-shine { fill: var(--toy-butter); }
.ms-cell.is-mine .ms-mine { opacity: .85; }
.ms-cell.is-wrong { box-shadow: inset 0 0 0 3px var(--caution); }
.ms-cell.is-wrong .ms-flag { opacity: .45; }

/* hint: the safe square pulses three times, then stays lit; the number that proves it gets a dashed ring */
.ms-cell.is-hint, .ms-cell.is-why { z-index: 1; }
.ms-cell.is-hint::after, .ms-cell.is-why::after { content: ""; position: absolute; inset: -4px; border-radius: inherit; pointer-events: none; }
.ms-cell.is-hint::after { border: 3px solid var(--accent); box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent); animation: ms-pulse 1s ease-in-out 3; }
.ms-cell.is-why::after { border: 3px dashed var(--accent); }
@keyframes ms-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.ms-cell.is-nope { animation: ms-shake .36s ease; }
@keyframes ms-shake { 0%, 100% { translate: 0 0; } 25% { translate: -3px 0; } 50% { translate: 3px 0; } 75% { translate: -2px 0; } }

/* after a mine: a calm card at the bottom, Undo first */
.ms-boom {
  position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 8;
  width: min(30rem, calc(100% - 24px)); display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg);
  background: var(--surface-200); border: 1.5px solid var(--line-strong); box-shadow: var(--shadow-float); color: var(--ink);
}
.ms-boom[hidden] { display: none; }
/* the host sits in the bottom corner on phones: the card goes at the top, under the toolbar */
.ms-corner .ms-boom { top: var(--ms-top, 72px); bottom: auto; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
.ms-boom-text { margin: 0; font-size: .95rem; line-height: 1.4; }
.ms-boom-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ms-boom .icon { width: 1.1rem; height: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  .ms-cell { transition: none; }
  .ms-cell.is-hint::after { animation: none; opacity: 1; }
  .ms-cell.is-nope { animation: none; }
}
