:root {
  --bg: #07111f;
  --panel: #0f172a;
  --line: rgba(148, 163, 184, 0.22);
  --text: #e8edf5;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-text: #93c5fd;
  --danger: #ef4444;
  --gold: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #15233a 0%, var(--bg) 70%);
  color: var(--text);
  font-family: "Vazirmatn", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body { min-height: 100vh; min-height: 100dvh; }

.m-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 10px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.m-mast {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.m-mast h1 { font-size: clamp(1.25rem, 5vw, 1.6rem); font-weight: 800; }
.m-mast p { color: var(--muted); font-size: 0.74rem; margin-top: 2px; }

.m-stats { display: flex; gap: 10px; }
.m-stat {
  min-width: 58px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 10px;
}
.m-stat .l { color: var(--muted); font-size: 0.66rem; }
.m-stat .v { font-size: 1rem; font-weight: 800; color: var(--accent-text); }

.m-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.m-diff { display: flex; gap: 6px; }
.m-diff button, .mb {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.m-diff button:hover, .mb:hover { border-color: var(--accent); color: var(--accent-text); }
.m-diff button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mb.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.mb.primary:hover { color: #fff; background: #2f6fe0; }
.mb.on { background: rgba(239, 68, 68, 0.14); border-color: var(--danger); color: #fca5a5; }
#flagBtn { margin-inline-start: auto; }

.m-frame { position: relative; overflow-x: auto; }

.m-board {
  display: grid;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  width: max-content;
  margin: 0 auto;
}

.m-cell {
  width: var(--cell, 30px);
  height: var(--cell, 30px);
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 30px) * 0.5);
  font-weight: 800;
  cursor: pointer;
}
.m-cell.open { background: rgba(15, 23, 42, 0.65); border-color: rgba(148, 163, 184, 0.10); cursor: default; }
.m-cell.boom { background: rgba(239, 68, 68, 0.30); border-color: var(--danger); }
.m-cell.wrong { background: rgba(239, 68, 68, 0.12); }

.m-cell.n1 { color: #60a5fa; }
.m-cell.n2 { color: #4ade80; }
.m-cell.n3 { color: #f87171; }
.m-cell.n4 { color: #a78bfa; }
.m-cell.n5 { color: #fbbf24; }
.m-cell.n6 { color: #2dd4bf; }
.m-cell.n7 { color: #f472b6; }
.m-cell.n8 { color: #cbd5e1; }

.m-flag { width: 40%; height: 58%; position: relative; }
.m-flag::before {
  content: "";
  position: absolute;
  inset-inline-start: 38%;
  top: 0;
  width: 12%;
  height: 100%;
  background: #cbd5e1;
  border-radius: 1px;
}
.m-flag::after {
  content: "";
  position: absolute;
  inset-inline-start: 46%;
  top: 6%;
  width: 44%;
  height: 42%;
  background: var(--danger);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.m-mine {
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: #1f2937;
  box-shadow: inset 0 0 0 2px #94a3b8;
}

.m-overlay {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: rgba(7, 17, 31, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-overlay[hidden] { display: none !important; }
.m-over-card { text-align: center; padding: 20px; }
.m-over-card h2 { font-size: 1.25rem; font-weight: 800; margin-bottom: 6px; }
.m-over-card h2.win { color: var(--gold); }
.m-over-card h2.lose { color: #f87171; }
.m-over-card p { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }

.m-help { color: var(--muted); font-size: 0.76rem; text-align: center; line-height: 1.9; }
