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

body {
  background: #202124;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8eaed;
  user-select: none;
  -webkit-user-select: none;
}

#back-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  color: #fff;
  text-decoration: none;
  font-size: 22px;
  font-weight: 700;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #5f6368;
  transition: background 0.2s;
  line-height: 1;
}

#back-btn:hover {
  background: #80868b;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 520px;
  padding: 0 4px;
}

.toolbar-icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

#mine-counter,
#timer-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
}

#timer-display {
  justify-content: flex-end;
}

#new-game-btn {
  background: #3c4043;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #e8eaed;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

#new-game-btn:hover {
  background: #5f6368;
}

#new-game-btn:active {
  transform: scale(0.95);
}

#best-time-display {
  font-size: 14px;
  color: #9aa0a6;
  text-align: center;
}

/* Difficulty */
#difficulty-bar {
  display: flex;
  gap: 6px;
  background: #292a2d;
  padding: 4px;
  border-radius: 12px;
}

.diff-btn {
  padding: 8px 22px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #9aa0a6;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.diff-btn:hover {
  color: #e8eaed;
}

.diff-btn.active {
  background: #4caf50;
  color: #fff;
}

/* Board */
#board {
  display: grid;
  gap: 0;
  background: #3c4043;
  padding: 0;
  border-radius: 0;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.cell {
  width: 38px;
  height: 38px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.08s, transform 0.1s;
  position: relative;
  border: none;
  outline: none;
  padding: 0;
}

.cell.hidden {
  background: #5f9b3c;
}

.cell.hidden:hover {
  background: #6eac48;
  transform: scale(1.05);
}

.cell.hidden:active {
  transform: scale(0.94);
}

.cell.hidden.alt {
  background: #57903a;
}

.cell.hidden.alt:hover {
  background: #6eac48;
}

.cell.revealed {
  background: #d7c9a5;
  cursor: default;
}

.cell.revealed.alt {
  background: #d2c49e;
}

.cell.flagged {
  background: #5f9b3c;
}

.cell.flagged.alt {
  background: #57903a;
}

.cell.mine-hit {
  background: #e53935;
}

.cell.mine-shown {
  background: #d7c9a5;
}

.cell.mine-shown.alt {
  background: #d2c49e;
}

/* Number colors like Google minesweeper */
.cell.n1 { color: #1976d2; }
.cell.n2 { color: #388e3c; }
.cell.n3 { color: #e53935; }
.cell.n4 { color: #7b1fa2; }
.cell.n5 { color: #ff8f00; }
.cell.n6 { color: #00897b; }
.cell.n7 { color: #5d4037; }
.cell.n8 { color: #78909c; }

.flag-icon {
  font-size: 18px;
  line-height: 1;
}

.mine-icon {
  font-size: 20px;
  line-height: 1;
}

#hint-text {
  font-size: 13px;
  color: #5f6368;
  margin-top: 4px;
}

/* Win / lose animations */
@keyframes cell-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.cell.reveal-anim {
  animation: cell-pop 0.2s ease-out forwards;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

#board.shake {
  animation: shake 0.35s ease-in-out;
}

@media (max-width: 640px) {
  .cell {
    width: 32px;
    height: 32px;
    font-size: 15px;
    border-radius: 0;
  }

  #toolbar {
    max-width: 100%;
  }

  .diff-btn {
    padding: 6px 16px;
    font-size: 13px;
  }
}

@media (max-width: 400px) {
  .cell {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }
}
