/* ===========================================================
   Démineur — styles
   Mobile-first, compatible iOS Safari / Android Chrome & Firefox
   =========================================================== */

:root {
  --bg-1: #eef4fb;
  --bg-2: #dce9f7;
  --surface: #ffffff;
  --surface-alt: #f3f7fc;
  --text: #172433;
  --text-dim: #5c6c7d;
  --primary: #3a6ea5;
  --primary-dark: #2b5580;
  --primary-contrast: #ffffff;
  --accent: #f2a541;
  --success: #2fb380;
  --success-bg: #e4f8f0;
  --danger: #e14b4b;
  --danger-bg: #fdeaea;
  --border: #d9e3ef;
  --shadow: 0 8px 24px rgba(40, 70, 110, 0.12);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #10161f;
    --bg-2: #16202c;
    --surface: #1c2733;
    --surface-alt: #212e3c;
    --text: #eef3f9;
    --text-dim: #9aabbc;
    --primary: #6ea3d8;
    --primary-dark: #8fbaea;
    --primary-contrast: #0c1620;
    --accent: #f6b85c;
    --success: #4fd6a2;
    --success-bg: #17362d;
    --danger: #ff7a7a;
    --danger-bg: #3a1c1c;
    --border: #2b3947;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior-y: contain; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% -10%, var(--bg-2), var(--bg-1) 60%);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
}

.page {
  max-width: 640px; margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
  min-height: 100dvh; display: flex; flex-direction: column;
}

.view.hidden { display: none; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.game-title { font-size: 19px; margin: 0; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: 42px; height: 42px; font-size: 18px; cursor: pointer; text-decoration: none;
  color: var(--text); display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(0.95); }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.intro-card { margin-bottom: 18px; }
.intro-card p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.55; }

.btn {
  border: none; border-radius: 14px; padding: 13px 18px; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 6px 16px rgba(58,110,165,0.35); }
.btn-secondary { background: var(--surface-alt); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost { background: var(--surface); color: var(--text-dim); border: 1.5px solid var(--border); }
.btn-big { width: 100%; padding: 15px; font-size: 16px; }

/* ---------- Choix de la difficulté ---------- */
.diff-list { display: flex; flex-direction: column; gap: 12px; }
.diff-card {
  display: flex; align-items: center; gap: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
}
.diff-card:active { transform: scale(0.98); }
.diff-emoji { font-size: 28px; width: 48px; text-align: center; flex-shrink: 0; }
.diff-info { flex: 1; }
.diff-info strong { display: block; font-size: 16px; }
.diff-info span { font-size: 12.5px; color: var(--text-dim); }
.diff-best { font-size: 12px; font-weight: 700; color: var(--success); white-space: nowrap; }

/* ---------- Jeu ---------- */
.game-stats { display: flex; gap: 8px; }
.stat-pill {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 9px 12px; font-weight: 700; font-size: 14px; min-width: 64px; text-align: center;
}

.board-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.toggle-btn { font-size: 13px; padding: 9px 14px; }
.toggle-btn.active { background: var(--accent); color: #2a1c00; border-color: var(--accent); }
.hint-text { font-size: 11.5px; color: var(--text-dim); flex: 1; min-width: 160px; text-align: right; }

.board-scroller { overflow: auto; flex: 1; display: flex; justify-content: center; padding-bottom: 8px; }
.board {
  display: grid; gap: 2px; background: var(--border); border: 2px solid var(--border);
  border-radius: 10px; padding: 2px; width: max-content; margin: 0 auto;
}

.cell {
  width: 30px; height: 30px; background: var(--surface-alt); border-radius: 4px;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800;
  cursor: pointer;
}
.cell.hidden-cell { background: var(--surface); box-shadow: inset 0 -2px 0 rgba(0,0,0,.08), inset 0 2px 0 rgba(255,255,255,.5); }
.cell.hidden-cell:active { filter: brightness(0.94); }
.cell.revealed { background: var(--surface-alt); cursor: default; }
.cell.flagged { background: var(--surface); font-size: 15px; }
.cell.mine-cell { background: var(--danger-bg); }
.cell.mine-hit { background: var(--danger); }
.cell.n1 { color: #2f6fd8; } .cell.n2 { color: #2fa54f; } .cell.n3 { color: #d84545; }
.cell.n4 { color: #6a3fc9; } .cell.n5 { color: #b8631f; } .cell.n6 { color: #1f9e9e; }
.cell.n7 { color: #333; } .cell.n8 { color: #777; }

/* ---------- Modale fin de partie ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 16, 24, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: 22px; padding: 26px 22px; max-width: 360px; width: 100%;
  text-align: center; box-shadow: var(--shadow);
}
.modal-emoji { font-size: 44px; margin-bottom: 6px; }
.modal h2 { margin: 0 0 8px; }
.modal p { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }

@media (min-width: 640px) {
  .cell { width: 34px; height: 34px; font-size: 15px; }
}
