/*--------------------------------------------------------------
# Minesweeper page
# Reuses .calc-card / .search-button / .reset-button /
# .result-unit-toggle / .unit-tab / .calc-error / .presets-panel /
# .presets-header / .presets-title / .file-count / .action-row /
# .calc-field / .input-unit-wrap / .field-help from style.css.
--------------------------------------------------------------*/
.ms-section { padding: 60px 0; }

.ms-card { padding: 28px 32px 32px; }

.ms-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid #eef0f2;
}
.ms-stats { display: flex; gap: 28px; flex-wrap: wrap; }
.ms-stat  { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.ms-stat-label {
  font-size: 11px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 4px;
}
.ms-stat-value {
  font-family: "Poppins", sans-serif; font-size: 28px; font-weight: 700;
  color: #45505b; font-variant-numeric: tabular-nums; transition: color 0.2s;
}
.ms-stat-value.is-running { color: #0563bb; }
.ms-stat-value.is-warning { color: #d97706; }
.ms-stat-value.is-critical { color: #dc3545; }

/* Mode row (Reveal / Flag pill + hint) */
.ms-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.ms-flag-toggle .bx { vertical-align: -1px; margin-right: 4px; }
.ms-mode-hint {
  font-size: 12px;
  color: #6c757d;
}
.ms-mode-hint strong { color: #45505b; }

/* Adaptive hint: keyboard / mouse text on desktop, touch text on mobile. */
.hint-mobile { display: none; }
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  .hint-desktop { display: none; }
  .hint-mobile  { display: inline; }
}

/* The Reveal / Flag mode toggle is a touch affordance — desktop users just
   click vs right-click. Default to hidden, then show on touch devices or
   narrow viewports (so DevTools emulation also reveals it). */
.ms-flag-toggle { display: none; }
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  .ms-flag-toggle { display: inline-flex; }
}

/* Stage / board */
.ms-stage-wrap {
  width: 100%;
  overflow-x: auto;  /* expert board is wider than mobile screen */
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}
.ms-stage {
  position: relative;
  margin: 0 auto;
  display: inline-block;
  background: #eef2f6;
  border-radius: 10px;
  padding: 8px;
  border: 1px solid #e4eaf1;
  min-width: min-content;
}
.ms-board {
  display: grid;
  gap: 2px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.ms-cell {
  width: 30px;
  height: 30px;
  background: linear-gradient(180deg, #fefefe, #e7ecf1);
  border: 1px solid #cdd5de;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: #45505b;
  cursor: pointer;
  transition: background 0.08s, transform 0.08s;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
.ms-cell:hover:not(.is-open):not(.is-flag) {
  background: linear-gradient(180deg, #f0f6fc, #d6e4f1);
}
.ms-cell:active:not(.is-open) { transform: scale(0.96); }
.ms-cell.is-open {
  background: #f8fafd;
  border-color: #e4eaf1;
  cursor: default;
}
.ms-cell.is-flag {
  background: linear-gradient(180deg, #fff, #ffd9d9);
  color: #dc3545;
}
.ms-cell.is-flag::before {
  content: '\2691';
  font-size: 18px;
}
.ms-cell.is-mine {
  background: #fff3f3;
  border-color: #f5c2c7;
  color: #dc3545;
}
.ms-cell.is-mine.is-detonated {
  background: #dc3545;
  color: #fff;
  border-color: #b02a37;
}
.ms-cell.is-mine::before { content: '\2737'; font-size: 16px; }
.ms-cell.is-flag::before, .ms-cell.is-mine::before {
  pointer-events: none;
}
.ms-cell.is-mine.is-flag::before { content: '\2691'; color: #dc3545; }
.ms-cell.is-wrong-flag {
  background: #fff3f3;
}
.ms-cell.is-wrong-flag::after {
  content: '\2715';
  position: absolute;
  font-size: 18px;
  color: #dc3545;
  pointer-events: none;
}

/* Number colors (classic Minesweeper palette, but harmonized with site) */
.ms-cell.n1 { color: #0563bb; }
.ms-cell.n2 { color: #28a745; }
.ms-cell.n3 { color: #dc3545; }
.ms-cell.n4 { color: #563d7c; }
.ms-cell.n5 { color: #b95323; }
.ms-cell.n6 { color: #138496; }
.ms-cell.n7 { color: #45505b; }
.ms-cell.n8 { color: #6c757d; }

/* Overlay */
.ms-overlay {
  position: absolute; inset: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(248, 250, 253, 0.94);
  backdrop-filter: blur(2px);
  border-radius: 8px;
}
.ms-overlay[hidden] { display: none; }
.ms-overlay-card { text-align: center; padding: 22px 28px; max-width: 320px; }
.ms-overlay-title {
  font-family: "Poppins", sans-serif; font-size: 26px; font-weight: 700;
  color: #45505b; margin-bottom: 4px;
}
.ms-overlay-sub { font-size: 14px; color: #6c757d; margin-bottom: 16px; }

/* ── Result card ───────────────────────────────────────────────── */
.ms-result-card { margin-top: 24px; }
.ms-result-body { padding: 26px 28px 28px; }
.ms-result-stats {
  display: flex; justify-content: center; gap: 28px; flex-wrap: wrap;
  padding-bottom: 22px; margin-bottom: 22px;
  border-bottom: 1px solid #eef0f2;
}
.ms-result-stat {
  display: flex; flex-direction: column; align-items: center;
  background: #f8fafd; border: 1px solid #e4eaf1; border-radius: 10px;
  padding: 20px 28px; min-width: 130px;
}
.ms-result-num {
  font-family: "Poppins", sans-serif; font-size: 32px; font-weight: 700;
  color: #0563bb; font-variant-numeric: tabular-nums;
}
.ms-result-label {
  font-size: 12px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px; margin-top: 4px;
}
.ms-submit-form { max-width: 520px; margin: 0 auto; }
.ms-submit-status {
  margin-top: 14px; padding: 10px 14px; border-radius: 6px;
  font-size: 14px; text-align: center;
}
.ms-submit-status.is-success {
  background: #e8f5ee; color: #146c2e; border-left: 4px solid #28a745;
}
.ms-submit-status.is-error {
  background: #fff3f3; color: #dc3545; border-left: 4px solid #dc3545;
}
.ms-btn-label, .ms-btn-spinner { display: inline-flex; align-items: center; gap: 6px; }
.ms-btn-spinner .bx { animation: ms-spin 0.8s linear infinite; }
@keyframes ms-spin { to { transform: rotate(360deg); } }
.search-button[aria-busy="true"] { pointer-events: none; opacity: 0.85; }

/* ── Leaderboard ───────────────────────────────────────────────── */
.ms-leaderboard { margin-top: 24px; }
.ms-lb-body { padding: 4px 0 8px; }
.ms-lb-table { width: 100%; border-collapse: collapse; }
.ms-lb-table thead th {
  font-size: 11px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 10px 28px; text-align: left;
  border-bottom: 1px solid #eef0f2;
}
.ms-lb-table tbody td {
  padding: 12px 28px; font-size: 14px; color: #45505b;
  border-bottom: 1px solid #f1f4f8; vertical-align: middle;
}
.ms-lb-table tbody tr:last-child td { border-bottom: none; }
.ms-lb-table tbody tr.is-self { background: rgba(5, 99, 187, 0.06); font-weight: 600; }
.ms-lb-rank { width: 50px; }
.ms-lb-num  { width: 90px; text-align: right; font-variant-numeric: tabular-nums; }
.ms-lb-date { width: 120px; color: #6c757d; font-size: 12px; }
.ms-lb-empty { padding: 28px !important; text-align: center; color: #adb5bd; font-size: 14px; }
.ms-lb-rank-medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 12px; font-weight: 700; color: #fff;
}
.ms-lb-rank-medal.r1 { background: #d4af37; }
.ms-lb-rank-medal.r2 { background: #aab2bd; }
.ms-lb-rank-medal.r3 { background: #cd7f32; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .ms-card { padding: 22px 16px 26px; }
  .ms-toolbar { gap: 14px; }
  .ms-stats { gap: 18px; }
  .ms-stat-value { font-size: 22px; }
  .ms-cell { width: 28px; height: 28px; font-size: 14px; }
  .ms-result-body { padding: 22px 18px; }
  .ms-result-stat { padding: 16px 20px; min-width: 0; flex: 1; }
  .ms-result-num { font-size: 26px; }
  .ms-lb-table thead th, .ms-lb-table tbody td { padding: 10px 14px; }
  .ms-lb-date { display: none; }
}
@media (max-width: 480px) {
  .ms-cell { width: 26px; height: 26px; font-size: 13px; }
  .ms-result-stats { gap: 12px; }
  .ms-lb-num { width: 64px; }
}
