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

:root {
  --bg-1: #fdf3ea;
  --bg-2: #fbe6d2;
  --surface: #ffffff;
  --surface-alt: #fdf6ee;
  --text: #2e2015;
  --text-dim: #8a7460;
  --primary: #c97a2b;
  --primary-dark: #a5601c;
  --primary-contrast: #ffffff;
  --accent: #2b8fc9;
  --success: #2fb380;
  --success-bg: #e4f8f0;
  --danger: #e14b4b;
  --danger-bg: #fdeaea;
  --border: #f0ddc8;
  --shadow: 0 8px 24px rgba(140, 90, 30, 0.14);
  --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: #1b140d;
    --bg-2: #251b10;
    --surface: #2a2015;
    --surface-alt: #322619;
    --text: #f7ece0;
    --text-dim: #c2ab93;
    --primary: #e8a35c;
    --primary-dark: #f0b876;
    --primary-contrast: #241705;
    --accent: #6cb8ea;
    --success: #4fd6a2;
    --success-bg: #17362d;
    --danger: #ff7a7a;
    --danger-bg: #3a1c1c;
    --border: #402f1d;
    --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: 520px; 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; }
.view { flex: 1; display: flex; flex-direction: column; }

.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); }

.btn {
  border: none; border-radius: 14px; padding: 12px 14px; font-weight: 700; font-size: 14px;
  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(201,122,43,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; }

/* ---------- Chargement ---------- */
.loading-box { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text-dim); }
.loading-spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 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: 56px; text-align: center;
}

.board-scroller { display: flex; justify-content: center; margin-bottom: 12px; }
.board {
  display: grid; grid-template-columns: repeat(9, 1fr); width: min(100%, 440px); aspect-ratio: 1;
  background: var(--text); border: 2px solid var(--text); border-radius: 8px; overflow: hidden;
  gap: 1px;
}
.sud-cell {
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  font-size: clamp(14px, 4.4vw, 20px); font-weight: 700; cursor: pointer; position: relative;
}
.sud-cell.given { color: var(--text); font-weight: 800; }
.sud-cell.entered { color: var(--primary); }
.sud-cell.wrong { color: var(--danger); }
.sud-cell.selected { background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.sud-cell.peer { background: var(--surface-alt); }
.sud-cell.same-value { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
.sud-cell.border-right { border-right: 2px solid var(--text); }
.sud-cell.border-bottom { border-bottom: 2px solid var(--text); }

.sud-notes { position: absolute; inset: 2px; display: grid; grid-template-columns: repeat(3, 1fr); font-size: clamp(7px, 1.9vw, 9.5px); color: var(--text-dim); font-weight: 700; }
.sud-notes span { display: flex; align-items: center; justify-content: center; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.tool-btn { flex: 1; font-size: 12.5px; padding: 10px 6px; }
.tool-btn.active { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
#hint-count { opacity: .8; }

.numpad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.num-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 0; font-size: 17px; font-weight: 800; color: var(--text); cursor: pointer;
}
.num-btn:active { transform: scale(0.95); }
.num-btn.exhausted { opacity: .3; }

/* ---------- Modale fin de partie ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(30, 20, 10, 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; }
