: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;
    padding: 16px;
}

.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 : difficulté + thème */
.tools { position: relative; display: flex; gap: 8px; margin-left: auto; }
.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 : « Numéro → Nom » / « Nom → Numéro » */
.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;
}
/* Sens « Nom → Numéro » : c'est le nom qui s'affiche en grand, moins grand qu'un numéro. */
.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, .choices-moyen { grid-template-columns: 1fr; }
@media (min-width: 560px) { .choices-moyen { grid-template-columns: 1fr 1fr; } }

.choice {
    padding: 16px;
    font-size: 1.15rem;
    font-weight: 600;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.choice:not(:disabled):hover { border-color: var(--accent); }

/* Difficile : 101 tags compacts dans un panneau qui défile, le numéro reste visible au-dessus. */
.choices-difficile {
    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 {
    padding: 14px 20px;
    font-weight: 600;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}
.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; grid-template-columns: auto 1fr; column-gap: 12px; align-items: baseline; }
.card-code { font-size: 1.8rem; font-weight: 800; grid-row: span 2; }
.card-name { font-size: 1.2rem; font-weight: 700; }
.card-region { font-size: .95rem; opacity: .9; grid-column: 2; }
.card-body > .card-name:first-child { grid-column: 1 / -1; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
