/* Devinade : feuille de style unique, mobile d'abord (380 px). */
:root {
  --accent: #2563c9;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1b1d21;
  --muted: #5d636e;
  --line: #dcd8cf;
  --exact: #17803d;
  --exact-text: #ffffff;
  --close: #e9b829;
  --close-text: #1b1d21;
  --wrong: #6b7280;
  --wrong-text: #ffffff;
  --link: var(--accent);
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417;
    --surface: #1c1f24;
    --text: #eceef1;
    --muted: #a3a9b4;
    --line: #2f343c;
    --exact: #1f8a4c;
    --close: #d9a91f;
    --wrong: #444b56;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --link: #8fb3ef;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121417;
  --surface: #1c1f24;
  --text: #eceef1;
  --muted: #a3a9b4;
  --line: #2f343c;
  --exact: #1f8a4c;
  --close: #d9a91f;
  --wrong: #444b56;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  --link: #8fb3ef;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--link); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { width: 100%; max-width: 560px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* Barre du haut */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding-block: 10px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 3px solid var(--accent);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--text);
  cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.lang { font-size: 0.8rem; font-weight: 800; border: 2px solid var(--line); width: 40px; }

/* Modes de jeu */
.modes {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--text) 7%, var(--bg)); border-radius: 12px;
}
.modes button, .levels button {
  min-height: 40px; padding: 0 8px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font-weight: 700; font-size: 0.92rem; cursor: pointer;
}
.modes button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.levels { display: inline-flex; gap: 4px; margin: -4px 0 10px; padding: 3px; border: 2px solid var(--line); border-radius: 999px; }
.levels button { min-height: 32px; padding: 0 14px; border-radius: 999px; font-size: 0.85rem; }
.levels button[aria-checked="true"] { background: var(--accent); color: #fff; }
/* Indices */
.hints { margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--line); }
.hints h2 { margin: 0 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.hints ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hint-item { font-size: 0.92rem; }
.hint-item.locked { color: var(--muted); font-size: 0.85rem; }
.hint-item.open strong::after { content: " :"; }
:lang(en) .hint-item.open strong::after { content: ":"; }
.hint-btn {
  width: 100%; min-height: 40px; padding: 0 12px; text-align: left; cursor: pointer; font-weight: 700; font-size: 0.9rem;
  border: 2px solid var(--accent); border-radius: 8px; background: transparent; color: var(--text);
}
.record { margin: -4px 0 10px; color: var(--muted); }
.record strong { color: var(--exact); }
.end-sub { margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }

main.wrap { flex: 1; padding-top: 12px; padding-bottom: 24px; }
.intro { margin: 0 0 4px; color: var(--muted); font-size: 0.95rem; }
.meta-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; }
.meta-row .meta { margin: 0; }
.btn.ghost.skip { min-height: 34px; padding: 0 12px; font-size: 0.85rem; flex: none; }
.meta { margin: 0 0 12px; font-weight: 700; font-size: 0.9rem; }

