:root {
  --bg: #FFF8F3;
  --primary: #FF6B9D;
  --primary-light: #FF8FB3;
  --primary-dark: #E85585;
  --secondary: #5EC9F2;
  --accent: #FFD93D;
  --danger: #FF6B6B;
  --card: #FFFFFF;
  --text: #2D3142;
  --text-light: #6C7293;
  --border: #F0E6DD;
  --board-bg: #FFE8DD;
  --cell-hidden: #FF8FB3;
  --cell-hidden-dark: #E85585;
  --cell-open: #FFF0E6;
  --cell-open-alt: #FFE8DD;
  --shadow: 0 8px 24px rgba(45, 49, 66, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 64px 12px 12px;
  flex-direction: column;
}

#ui-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  z-index: 5;
}
.ui-row { display: flex; gap: 8px; align-items: center; }
.ui-pill {
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(45,49,66,0.08);
  font-size: 0.9rem;
  white-space: nowrap;
}
.ui-label { font-weight: 600; color: var(--text-light); margin-right: 4px; font-size: 0.78rem; }

#pause-btn,
#mute-btn,
#flag-btn {
  background: rgba(255,255,255,0.92);
  border: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(45,49,66,0.08);
  transition: transform 0.12s ease, background 0.12s ease;
}
#flag-btn.active {
  background: var(--primary);
  color: #fff;
}

#difficulty-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 4px 0 10px;
  flex-wrap: wrap;
}
.diff-btn {
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text-light);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.diff-btn--active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(255,107,157,0.3);
}

#board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
}
#board {
  display: grid;
  background: var(--board-bg);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
  gap: 2px;
  touch-action: manipulation;
}

.cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, var(--cell-hidden), var(--cell-hidden-dark));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  position: relative;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.4), inset -1px -1px 0 rgba(0,0,0,0.1);
  transition: transform 0.08s ease, background 0.12s ease;
  color: transparent;
}
.cell:active { transform: scale(0.94); }

.cell.flag {
  background: linear-gradient(135deg, #FFD93D, #FF9F45);
}
.cell.flag::after {
  content: '🚩';
  font-size: 0.78em;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2));
}

.cell.open {
  background: var(--cell-open);
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: default;
}
.cell.open.alt {
  background: var(--cell-open-alt);
}
.cell.open.n1 { color: #2C7BE5; }
.cell.open.n2 { color: #6BCB77; }
.cell.open.n3 { color: #FF6B6B; }
.cell.open.n4 { color: #1B4F8F; }
.cell.open.n5 { color: #A03333; }
.cell.open.n6 { color: #2BAEC0; }
.cell.open.n7 { color: #2D3142; }
.cell.open.n8 { color: #6C7293; }

.cell.mine {
  background: var(--danger) !important;
  color: #fff;
}
.cell.mine::after {
  content: '💣';
  font-size: 0.85em;
}
.cell.mine.exploded {
  background: #C0392B !important;
  animation: shake 0.35s ease;
}
.cell.wrong-flag {
  background: #C0392B !important;
}
.cell.wrong-flag::after {
  content: '✕';
  color: #fff;
  font-size: 0.9em;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 49, 66, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal__inner {
  background: var(--card);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal__inner h2 { margin: 0 0 8px; font-size: 1.6rem; }
.modal__inner p { margin: 0 0 16px; color: var(--text-light); }
.big-score { font-size: 1.4rem !important; color: var(--text) !important; font-weight: 800; margin: 4px 0 !important; }
.sub-score { font-size: 0.95rem; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 107, 157, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }

.ad-slot {
  margin-top: 16px;
  min-height: 100px;
}
