/*
  minesweeper.css, game-specific rules only. Shared chrome (title, HUD,
  buttons, overlay, panel, touch-only visibility) lives in ../shared/arcade.css.
*/

.ms-difficulty {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.ms-panel {
  display: inline-block;
  max-width: 96vw;
  overflow-x: auto;
}

.ms-grid {
  display: grid;
  grid-template-columns: repeat(var(--ms-cols), var(--ms-cell-size));
  grid-template-rows: repeat(var(--ms-rows), var(--ms-cell-size));
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
}

.ms-cell {
  position: relative;
  width: var(--ms-cell-size);
  height: var(--ms-cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(223, 246, 251, 0.07), rgba(223, 246, 251, 0) 55%),
    var(--arcade-cell);
  border: 1px solid var(--arcade-cell-line);
  border-radius: 3px;
  box-shadow:
    inset 1px 1px 0 rgba(223, 246, 251, 0.08),
    inset -1px -1px 0 rgba(0, 0, 0, 0.5);
  color: var(--arcade-fg);
  font-family: var(--arcade-font);
  font-size: calc(var(--ms-cell-size) * 0.45);
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

@media (hover: hover) {
  .ms-cell:not(.is-revealed):hover {
    border-color: var(--arcade-accent);
    box-shadow:
      var(--arcade-glow-cyan),
      inset 1px 1px 0 rgba(223, 246, 251, 0.08),
      inset -1px -1px 0 rgba(0, 0, 0, 0.5);
  }
}

.ms-cell.is-revealed {
  background: var(--arcade-cell-rev);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
  cursor: default;
  animation: ms-reveal 0.14s ease-out backwards;
  animation-delay: var(--ms-delay, 0ms);
}

/* Flood reveals ripple outward: JS sets --ms-delay per cell by BFS depth.
   The backwards fill keeps a delayed cell invisible until its turn. */
@keyframes ms-reveal {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.ms-cell.is-mine-revealed {
  background: rgba(255, 59, 59, 0.18);
}

.ms-cell.is-mine-hit {
  background: rgba(255, 59, 59, 0.35);
}

/* Mine: a plain CSS dot, no emoji glyphs. */
.ms-cell.is-mine-revealed::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50%;
  height: 50%;
  transform: translate(-50%, -50%);
  background: var(--arcade-danger);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--arcade-danger);
}

/* Flag: a small CSS pole and triangle, no emoji glyphs. */
.ms-cell.is-flagged::before {
  content: "";
  position: absolute;
  left: 46%;
  top: 22%;
  width: 2px;
  height: 58%;
  background: var(--arcade-fg);
}

.ms-cell.is-flagged::after {
  content: "";
  position: absolute;
  left: 46%;
  top: 20%;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 9px;
  border-color: transparent transparent transparent var(--arcade-accent-2);
  filter: drop-shadow(0 0 3px var(--arcade-accent-2));
  animation: ms-flag-pop 0.16s ease-out;
}

@keyframes ms-flag-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* JS toggles is-shaking on the grid when a mine is hit. */
.ms-grid.is-shaking {
  animation: ms-shake 0.4s ease-in-out;
}

@keyframes ms-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-2px, -1px); }
  80% { transform: translate(2px, 1px); }
}

/* Distinct colors for the adjacent-mine-count numbers 1-8. */
.ms-cell.n1 { color: #4da6ff; }
.ms-cell.n2 { color: var(--arcade-ok); }
.ms-cell.n3 { color: var(--arcade-danger); }
.ms-cell.n4 { color: #b06cff; }
.ms-cell.n5 { color: #ffb020; }
.ms-cell.n6 { color: var(--arcade-accent); }
.ms-cell.n7 { color: var(--arcade-accent-2); }
.ms-cell.n8 { color: #f5f5f5; }

.ms-mode {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ms-grid.is-flag-mode .ms-cell:not(.is-revealed) {
  cursor: crosshair;
}

.ms-note {
  max-width: 46ch;
  text-align: center;
  font-size: clamp(8px, 1.3vw, 10px);
  color: var(--arcade-muted);
  letter-spacing: 0.03em;
  line-height: 1.7;
}
