:root {
  --bg: #1e2433;
  --panel: #2a3247;
  --panel-light: #35405a;
  --cell-unrevealed: #4a5570;
  --cell-unrevealed-hover: #5a6790;
  --cell-revealed: #3a4358;
  --border: #161b28;
  --text: #eef2f9;
  --accent: #ffb454;
  --num-1: #4aa8ff;
  --num-2: #5edc8a;
  --num-3: #ff6b6b;
  --num-4: #b48cff;
  --num-5: #ff9e5e;
  --num-6: #4fd8c8;
  --num-7: #f5f5f5;
  --num-8: #ffd166;
}

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

body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, #2b3550 0%, var(--bg) 60%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  padding: 20px;
}

.game {
  background: var(--panel);
  border: 1px solid #3c4762;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  user-select: none;
  -webkit-user-select: none;
}

.topbar { display: flex; justify-content: center; margin-bottom: 14px; }

.difficulty { display: flex; gap: 8px; }

.btn {
  background: var(--panel-light);
  color: var(--text);
  border: 1px solid #4a5678;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:hover { background: #40507a; }
.btn:active { transform: translateY(1px); }

.diff-btn.active {
  background: var(--accent);
  color: #1e2433;
  border-color: var(--accent);
  font-weight: 600;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #20273a;
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.hud-box {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 22px;
  font-weight: 700;
  background: #141a2a;
  color: #ff5f6d;
  padding: 4px 12px;
  border-radius: 8px;
  letter-spacing: 2px;
  min-width: 66px;
  text-align: center;
}

.reset-btn {
  width: 46px;
  height: 46px;
  font-size: 24px;
  border-radius: 10px;
  border: 1px solid #4a5678;
  background: var(--panel-light);
  cursor: pointer;
  line-height: 1;
}

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

.board-wrap { display: flex; justify-content: center; }

.board {
  display: grid;
  gap: 3px;
  background: var(--panel);
  padding: 6px;
  border-radius: 10px;
  touch-action: manipulation;
}

.cell {
  width: 34px;
  height: 34px;
  border-radius: 5px;
  background: var(--cell-unrevealed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  color: transparent;
  transition: background 0.1s;
  font-family: inherit;
  padding: 0;
}

.cell:hover { background: var(--cell-unrevealed-hover); }

.cell.revealed {
  background: var(--cell-revealed);
  cursor: default;
  color: var(--text);
  box-shadow: inset 0 0 0 1px #2c3346;
}

.cell.revealed:hover { background: var(--cell-revealed); }

.cell.flagged { color: #ffb454; }
.cell.question { color: #8ea3c7; }

.cell.mine-hit { background: #ff5f6d !important; }

.cell.num-1 { color: var(--num-1); }
.cell.num-2 { color: var(--num-2); }
.cell.num-3 { color: var(--num-3); }
.cell.num-4 { color: var(--num-4); }
.cell.num-5 { color: var(--num-5); }
.cell.num-6 { color: var(--num-6); }
.cell.num-7 { color: var(--num-7); }
.cell.num-8 { color: var(--num-8); }

.cell:disabled { cursor: default; }

.legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
  font-size: 12px;
  color: #8ea3c7;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 26, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

.overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border: 1px solid #4a5678;
  border-radius: 18px;
  padding: 34px 48px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: popIn 0.25s ease-out;
}

.modal-emoji { font-size: 56px; margin-bottom: 8px; }

.modal h2 { margin-bottom: 8px; font-size: 24px; }

.modal p { color: #aebcd8; margin-bottom: 20px; font-size: 14px; }

.modal-btn { background: var(--accent); color: #1e2433; border-color: var(--accent); font-size: 15px; font-weight: 600; padding: 10px 26px; }

.modal-btn:hover { background: #ffc97e; }

@media (max-width: 640px) {
  .game { padding: 10px; }
  .cell { width: 26px; height: 26px; font-size: 14px; border-radius: 4px; }
  .hud-box { font-size: 18px; min-width: 56px; }
  .reset-btn { width: 40px; height: 40px; font-size: 20px; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
