/* ============================================================
   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(40px, calc(7.8vw + 1.33px), 57.33px);
  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: rgba(34, 49, 74, 0.52);
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  height: 100dvh;
  inset: 0;
  justify-content: center;
  min-width: 0;
  opacity: 0;
  padding: 24px;
  pointer-events: none;
  position: fixed;
  transform: scale(0.98);
  visibility: hidden;
  width: 100vw;
  z-index: 5000;
}
.ms-result-animation[aria-hidden="false"] {
  opacity: 1;
  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 78px;
  font-family: var(--font-display);
  font-size: 2.7rem;
  font-weight: 800;
  height: 78px;
  justify-content: center;
  box-shadow: 0 8px 0 rgba(34, 49, 74, 0.18);
  width: 78px;
}
.ms-result-text {
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 0 rgba(34, 49, 74, 0.14);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 7vw, 2rem);
  font-weight: 800;
  line-height: 1.05;
  padding: 12px 18px;
  text-align: center;
}
.ms-result-animation.is-cleared .ms-result-icon {
  background: var(--simon-green);
  color: #fff;
  animation: ms-result-icon-cleared 3s ease both;
}
.ms-result-animation.is-hit .ms-result-icon {
  background: var(--pink);
  color: #fff;
  animation: ms-result-icon-hit 3s ease both;
}
.ms-result-animation.is-cleared .ms-result-text {
  animation: ms-result-text-cleared 3s ease both;
}
.ms-result-animation.is-hit .ms-result-text {
  animation: ms-result-text-hit 3s ease both;
}

@keyframes ms-result-cleared {
  0% { opacity: 0; transform: scale(0.98); }
  16% { opacity: 1; transform: scale(1.02); }
  30% { transform: scale(1); }
  76% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.99); }
}

@keyframes ms-result-hit {
  0% { opacity: 0; transform: scale(0.98); }
  16% { opacity: 1; transform: translateX(-8px) scale(1); }
  25% { transform: translateX(8px) scale(1); }
  34% { transform: translateX(-5px) scale(1); }
  43% { transform: translateX(5px) scale(1); }
  55% { transform: translateX(0) scale(1); }
  76% { opacity: 1; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(0) scale(0.99); }
}

@keyframes ms-result-icon-cleared {
  0% { transform: scale(0.3) rotate(-28deg); }
  14% { transform: scale(1.28) rotate(8deg); }
  26% { transform: scale(0.96) rotate(-4deg); }
  38% { transform: scale(1.08) rotate(0); }
  70% { transform: scale(1) rotate(0); }
  86% { transform: scale(1.12) rotate(0); }
  100% { transform: scale(0.9) rotate(0); }
}

@keyframes ms-result-icon-hit {
  0% { transform: scale(0.35); }
  12% { transform: scale(1.18) rotate(-10deg); }
  20% { transform: translateX(-14px) rotate(10deg); }
  28% { transform: translateX(14px) rotate(-10deg); }
  36% { transform: translateX(-10px) rotate(8deg); }
  44% { transform: translateX(10px) rotate(-8deg); }
  56% { transform: translateX(0) rotate(0); }
  82% { transform: scale(1); }
  100% { transform: scale(0.9); }
}

@keyframes ms-result-text-cleared {
  0%, 12% { opacity: 0; transform: translateY(18px) scale(0.94); }
  24% { opacity: 1; transform: translateY(0) scale(1.04); }
  36%, 82% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

@keyframes ms-result-text-hit {
  0%, 10% { opacity: 0; transform: translateY(18px); }
  20% { opacity: 1; transform: translateY(0); }
  28% { transform: translateX(-7px); }
  36% { transform: translateX(7px); }
  44%, 82% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateY(-8px); }
}

#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: 6px;
    padding-right: 6px;
  }
  .ms-toggle button {
    padding: 8px 10px;
  }
  .ms-board-wrap[data-size="9"],
  .ms-board-wrap[data-size="12"] {
    overflow-x: hidden;
    padding-left: 0;
    padding-right: 0;
  }
  .ms-board {
    gap: 2px;
  }
  .ms-board[data-size="9"] {
    --ms-cell: clamp(28px, 8.6vw, 34px);
  }
  .ms-board[data-size="12"] {
    --ms-cell: clamp(21px, 6.15vw, 28px);
  }
  .ms-board[data-size="16"] {
    --ms-cell: clamp(19px, 5vw, 24px);
  }
  .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;
  }
  .ms-result-animation.is-cleared .ms-result-icon,
  .ms-result-animation.is-hit .ms-result-icon,
  .ms-result-animation.is-cleared .ms-result-text,
  .ms-result-animation.is-hit .ms-result-text {
    animation: none;
  }
}

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