/* ============================================================
   Minesweeper
   ============================================================ */

.ms-controls {
  display: flex;
  justify-content: center;
}

.ms-toggle {
  border: 2px solid var(--ink);
  border-radius: 999px;
  display: inline-flex;
  overflow: hidden;
}
.ms-toggle button {
  background: var(--surface);
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 8px 16px;
}
.ms-toggle button.active {
  background: var(--ink);
  color: #fff;
}

.ms-status {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  min-height: 1.4em;
  text-align: center;
}

.ms-board-wrap {
  max-width: 100%;
  overflow-x: auto;
  padding: 6px 4px 12px;
  width: 100%;
}
.ms-board {
  --ms-size: 9;
  --ms-cell: clamp(30px, 7.4vw, 49px);
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(var(--ms-size), var(--ms-cell));
  justify-content: center;
  margin: 0 auto;
  touch-action: manipulation;
  width: max-content;
}
.ms-board[data-size="12"] {
  --ms-cell: clamp(27px, 5.85vw, 42px);
}
.ms-board[data-size="16"] {
  --ms-cell: clamp(23px, 4.55vw, 36px);
}

.ms-cell {
  align-items: center;
  aspect-ratio: 1;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 7px;
  box-shadow: 0 3px 0 rgba(34, 49, 74, 0.13);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.1vw, 1.18rem);
  font-weight: 800;
  justify-content: center;
  min-width: 0;
  padding: 0;
  transition: transform 0.08s ease, background 0.08s ease;
}
.ms-cell:hover:not(:disabled) {
  transform: translateY(-1px);
}
.ms-cell.is-revealed {
  background: var(--bg-soft);
  border-color: var(--line);
  box-shadow: inset 0 2px 0 rgba(34, 49, 74, 0.05);
  cursor: default;
}
.ms-cell.is-flagged {
  background: var(--yellow);
}
.ms-cell.is-mine {
  background: var(--pink);
  color: #fff;
}
.ms-cell.is-wrong-flag {
  background: #fff;
  color: var(--pink-deep);
}
.ms-cell[data-adjacent="1"] { color: var(--simon-blue); }
.ms-cell[data-adjacent="2"] { color: var(--teal-deep); }
.ms-cell[data-adjacent="3"] { color: var(--pink-deep); }
.ms-cell[data-adjacent="4"] { color: var(--purple-deep); }
.ms-cell[data-adjacent="5"],
.ms-cell[data-adjacent="6"],
.ms-cell[data-adjacent="7"],
.ms-cell[data-adjacent="8"] { color: var(--ink); }

#flag-mode-btn.active {
  background: var(--yellow);
}

.ms-result-animation {
  align-items: center;
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 0 rgba(34, 49, 74, 0.14);
  display: flex;
  gap: 12px;
  justify-content: center;
  left: 50%;
  min-width: min(300px, calc(100vw - 48px));
  opacity: 0;
  padding: 14px 18px;
  pointer-events: none;
  position: fixed;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.86);
  visibility: hidden;
  z-index: 70;
}
.ms-result-animation[aria-hidden="false"] {
  visibility: visible;
}
.ms-result-animation.is-cleared {
  animation: ms-result-cleared 3s ease both;
}
.ms-result-animation.is-hit {
  animation: ms-result-hit 3s ease both;
}
.ms-result-icon {
  align-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  display: inline-flex;
  flex: 0 0 46px;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  height: 46px;
  justify-content: center;
  width: 46px;
}
.ms-result-text {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
}
.ms-result-animation.is-cleared .ms-result-icon {
  background: var(--simon-green);
  color: #fff;
}
.ms-result-animation.is-hit .ms-result-icon {
  background: var(--pink);
  color: #fff;
}

@keyframes ms-result-cleared {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.86); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.94); }
}

@keyframes ms-result-hit {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.86); }
  16% { opacity: 1; transform: translate(calc(-50% - 8px), -50%) scale(1); }
  25% { transform: translate(calc(-50% + 8px), -50%) scale(1); }
  34% { transform: translate(calc(-50% - 5px), -50%) scale(1); }
  43% { transform: translate(calc(-50% + 5px), -50%) scale(1); }
  55% { transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.94); }
}

#game-stage:fullscreen,
#game-stage.is-ios-fullscreen {
  border: none;
  border-radius: 0;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--obg-vh, 1vh) * 100);
  justify-content: flex-start;
  overflow-y: auto;
  width: 100vw;
}

@media (max-width: 560px) {
  #game-stage {
    padding-left: 9px;
    padding-right: 9px;
  }
  .ms-toggle button {
    padding: 8px 10px;
  }
  .ms-board {
    gap: 3px;
  }
  .ms-cell {
    border-radius: 6px;
    border-width: 1.5px;
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ms-result-animation.is-cleared,
  .ms-result-animation.is-hit {
    animation: ms-result-reduced 3s ease both;
  }
}

@keyframes ms-result-reduced {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  82% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
