:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --text: #1d2433;
    --muted: #5b6577;
    --border: #d5dbe8;
    --accent: #2954c8;
    --accent-text: #ffffff;
    --ok: #1c7c3a;
    --ok-bg: #e3f5e9;
    --ko: #b3261e;
    --ko-bg: #fde8e6;
    --radius: 14px;
    color-scheme: light;
}

/* Thème sombre : celui du système tant que le joueur n'a pas choisi (data-theme absent), sinon son choix. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #12161f;
        --surface: #1c2230;
        --text: #eef1f8;
        --muted: #a2adc2;
        --border: #34405a;
        --accent: #7ea2ff;
        --accent-text: #0e1424;
        --ok: #6fd48d;
        --ok-bg: #153a24;
        --ko: #ff8f87;
        --ko-bg: #46201d;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #12161f;
    --surface: #1c2230;
    --text: #eef1f8;
    --muted: #a2adc2;
    --border: #34405a;
    --accent: #7ea2ff;
    --accent-text: #0e1424;
    --ok: #6fd48d;
    --ok-bg: #153a24;
    --ko: #ff8f87;
    --ko-bg: #46201d;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

.app {
    max-width: 760px;
    margin: 0 auto;
    /* Marge basse confortable : le bouton « Rejouer » ne doit pas coller au bas de l'écran. */
    padding: 16px 16px 56px;
}

.top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-bottom: 8px;
}

h1 { font-size: clamp(1.1rem, 4.6vw, 1.4rem); margin: 0; }

/* Outils en haut à droite : score + difficulté + thème */
.tools { position: relative; display: flex; align-items: center; gap: 8px; margin-left: auto; }
.score {
    margin: 0;
    padding: 6px 12px;
    white-space: nowrap;
    color: var(--muted);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.score strong { color: var(--text); font-variant-numeric: tabular-nums; }
.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 6px 12px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn.icon { justify-content: center; width: 40px; padding: 0; font-size: 1.2rem; line-height: 1; }
.tool-label { color: var(--muted); }
@media (max-width: 480px) { .tool-label { display: none; } }

.dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 10;
    display: grid;
    gap: 4px;
    width: min(320px, calc(100vw - 32px));
    padding: 6px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.menu-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    text-align: left;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 10px;
}
.menu-item:hover { background: var(--bg); }
.menu-item[aria-current="true"] { border-color: var(--accent); }
.menu-item-name { font-weight: 700; }
.menu-item-desc { font-size: .9rem; color: var(--muted); }

