:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6a6f76;
  --line: #d8d6d0;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --error: #d6336c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #22242a;
    --text: #e8e8ea;
    --muted: #9a9ea6;
    --line: #3a3d44;
    --accent: #7a95ff;
    --accent-text: #10121a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
.topbar {
  display: flex; align-items: center; gap: 8px;
  max-width: 520px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px 6px;
}
.topbar h1 { flex: 1; font-size: 1.2rem; margin: 0; }
.topbar .back { font-size: 1.8rem; line-height: 1; color: var(--muted); text-decoration: none; padding: 0 4px; }
.topbar .back:hover { color: var(--text); }
main { max-width: 520px; margin: 0 auto; padding: 0 16px 32px; }

button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 14px; min-height: 40px; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.icon { font-size: 1.2rem; width: 42px; padding: 0; }

.modes { display: flex; gap: 8px; margin: 8px 0 12px; }
.modes button { flex: 1; }
.modes button[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }

.status { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 10px; }
.status b { color: var(--text); font-variant-numeric: tabular-nums; }

.board {
  display: grid; gap: 12px; width: 100%; max-width: 420px; aspect-ratio: 1; margin: 0 auto;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.board.n4 { grid-template-columns: repeat(2, 1fr); }
.board.n9 { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pad {
  border: 0; border-radius: 18px; padding: 0; min-height: 0;
  background: var(--c); opacity: .38; filter: saturate(.8);
  transition: opacity .12s, transform .12s, filter .12s, box-shadow .12s;
}
.board.n9 .pad { border-radius: 14px; }
.pad.lit { opacity: 1; filter: saturate(1.15) brightness(1.08); transform: scale(1.04);
           box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--c); }
.pad.wrong { opacity: 1; box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--error); }
.board.input .pad { cursor: pointer; }
.board.input .pad:hover { opacity: .55; }
.board:not(.input) .pad { cursor: default; }
@media (prefers-reduced-motion: reduce) { .pad, .pad.lit { transition: none; transform: none; } }

.message { text-align: center; min-height: 3em; margin: 14px 0 6px; }
.message.error { color: var(--error); font-weight: 600; }
.message.good { color: #2f9e44; font-weight: 600; }
.actions { display: flex; justify-content: center; }
.actions button { min-width: 160px; }

/* ---------- menu et fenêtres ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 20px 22px; width: min(92vw, 440px); max-width: 92vw;
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin: 0 0 10px; font-size: 1.2rem; }
h3 { font-size: 1rem; margin: 0 0 4px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog.drawer {
  margin: 0 0 0 auto; height: 100%; max-height: 100%;
  width: min(86vw, 340px); max-width: 86vw;
  border-radius: 0; border: none; border-left: 1px solid var(--line);
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
}
dialog.drawer:not([open]) { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.drawer-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); padding-top: 8px; }
.menu-list button, .menu-list a {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: none;
  border-radius: 8px; min-height: 46px; padding: 8px 10px; font-size: 1rem; color: var(--text); text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover,
.menu-list button:focus-visible, .menu-list a:focus-visible { background: rgba(127, 127, 127, .12); outline: none; }
.version { margin-top: auto; text-align: center; color: var(--muted); font-size: .75rem; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.small { font-size: .85rem; }
.muted { color: var(--muted); margin: 0 0 8px; }
.error { color: var(--error); margin: 0; font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; border-top: 1px solid var(--line); }
.stack label { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; color: var(--muted); }
.stack button { align-self: flex-start; }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

#top { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 12px;
       max-height: 55vh; overflow: auto; }
#top li { display: flex; gap: 10px; padding: 7px 12px; border-top: 1px solid var(--line); }
#top li:first-child { border-top: 0; }
#top li.mine { font-weight: 700; color: var(--accent); }
#top .rank { width: 2em; color: var(--muted); font-variant-numeric: tabular-nums; }
#top .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top .score { font-variant-numeric: tabular-nums; }
#top .empty { color: var(--muted); }
