*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-raised: #252542;
  --border: #3d3d6b;
  --text: #e8e8f0;
  --text-muted: #9898b8;
  --accent: #6c63ff;
  --mine: #ff4757;
  --flag: #ffa502;
  --win: #2ed573;
  --shadow: rgba(0, 0, 0, 0.35);
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #1a1a35 0%, var(--bg) 60%);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.app {
  width: min(100%, 960px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.header {
  text-align: center;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 420px;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px var(--shadow);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4rem;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.reset-btn {
  width: 3rem;
  height: 3rem;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--surface-raised);
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  line-height: 1;
}

.reset-btn:hover {
  background: #32325a;
}

.reset-btn:active {
  transform: scale(0.94);
}

.status {
  min-height: 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.status.win {
  color: var(--win);
}

.status.lose {
  color: var(--mine);
}

/* Light-themed board only */
.board {
  --board-bg: #c8ceda;
  --cell-hidden: #9aa5ba;
  --cell-hidden-hover: #a8b3c8;
  --cell-revealed: #eef1f6;
  --cell-revealed-border: #d5dae4;
  --num-1: #6b9fd4;
  --num-2: #6baf7b;
  --num-3: #d97b7b;
  --num-4: #4a3f91;
  --num-5: #8b4513;
  --num-6: #0f766e;
  --num-7: #3d3d3d;
  --num-8: #5c6370;

  display: grid;
  gap: 2px;
  padding: 8px;
  width: min(100%, calc(var(--cols, 30) * 26px + 16px));
  background: var(--board-bg);
  border: 1px solid #b0b8c8;
  border-radius: 10px;
  box-shadow: 0 8px 32px var(--shadow);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.board .cell {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  border-radius: 3px;
  background: var(--cell-hidden);
  color: #1a1a1a;
  font-size: clamp(0.55rem, 2.4vw, 0.85rem);
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.08s, box-shadow 0.08s;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.45),
    inset -1px -1px 0 rgba(0, 0, 0, 0.12);
}

.board .cell:hover:not(.revealed):not(.flagged) {
  background: var(--cell-hidden-hover);
}

.board .cell.revealed {
  background: var(--cell-revealed);
  box-shadow: inset 0 0 0 1px var(--cell-revealed-border);
  cursor: default;
}

.board .cell.flagged {
  font-size: clamp(0.75rem, 3vw, 1rem);
}

.board .cell.mine-hit {
  background: var(--mine);
  box-shadow: none;
}

.board .cell.mine-revealed {
  background: #f8e8ea;
  box-shadow: inset 0 0 0 1px #e8c4c8;
}

.board .cell.n1 { color: var(--num-1); }
.board .cell.n2 { color: var(--num-2); }
.board .cell.n3 { color: var(--num-3); }
.board .cell.n4 { color: var(--num-4); }
.board .cell.n5 { color: var(--num-5); }
.board .cell.n6 { color: var(--num-6); }
.board .cell.n7 { color: var(--num-7); }
.board .cell.n8 { color: var(--num-8); }

.footer {
  margin-top: 0.5rem;
  text-align: center;
}

.footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

@media (max-width: 480px) {
  body {
    padding: 0.5rem;
  }

  .toolbar {
    gap: 1rem;
  }
}