/* Menu du sens du jeu : « Pays → Capitale » / « Capitale → Pays » */
.sens {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin: 4px 0 12px;
    padding: 4px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.sens-btn {
    padding: 8px 10px;
    font-weight: 600;
    background: transparent;
    border: 0;
    border-radius: 999px;
}
.sens-btn:hover { background: var(--bg); }
.sens-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.lead { font-size: 1.1rem; color: var(--muted); }
[hidden] { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Menu */
.modes { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .modes { grid-template-columns: 1fr 1fr; } }

.mode {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    padding: 18px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.mode:hover { border-color: var(--accent); }
.mode-name { font-size: 1.25rem; font-weight: 700; }
.mode-desc { color: var(--muted); }

/* Jeu */
.prompt { font-size: 1.15rem; margin: 16px 0 0; }
.number {
    margin: 0 0 16px;
    font-size: clamp(5rem, 28vw, 9rem);
    font-weight: 800;
    line-height: 1.05;
    text-align: center;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
/* La question (un pays ou une capitale) s'affiche en grand. */
.number.is-name {
    font-size: clamp(2.2rem, 11vw, 4.2rem);
    line-height: 1.15;
    text-wrap: balance;
    overflow-wrap: anywhere;
}

.choices { display: grid; gap: 10px; }
.choices-facile { grid-template-columns: 1fr; }
/* 4 choix : un carré 2 × 2, sur mobile comme sur ordinateur. */
.choices-moyen, .choices-difficile { grid-template-columns: 1fr 1fr; }

.choice {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 68px;
    padding: 12px 10px;
    font-size: 1.15rem;
    font-weight: 600;
    text-align: center;
    overflow-wrap: break-word;
    hyphens: auto;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
@media (max-width: 480px) { .choice { padding: 10px 6px; font-size: 1rem; } }
.choice:not(:disabled):hover { border-color: var(--accent); }

/* Expert : 199 tags compacts dans un panneau qui défile, la question reste visible au-dessus. */
.choices-expert {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    min-height: 140px;
    overflow-y: auto;
    padding: 10px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.tag-group { display: flex; align-items: flex-start; gap: 8px; }
.tag-list { display: flex; flex-wrap: wrap; flex: 1; gap: 6px; min-width: 0; }
.tag-letter {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    font-size: .9rem;
    font-weight: 800;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 50%;
}
.tag {
    padding: 4px 11px;
    font-size: .92rem;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 999px;
}
.tag:not(:disabled):hover { border-color: var(--accent); }

.choice.ok, .tag.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.choice.ko, .tag.ko { background: var(--ko-bg); border-color: var(--ko); color: var(--ko); font-weight: 700; }

.expert-form { display: flex; gap: 10px; }
.expert-form input {
    flex: 1;
    min-width: 0;
    padding: 14px;
    font: inherit;
    font-size: 1.15rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.expert-form input:disabled { opacity: .7; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-weight: 600;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.btn svg { flex: none; width: 1.25em; height: 1.25em; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .6; }

.error { color: var(--ko); font-weight: 600; margin: 12px 0 0; }

/* Résultat */
.result { margin-top: 20px; }
.verdict { font-size: 1.4rem; font-weight: 700; margin: 0 0 12px; }
.verdict.ok { color: var(--ok); }
.verdict.ko { color: var(--ko); }

.cards { display: grid; gap: 10px; }
.card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border: 2px solid;
    border-radius: var(--radius);
}
.card.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.card.ko { background: var(--ko-bg); border-color: var(--ko); color: var(--ko); }
.card-icon { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.card-body { display: grid; gap: 2px; min-width: 0; }
.card-name { font-size: 1.25rem; font-weight: 800; overflow-wrap: anywhere; }
.card-capital { font-size: 1.05rem; overflow-wrap: anywhere; }
.card-region { font-size: .95rem; opacity: .9; }
.card-note { margin-top: 4px; font-size: .9rem; font-style: italic; color: var(--text); opacity: .85; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; scroll-margin-bottom: 32px; }
.choices-hint { margin: 14px 0 8px; color: var(--muted); }

/* « Localiser » : fenêtre avec la carte du monde cliquable */
.map-dialog {
    width: min(960px, calc(100vw - 16px));
    max-height: calc(100vh - 16px);
    padding: 12px;
    overflow-y: auto;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.map-dialog::backdrop { background: rgba(8, 12, 22, .65); }
.map-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.map-title { margin: 0; font-size: clamp(1.05rem, 4vw, 1.3rem); }
.map-zoom { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.map-tip { color: var(--muted); font-size: .85rem; }
@media (max-width: 480px) { .map-tip { display: none; } }

.map-view {
    height: clamp(260px, 46vh, 640px);
    overflow: hidden;
    color: var(--muted);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.map-svg { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.map-svg:active { cursor: grabbing; }
/* Océan : fond légèrement bleuté ; pays du jeu cliquables ; territoires (Groenland, Sahara occidental…) en gris. */
.map-svg .ocean { fill: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.map-svg [data-code] {
    fill: var(--border);
    fill: color-mix(in srgb, var(--accent) 24%, var(--surface));
    stroke: var(--surface);
    stroke-width: .7;
    vector-effect: non-scaling-stroke;
    cursor: pointer;
}
.map-svg .terr { fill: var(--border); stroke: var(--surface); stroke-width: .5; vector-effect: non-scaling-stroke; }
/* Point des petits pays : même couleur que les pays, cerclé pour rester visible sur l'océan. */
.map-svg circle.dot {
    fill: color-mix(in srgb, var(--accent) 45%, var(--surface));
    fill-opacity: .85;
    stroke: var(--accent);
    stroke-width: 1;
}
.map-svg:not(.done) [data-code]:hover { fill: var(--accent); fill-opacity: 1; }
.map-svg .ok { fill: var(--ok) !important; fill-opacity: 1; stroke: var(--text); stroke-width: 1.5; }
.map-svg .ko { fill: var(--ko) !important; fill-opacity: 1; stroke: var(--text); stroke-width: 1.5; }
.map-svg.done [data-code] { cursor: default; }
.map-feedback { margin-top: 12px; }
.map-credit { margin: 14px 0 0; font-size: .8rem; color: var(--muted); }
.map-credit a { color: inherit; }
.map-dialog .actions { scroll-margin-bottom: 16px; }