:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  /* Bleu / orange : couple lisible par la plupart des daltoniens. */
  --accent: #f59e0b;
  --accent-text: #1a1204;
  --ok: #38bdf8;
  --error: #fda4af;
  --energy: #22d3ee;
  --radius: 14px;
  --tap: 52px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); margin: 0; font-size: .9rem; }
:focus-visible { outline: 3px solid var(--ok); outline-offset: 2px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: var(--tap); padding: 0 20px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform .1s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-big { width: 100%; min-height: 60px; font-size: 1.15rem; }
.btn-ghost { background: transparent; width: 100%; }
.btn-energy {
  background: transparent; border-color: var(--energy); color: var(--energy);
  text-align: center; margin-top: 8px;
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  border: 0; border-radius: 50%; background: var(--surface); color: var(--text);
  font-size: 1.3rem; cursor: pointer;
}

/* ---------- Accueil ---------- */
.home { text-align: center; padding-top: 4vh; }
.logo { font-size: 3.5rem; line-height: 1; }
h1 { font-size: 2.2rem; margin: .2em 0 0; letter-spacing: -.02em; }
.tagline { color: var(--muted); margin: .2em 0 1.2em; }
.rules {
  text-align: left; margin: 0 0 1.4em; padding: 16px 16px 16px 40px;
  background: var(--surface); border-radius: var(--radius);
}
.rules li + li { margin-top: .5em; }
.modes { border: 0; padding: 0; margin: 0 0 1.2em; display: grid; gap: 10px; }
.modes legend { color: var(--muted); margin-bottom: 8px; padding: 0; font-size: .95rem; }
.mode { display: block; cursor: pointer; }
.mode input { position: absolute; opacity: 0; }
.mode > span {
  display: flex; justify-content: space-between; align-items: center;
  min-height: var(--tap); padding: 10px 16px;
  border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.mode small { color: var(--muted); }
.mode input:checked + span { border-color: var(--accent); background: var(--surface-2); }
.mode input:checked + span strong::before { content: "✓ "; color: var(--accent); }
.mode input:focus-visible + span { outline: 3px solid var(--ok); outline-offset: 2px; }

/* ---------- Partie ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar-title { flex: 1; text-align: center; }
.topbar h2 { margin: 0; font-size: 1.25rem; }

.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; }
#guess-input {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 1.05rem;
}
#guess-input:focus { border-color: var(--accent); outline: none; }
.suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.suggestions li {
  min-height: 48px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-radius: 10px; cursor: pointer;
}
.suggestions li[aria-selected="true"] { background: var(--border); }

.message { min-height: 1.45em; margin: 8px 2px; font-size: .95rem; color: var(--muted); }
.message.error { color: var(--error); }

.guesses { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.guess {
  display: grid; gap: 4px 10px; align-items: center;
  grid-template-columns: 1fr auto 1.2fr;
  grid-template-areas: "name name name" "dist dir prox";
  padding: 10px 12px; min-height: 64px;
  background: var(--surface); border: 2px solid transparent; border-radius: var(--radius);
}
.guess.empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; color: var(--border); background: transparent;
  border: 2px dashed var(--surface-2); font-weight: 700;
}
.guess.correct { border-color: var(--ok); }
.guess.new { animation: pop .35s ease-out; }
.g-name { grid-area: name; font-weight: 700; }
.g-dist { grid-area: dist; font-variant-numeric: tabular-nums; }
.g-dir { grid-area: dir; display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.arrow {
  display: inline-block; font-size: 1.3rem; line-height: 1;
  transform: rotate(var(--rot)); transition: transform .4s ease;
}
.g-prox { grid-area: prox; display: flex; align-items: center; gap: 6px; }
.g-prox .bar {
  flex: 1; height: 8px; border-radius: 4px;
  /* Remplissage hachuré : la proportion se lit aussi sans couleur. */
  background: var(--surface-2) repeating-linear-gradient(135deg, var(--accent) 0 6px, #fbbf24 6px 10px) no-repeat;
  background-size: var(--p) 100%;
}
.g-prox b { font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: right; }
.guess.correct .g-prox .bar { background-image: none; background-color: var(--ok); }

/* ---------- Fin de partie ---------- */
.end { display: grid; gap: 14px; }
.end.appear { animation: rise .45s ease-out; }
.end-title { margin: 0; font-size: 1.4rem; text-align: center; }
.end-title:focus { outline: none; }
.end-answer { margin: 0; text-align: center; font-size: 1.1rem; }
.share-preview {
  margin: 0; padding: 12px; background: var(--surface); border-radius: var(--radius);
  font: inherit; font-size: .95rem; white-space: pre-wrap; line-height: 1.5;
}
.countdown { text-align: center; margin: 0; color: var(--muted); }
.countdown time { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.2rem; }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0; text-align: center;
}
.stats div { background: var(--surface); border-radius: 10px; padding: 8px 4px; }
.stats dt { font-size: .75rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; }
.dist-title { margin: 12px 0 6px; font-size: .9rem; color: var(--muted); }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dist li { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
.dist li > span:first-child { width: 1em; text-align: right; }
.dist-bar {
  width: var(--w); min-width: 1.8em; padding: 1px 6px; text-align: right;
  background: var(--surface-2); border-radius: 4px; font-weight: 700;
}
.dist li.hl .dist-bar { background: var(--accent); color: var(--accent-text); }
.dist li.hl > span:first-child::after { content: "★"; color: var(--accent); margin-left: -2px; }

dialog {
  width: min(92vw, 440px); padding: 20px; border: 1px solid var(--border);
  border-radius: 18px; background: var(--bg); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 0; }
dialog form { margin-top: 16px; }

@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Mini-carte ---------- */
.end-map { background: var(--surface); border-radius: var(--radius); padding: 8px; }
.map { display: block; width: 100%; max-height: 360px; }
.m-land { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.m-dot { fill: var(--muted); opacity: .45; }
.m-line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; opacity: .7; }
.m-guess { fill: var(--accent); stroke: var(--bg); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.m-num { fill: var(--accent-text); font-weight: 800; text-anchor: middle; dominant-baseline: central; }
.m-target { fill: none; stroke: var(--ok); stroke-width: 3; vector-effect: non-scaling-stroke; }
.m-star { fill: var(--ok); text-anchor: middle; dominant-baseline: central; }

/* ---------- Transfert des statistiques ---------- */
.transfer { margin-top: 16px; }
.transfer summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); }
.transfer textarea {
  width: 100%; margin: 8px 0; padding: 10px; border: 2px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: .85rem/1.3 ui-monospace, monospace; resize: vertical;
}

/* ---------- Langue et installation ---------- */
.home { position: relative; }
.lang { position: absolute; top: 0; right: 0; display: flex; gap: 4px; }
.lang button {
  min-width: 48px; min-height: 44px; border: 2px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer;
}
.lang button[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }
.home .install-btn { margin-top: 10px; }
.install-steps { padding-left: 1.4em; }
.install-steps li + li { margin-top: .6em; }