/* Saisie */
.guess-form { display: flex; gap: 8px; margin-bottom: 14px; position: relative; }
.combo { position: relative; flex: 1; }
.combo input {
  width: 100%; height: 48px; padding: 0 14px;
  font-size: 1.05rem; /* 16 px min : pas de zoom auto sur iOS */
  color: var(--text); background: var(--surface);
  border: 2px solid var(--line); border-radius: var(--radius);
}
.combo input:focus { border-color: var(--accent); outline: none; }
.combo ul {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 50vh; overflow-y: auto;
}
.combo li {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  min-height: 44px; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.combo li[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.combo li.empty { color: var(--muted); cursor: default; }
.hint { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-weight: 700;
  cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn:active { transform: translateY(1px); }

/* Plateau */
.tiles { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 4px; }
.tiles.header { margin-bottom: 4px; }
.col-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); text-align: center; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.guess-name { font-weight: 700; font-size: 0.95rem; margin: 0 0 4px; display: flex; align-items: baseline; gap: 6px; }
.guess-name .num {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 50%;
  background: var(--line); color: var(--text); font-size: 0.72rem;
}
.tile {
  position: relative;
  min-height: 64px; padding: 14px 3px 6px;
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  text-align: center; line-height: 1.15;
  font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; hyphens: auto;
}
.tile .sym { position: absolute; top: 2px; right: 5px; font-size: 0.72rem; opacity: 0.9; }
.tile .big { font-size: 1.25rem; line-height: 1.1; }
.tile.exact { background: var(--exact); color: var(--exact-text); }
.tile.close { background: var(--close); color: var(--close-text); }
.tile.wrong { background: var(--wrong); color: var(--wrong-text); }
.tile.flip { animation: flip 0.45s ease both; }
@keyframes flip {
  0% { transform: rotateX(90deg); opacity: 0.2; }
  100% { transform: rotateX(0); opacity: 1; }
}
.guess.win .tiles { animation: pop 0.4s ease 0.8s both; }
@keyframes pop { 50% { transform: scale(1.04); } }
@media (prefers-reduced-motion: reduce) {
  .tile.flip, .guess.win .tiles { animation: none; }
}

/* Fin de partie */
.end {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px; text-align: center;
  border-top: 4px solid var(--accent);
}
.end-title { margin: 0 0 10px; font-size: 1.15rem; font-weight: 800; }
.answer-card { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; text-align: left; }
.answer-card .card-img { font-size: 3.2rem; line-height: 1; flex: none; }
.answer-card .card-img:empty { display: none; }
.answer-card .card-lines { display: grid; gap: 2px; }
.answer-card strong { font-size: 1.3rem; }
.answer-card .card-lines span { color: var(--muted); }
.culture { text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.culture p { margin: 0; line-height: 1.45; }
.culture .about + .trivia { margin-top: 10px; }
.culture h3 { font-size: 0.95rem; margin: 0 0 4px; }
.culture .wiki { display: inline-block; margin-top: 10px; font-size: 0.9rem; }
.end-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.end-actions .share { min-width: 160px; }
.countdown { margin: 14px 0 0; color: var(--muted); }
.countdown time { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.countdown.small { font-size: 0.9rem; text-align: center; }
.others { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.others h2 { font-size: 0.95rem; margin: 0 0 8px; }
.others ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.others .btn { width: 100%; }

.banner {
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}
.banner[hidden] { display: none; }
.error { padding: 16px; border-radius: var(--radius); background: var(--surface); }

/* Dialogues */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dlg { position: relative; padding: 18px 18px 20px; }
.dlg-close { position: absolute; top: 8px; right: 8px; font-size: 1.1rem; }
.dlg h2 { margin: 0 0 10px; font-size: 1.2rem; padding-right: 36px; }
.dlg h3 { margin: 18px 0 8px; font-size: 1rem; }
.legend, .attr-help { padding: 0; list-style: none; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.attr-help li { font-size: 0.95rem; }
.tile.mini { display: inline-grid; place-items: center; min-height: 0; width: 28px; height: 28px; padding: 0; }
.tile.mini .sym { position: static; font-size: 0.95rem; }
.arrow-demo { font-weight: 800; font-size: 1.1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-grid strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat-grid span { font-size: 0.72rem; color: var(--muted); }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); row-gap: 12px; }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dist li { display: flex; align-items: center; gap: 6px; }
.dist .k { width: 14px; font-weight: 700; text-align: right; }
.dist .bar {
  width: var(--w); min-width: 24px; padding: 2px 8px; text-align: right;
  background: var(--wrong); color: var(--wrong-text); font-weight: 700; border-radius: 4px; font-size: 0.85rem;
}
.dist .bar.today { background: var(--exact); color: var(--exact-text); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 0.95rem;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Pied de page */
.footer { padding-top: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.82rem; border-top: 1px solid var(--line); }
.footer p { margin: 4px 0; }

/* Accueil */
.niche-title { margin: 18px 0 8px; font-size: 1rem; }
.niches { display: flex; flex-wrap: wrap; gap: 8px; }
.niches button {
  min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700; font-size: 0.92rem;
}
.niches button[aria-checked="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.niche-block h3 { margin: 22px 0 0; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.game-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.game-card {
  width: 100%; display: flex; gap: 12px; align-items: center; padding: 14px; text-align: left; font: inherit; cursor: pointer;
  background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 6px solid var(--accent); color: var(--text); text-decoration: none;
}
.game-card .emoji { font-size: 1.8rem; flex: none; }
.game-card .txt { flex: 1; min-width: 0; }
.game-card strong { display: block; font-size: 1.05rem; }
.game-card .txt span { display: block; color: var(--muted); font-size: 0.86rem; }
.badge { flex: none; padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; white-space: nowrap; }
.badge.todo { background: var(--accent); color: #fff; }
.badge.progress { background: var(--close); color: var(--close-text); }
.badge.done { background: var(--exact); color: var(--exact-text); }

/* Pages de texte */
.prose { max-width: 640px; }
.prose h2 { font-size: 1.1rem; margin-top: 24px; }

.tiles[style*="--cols:6"] .tile { font-size: 0.7rem; padding-inline: 2px; }
.tiles[style*="--cols:6"] .tile .big { font-size: 1.1rem; }
.tiles[style*="--cols:6"] .col-label, .tiles.header[style*="--cols:6"] .col-label { font-size: 0.62rem; letter-spacing: 0; }

@media (min-width: 480px) {
  .tile { font-size: 0.85rem; min-height: 70px; }
}
