/* マインスイーパー固有スタイル */

.ms-settings {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px;
  margin-top: 4px;
}

.ms-field .field-label {
  margin-bottom: 8px;
}

.option-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.option-tabs--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-tab {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 8px 6px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.04s ease;
}

.option-tab small {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.75;
}

.option-tab:hover {
  background: var(--md-sys-color-primary-container);
}

.option-tab:active {
  transform: translateY(1px);
}

.option-tab.is-active {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.game-panel {
  margin-top: 20px;
}

.ms-result {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  text-align: center;
  animation: ms-result-in 200ms ease-out;
}

.ms-result.is-clear {
  border: 1px solid color-mix(in srgb, var(--success) 38%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, var(--success) 10%, var(--md-sys-color-surface));
}

.ms-result.is-over {
  border: 1px solid color-mix(in srgb, var(--danger) 38%, var(--md-sys-color-outline-variant));
  background: color-mix(in srgb, var(--danger) 8%, var(--md-sys-color-surface));
}

.ms-result__title {
  margin: 0;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ms-result.is-clear .ms-result__title {
  color: var(--success);
}

.ms-result.is-over .ms-result__title {
  color: var(--danger);
}

.ms-result__detail {
  margin: 4px 0 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.875rem;
  line-height: 1.6;
}

.ms-result__actions {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.ms-result__actions .btn {
  min-width: 9rem;
}

@keyframes ms-result-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ——— 盤面 ——— */
.ms-board-wrap {
  display: flex;
  justify-content: center;
  max-width: 100%;
  margin-bottom: 10px;
  padding-bottom: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}

/* 盤面が横幅に収まらない場合は中央寄せを外し、左端まで操作できるようにする */
.ms-board-wrap.is-scrollable {
  justify-content: flex-start;
}

.ms-board {
  --ms-cell: 32px;
  --ms-cols: 9;
  display: grid;
  grid-template-columns: repeat(var(--ms-cols), var(--ms-cell));
  gap: 2px;
  padding: 8px;
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(circle at 16% 0%, rgba(63, 196, 255, 0.14), transparent 60%),
    radial-gradient(circle at 88% 100%, rgba(150, 106, 255, 0.14), transparent 58%),
    linear-gradient(160deg, #16264a 0%, #101c38 55%, #0d1730 100%);
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: box-shadow 240ms ease;
}

.ms-board.is-clear {
  box-shadow: 0 0 0 1px rgba(94, 226, 178, 0.5), 0 14px 34px rgba(28, 52, 96, 0.24), 0 0 34px rgba(94, 226, 178, 0.32);
}

.ms-cell {
  position: relative;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--ms-cell);
  height: var(--ms-cell);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.02));
  color: #e9f1ff;
  font-family: "Outfit", "Noto Sans JP", sans-serif;
  font-size: calc(var(--ms-cell) * 0.54);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

@media (hover: hover) {
  .ms-cell:not(.is-open):hover {
    background: rgba(255, 255, 255, 0.17);
  }
}

.ms-cell:focus-visible {
  outline: 2px solid #6fd6ff;
  outline-offset: 1px;
  z-index: 1;
}

.ms-board.is-flag-mode .ms-cell:not(.is-open) {
  border-color: rgba(255, 122, 217, 0.4);
}

.ms-board.is-finished .ms-cell {
  cursor: default;
}

.ms-cell.is-open {
  border-color: rgba(255, 255, 255, 0.03);
  background: rgba(226, 238, 255, 0.21);
  cursor: default;
  animation: ms-open 150ms ease-out backwards;
}

@keyframes ms-open {
  from { opacity: 0.15; transform: scale(0.82); }
  to { opacity: 1; transform: none; }
}

/* 数字は盤面の暗い背景でも読みやすい色を優先する */
.ms-cell[data-adj="1"] { color: #78ccff; }
.ms-cell[data-adj="2"] { color: #6fe6a6; }
.ms-cell[data-adj="3"] { color: #ff93a9; }
.ms-cell[data-adj="4"] { color: #b7a3ff; }
.ms-cell[data-adj="5"] { color: #ffc774; }
.ms-cell[data-adj="6"] { color: #5fe1e1; }
.ms-cell[data-adj="7"] { color: #ffffff; }
.ms-cell[data-adj="8"] { color: #c3cfe4; }

/* フラグは旗竿と三角を疑似要素で描く（アイコンフォントに依存しない） */
.ms-cell.is-flag::before {
  content: "";
  position: absolute;
  left: 34%;
  top: 22%;
  width: 8%;
  min-width: 2px;
  height: 56%;
  border-radius: 1px;
  background: #dbe7fb;
}

.ms-cell.is-flag::after {
  content: "";
  position: absolute;
  left: 42%;
  top: 22%;
  width: 28%;
  height: 28%;
  background: linear-gradient(135deg, #ff8ada, #ff4fa3);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  filter: drop-shadow(0 0 4px rgba(255, 94, 200, 0.75));
  animation: ms-flag-pop 150ms ease-out;
}

@keyframes ms-flag-pop {
  from { transform: scale(0.3); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}

.ms-cell.is-mine::before {
  content: "";
  position: absolute;
  left: 26%;
  top: 26%;
  width: 48%;
  height: 48%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffe9dd 0%, #ff9c62 38%, #d8362c 100%);
  box-shadow: 0 0 9px rgba(255, 110, 70, 0.65);
}

.ms-cell.is-exploded {
  border-color: rgba(255, 116, 92, 0.7);
  background: rgba(216, 54, 44, 0.42);
  animation: ms-boom 320ms ease-out;
}

.ms-cell.is-exploded::before {
  box-shadow: 0 0 16px rgba(255, 120, 80, 0.95), 0 0 30px rgba(255, 80, 60, 0.6);
}

@keyframes ms-boom {
  0% { transform: scale(1); }
  35% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* 地雷ではないのにフラグを立てていたマスは×で示す */
.ms-cell.is-wrong::before,
.ms-cell.is-wrong::after {
  content: "";
  position: absolute;
  left: 22%;
  top: 47%;
  width: 56%;
  height: 10%;
  min-height: 2px;
  border-radius: 2px;
  background: #ff8a8a;
}

.ms-cell.is-wrong::before { transform: rotate(45deg); }
.ms-cell.is-wrong::after { transform: rotate(-45deg); }

.ms-scroll-hint,
.ms-guide {
  margin: 0 auto 4px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  line-height: 1.6;
  text-align: center;
}

.game-controls {
  justify-content: center;
}

.game-controls .btn {
  min-width: 9rem;
  justify-content: center;
}

@media (max-width: 600px) {
  .ms-settings {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

@media (max-width: 480px) {
  .ms-result__title {
    font-size: 1.375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ms-cell.is-open,
  .ms-cell.is-flag::after,
  .ms-cell.is-exploded,
  .ms-result {
    animation: none;
  }
}

/* 共通画面とHUDを利用。多列盤面だけはセルの操作性を保って内部スクロールする。 */
html.gs-playing .game-panel.gs-screen {
  display: grid;
  grid-template-columns: 44px minmax(0, 586px);
  grid-template-areas: "bar settings" "status status" "board board" "hint hint" "mode mode" "controls controls";
  gap: 10px;
  justify-content: center;
  align-content: start;
}
html.gs-playing .game-panel > .gs-bar { grid-area: bar; margin: 0; align-self: start; }
html.gs-playing .ms-settings { grid-area: settings; grid-template-columns: 1fr; gap: 8px; margin: 0; min-width: 0; }
html.gs-playing .ms-mode { grid-area: mode; min-width: 0; }
html.gs-playing .ms-field .field-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
html.gs-playing .option-tabs { gap: 6px; }
html.gs-playing .option-tab {
  min-height: 44px; padding: 4px 6px; gap: 0;
  border-color: var(--play-border); background: var(--play-hud-bg); color: var(--play-text); font-size: .8125rem;
}
html.gs-playing .option-tab small { font-size: .6875rem; }
html.gs-playing .option-tab.is-active { border-color: var(--play-accent); background: color-mix(in srgb, var(--play-accent) 18%, var(--play-hud-bg)); color: var(--play-accent); }
html.gs-playing .option-tab:focus-visible { outline: 2px solid var(--play-accent); outline-offset: 2px; }
@media (hover: hover) {
  html.gs-playing .option-tab:hover { border-color: var(--play-accent); background: var(--play-btn-hover); }
}
html.gs-playing .game-panel > .gs-hud { grid-area: status; max-width: 640px; margin: 0; }
.ms-stage { position: relative; grid-area: board; min-width: 0; width: 100%; }
html.gs-playing .ms-board-wrap { margin: 0; }
html.gs-playing .ms-board { flex: none; border-color: var(--play-border); }
html.gs-playing .ms-result {
  position: absolute; inset: 0; z-index: 2; margin: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(11, 20, 42, .94); backdrop-filter: blur(5px);
}
html.gs-playing .ms-result__detail { color: var(--play-text); }
html.gs-playing .ms-scroll-hint { grid-area: hint; display: block; visibility: visible; min-height: 1.6em; margin: 0; color: var(--play-text-muted); text-align: center; }
html.gs-playing .ms-scroll-hint[hidden] { display: block !important; visibility: hidden; }
html.gs-playing .game-controls { grid-area: controls; margin: 0; justify-content: center; }
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .game-panel.gs-screen { row-gap: 24px; padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top)); }
}
@media (max-width: 380px) {
  html.gs-playing .option-tab { padding-inline: 2px; }
  html.gs-playing .option-tab small { font-size: .625rem; }
}
