/* Minesweeper styling — reuses the theme variables defined in line_escape.css
   (:root for dark, html[data-theme="light"] for light). */

.ms-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px 20px;
  color: var(--text);
}

.ms-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.ms-topbar a.back {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  background: var(--btn);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 6px 12px;
}
.ms-topbar a.back:active { transform: translateY(1px); }
.ms-title { font-size: 20px; font-weight: 700; letter-spacing: 0.3px; }

/* difficulty picker */
.ms-diffs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ms-diff-btn, .ms-daily {
  background: var(--btn);
  color: var(--muted);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ms-diff-btn.active { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
.ms-daily { margin-left: auto; color: var(--accent); }

/* HUD */
.ms-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--muted);
}
.ms-hud .lbl { color: var(--muted2); font-weight: 500; font-size: 12px; }
#ms-time { color: var(--text); font-variant-numeric: tabular-nums; }
#ms-mines { color: var(--accent); font-variant-numeric: tabular-nums; }
#ms-mode { color: var(--text); }

/* ------------------------------------------------------------- board */
#ms-board-wrap { overflow-x: auto; }
#ms-board {
  --ms-cell: 32px;
  display: grid;
  gap: 0;
  width: max-content;
  margin: 0 auto 10px;
  border: 2px solid var(--line2);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.ms-cell {
  width: var(--ms-cell);
  height: var(--ms-cell);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  /* raised, unrevealed tile */
  background: var(--btn);
  border: 1px solid var(--line);
  border-top-color: rgba(255, 255, 255, 0.18);
  border-left-color: rgba(255, 255, 255, 0.18);
  border-right-color: rgba(0, 0, 0, 0.28);
  border-bottom-color: rgba(0, 0, 0, 0.28);
}
.ms-cell:active:not(.open) { filter: brightness(1.12); }
.ms-cell.open {
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: default;
}
.ms-cell.flag { font-size: 0.9em; }
.ms-cell.flag.wrong { background: rgba(220, 60, 60, 0.25); }
.ms-cell.mine { background: rgba(220, 60, 60, 0.25); font-size: 0.9em; }
.ms-cell.mine.boom { background: #d43c3c; }

/* classic number colours (dark-theme friendly; light theme uses the originals) */
.ms-cell.n1 { color: #64a5ff; }
.ms-cell.n2 { color: #5ec25e; }
.ms-cell.n3 { color: #ff6b6b; }
.ms-cell.n4 { color: #b48cff; }
.ms-cell.n5 { color: #e0a15e; }
.ms-cell.n6 { color: #4fd0c9; }
.ms-cell.n7 { color: #e8e8e8; }
.ms-cell.n8 { color: #9aa4ad; }
html:not([data-dark]) .ms-cell.n1 { color: #1a46d8; }
html:not([data-dark]) .ms-cell.n2 { color: #187a18; }
html:not([data-dark]) .ms-cell.n3 { color: #c22020; }
html:not([data-dark]) .ms-cell.n4 { color: #5b1ea8; }
html:not([data-dark]) .ms-cell.n5 { color: #8a4a12; }
html:not([data-dark]) .ms-cell.n6 { color: #0d7d77; }
html:not([data-dark]) .ms-cell.n7 { color: #222; }
html:not([data-dark]) .ms-cell.n8 { color: #666; }

@keyframes ms-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
#ms-board-wrap.shake { animation: ms-shake 0.42s; }

/* ------------------------------------------------------------ actions */
.ms-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}
.ms-act {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 66px;
}
.ms-act small { font-size: 15px; }
.ms-act:active { transform: translateY(1px); }
.ms-act.active { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
.ms-hidden { display: none !important; }

.ms-guest-note {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
}
.ms-guest-note a { color: var(--accent); }

/* ------------------------------------------------------- leaderboard */
#ms-board-panel h3 { font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
#ms-board-panel .sk-lb { width: 100%; border-collapse: collapse; font-size: 13px; }
#ms-board-panel .sk-lb td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
#ms-board-panel .sk-lb td:first-child { width: 34px; text-align: center; }
#ms-board-panel .sk-lb td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#ms-board-panel .sk-lb tr.me td { color: var(--accent); font-weight: 700; }
#ms-board-panel .sk-lb img.flag { vertical-align: -1px; margin-right: 4px; }
#ms-board-panel .sk-empty, #ms-board-panel .sk-me-line { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* -------------------------------------------------------------- overlay */
#ms-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
#ms-overlay.hidden { display: none; }
.ms-ov-card {
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 22px 26px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#ms-ov-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.ms-ov-time { font-size: 34px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.ms-ov-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ms-ov-card .btnrow { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.ms-ov-card button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.ms-ov-card button.ghost {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--line2);
}

/* --------------------------------------------------------------- toast */
#ms-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(16px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 70;
  max-width: 90vw;
  text-align: center;
}
#ms-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------- hint highlight */
@keyframes ms-hintpulse {
  0% { box-shadow: inset 0 0 0 2px var(--accent); }
  50% { box-shadow: inset 0 0 0 4px var(--accent); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}
.ms-cell.hinted { animation: ms-hintpulse 1.2s; }
.ms-act .cnt {
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 0 5px;
  margin-left: 2px;
}

/* ---------------------------------------------------- XP line */
#ms-xpline {
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  margin: 0 auto 12px;
  width: max-content;
  max-width: 100%;
  cursor: pointer;
}
#ms-xpline .ms-xp-next { color: var(--muted2); font-weight: 500; }

/* ---------------------------------------------------- board themes */
/* Classic — the light-grey Windows look, whatever the site theme */
.ms-theme-classic { background: #bdbdbd; border-color: #7b7b7b; }
.ms-theme-classic .ms-cell {
  background: #c0c0c0;
  border: 1px solid #808080;
  border-top-color: #ffffff;
  border-left-color: #ffffff;
  border-right-color: #7b7b7b;
  border-bottom-color: #7b7b7b;
  color: #222;
}
.ms-theme-classic .ms-cell.open { background: #bdbdbd; border: 1px solid #9e9e9e; }
.ms-theme-classic .ms-cell.n1 { color: #0000ff; }
.ms-theme-classic .ms-cell.n2 { color: #007b00; }
.ms-theme-classic .ms-cell.n3 { color: #ff0000; }
.ms-theme-classic .ms-cell.n4 { color: #00007b; }
.ms-theme-classic .ms-cell.n5 { color: #7b0000; }
.ms-theme-classic .ms-cell.n6 { color: #007b7b; }
.ms-theme-classic .ms-cell.n7 { color: #000000; }
.ms-theme-classic .ms-cell.n8 { color: #7b7b7b; }
.ms-theme-classic .ms-cell.mine { background: #e3a3a3; }
.ms-theme-classic .ms-cell.mine.boom { background: #ff4d4d; }

/* Neon — dark glow */
.ms-theme-neon { background: #0a0f1e; border-color: #263a66; }
.ms-theme-neon .ms-cell {
  background: #141c33;
  border: 1px solid #1d2a4d;
  border-top-color: rgba(120, 170, 255, 0.25);
  border-left-color: rgba(120, 170, 255, 0.25);
  border-right-color: rgba(0, 0, 0, 0.5);
  border-bottom-color: rgba(0, 0, 0, 0.5);
  color: #e8f1ff;
}
.ms-theme-neon .ms-cell.open { background: #0a0f1e; border: 1px solid #182342; }
.ms-theme-neon .ms-cell.n1 { color: #4dc3ff; text-shadow: 0 0 6px rgba(77, 195, 255, 0.7); }
.ms-theme-neon .ms-cell.n2 { color: #52ff9d; text-shadow: 0 0 6px rgba(82, 255, 157, 0.7); }
.ms-theme-neon .ms-cell.n3 { color: #ff5c7a; text-shadow: 0 0 6px rgba(255, 92, 122, 0.7); }
.ms-theme-neon .ms-cell.n4 { color: #c393ff; text-shadow: 0 0 6px rgba(195, 147, 255, 0.7); }
.ms-theme-neon .ms-cell.n5 { color: #ffb35c; text-shadow: 0 0 6px rgba(255, 179, 92, 0.7); }
.ms-theme-neon .ms-cell.n6 { color: #5cf2e8; text-shadow: 0 0 6px rgba(92, 242, 232, 0.7); }
.ms-theme-neon .ms-cell.n7 { color: #ffffff; }
.ms-theme-neon .ms-cell.n8 { color: #93a3c9; }
.ms-theme-neon .ms-cell.mine { background: rgba(255, 60, 90, 0.3); }
.ms-theme-neon .ms-cell.mine.boom { background: #ff3c5a; }

/* ---------------------------------------------------- modals */
#ms-stats, #ms-custom {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 65;
  padding: 16px;
}
#ms-stats.hidden, #ms-custom.hidden { display: none; }
.ms-modal-card {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 16px 18px 18px;
  max-width: 420px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.ms-modal-slim { max-width: 320px; }
.ms-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  background: var(--panel);
  padding: 4px 0 8px;
  z-index: 3;
}
.ms-modal-head button {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

/* stats content */
.ms-lvl-big { font-size: 19px; font-weight: 800; color: var(--accent); text-align: center; }
.ms-xpbar {
  height: 9px;
  border-radius: 999px;
  background: var(--btn);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 8px 0 4px;
}
.ms-xpbar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.ms-stats-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
.ms-stats-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.ms-stats-table td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.ms-ach-head { font-size: 13px; font-weight: 800; color: var(--muted); margin: 14px 0 8px; }
.ms-ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ms-ach {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 4px;
  opacity: 0.45;
}
.ms-ach.got { opacity: 1; border-color: var(--accent); }
.ms-ach .i { font-size: 18px; }
.ms-ach .n { font-size: 10.5px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.ms-ach.got .n { color: var(--text); }

/* custom form */
.ms-cst-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.ms-cst-row label { font-size: 13px; color: var(--muted); }
.ms-cst-row input {
  width: 76px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 7px 9px;
  font-size:var(--fld-fs,14px);
  font-weight: 700;
  text-align: center;
}
.ms-cst-note { font-size: 12px; color: var(--muted2); margin: 4px 0 12px; }
#ms-custom .btnrow { display: flex; justify-content: center; }
#ms-custom .btnrow button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 9px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* numbered-puzzle / daily navigation (board panel) */
.ms-pz-nav{
  display:flex; align-items:center; justify-content:space-between;
  gap:8px; margin:0 0 12px;
}
.ms-pz-cur{ font-weight:700; color:var(--accent); font-size:15px; }
.ms-pz-btn{
  background:var(--btn); color:var(--text); border:1px solid var(--line2);
  border-radius:8px; padding:5px 12px; font-size:13px; font-weight:600; cursor:pointer;
}
.ms-pz-btn:hover:not([disabled]){ filter:brightness(1.15); }
.ms-pz-btn[disabled]{ opacity:.4; cursor:default; }
.ms-pz-solved-h{ margin:14px 0 8px; color:var(--muted2); font-size:13px; font-weight:600; }
.ms-pz-chips{ display:flex; flex-wrap:wrap; gap:6px; }
.ms-pz-chip{
  background:var(--btn); color:var(--text); border:1px solid var(--line2);
  border-radius:7px; padding:4px 9px; font-size:12px; font-weight:600; cursor:pointer;
  font-variant-numeric:tabular-nums;
}
.ms-pz-chip:hover{ border-color:var(--accent); color:var(--accent); }
