/* ===== Thèmes ===== */
:root {
  --bg: #f5f6fa;
  --bg-grad: radial-gradient(1200px 600px at 50% -200px, #e6e8ff 0%, transparent 70%);
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dde1ea;
  --text: #1b2232;
  --muted: #637087;
  --accent: #5b5bd6;
  --accent-strong: #4646c2;
  --accent-soft: #e9e9ff;
  --on-accent: #ffffff;
  --ok: #1f8f5f;
  --ok-soft: #dcf5e8;
  --ko: #d1453b;
  --ko-soft: #fde4e1;
  --gold: #c88a0a;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .08);
  --shadow-lg: 0 2px 4px rgba(20, 30, 60, .06), 0 18px 48px rgba(20, 30, 60, .14);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320;
    --bg-grad: radial-gradient(1200px 600px at 50% -200px, #1f2550 0%, transparent 70%);
    --surface: #171e2e;
    --surface-2: #20283a;
    --border: #2c3549;
    --text: #e8ecf5;
    --muted: #97a3b8;
    --accent: #8f8ff5;
    --accent-strong: #a9a9ff;
    --accent-soft: #262b52;
    --on-accent: #0e1320;
    --ok: #45c48a;
    --ok-soft: #173a2b;
    --ko: #f0766d;
    --ko-soft: #42201f;
    --gold: #f2bf4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 18px 48px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1320;
  --bg-grad: radial-gradient(1200px 600px at 50% -200px, #1f2550 0%, transparent 70%);
  --surface: #171e2e;
  --surface-2: #20283a;
  --border: #2c3549;
  --text: #e8ecf5;
  --muted: #97a3b8;
  --accent: #8f8ff5;
  --accent-strong: #a9a9ff;
  --accent-soft: #262b52;
  --on-accent: #0e1320;
  --ok: #45c48a;
  --ok-soft: #173a2b;
  --ko: #f0766d;
  --ko-soft: #42201f;
  --gold: #f2bf4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 18px 48px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  transition: background-color .3s, color .3s;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* Effets de survol réservés aux souris : sur écran tactile, ils peuvent obliger à toucher deux fois. */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { transform: translateY(-1px); }
  .mode-card:hover { transform: translateY(-2px); }
  .btn:hover { transform: translateY(-1px); }
  .btn-primary:hover { background: var(--accent-strong); }
  .help-toc a:hover { border-color: var(--accent); color: var(--accent); }
  .opt:not(:disabled):hover { transform: translateY(-2px); border-color: var(--accent); }
}
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 10px; }
.muted { color: var(--muted); }
kbd {
  font: 600 .72em/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: .25em .45em; border-radius: 6px;
  background: rgba(255, 255, 255, .2); margin-left: .5em;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.screen { flex: 1; animation: fade-in .35s ease both; }

/* ===== En-tête ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 12px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 4px 6px; margin-left: -6px;
}
.brand-logo { font-size: 26px; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.amp { color: var(--accent); }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow);
  transition: transform .15s;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-moon { fill: currentColor !important; stroke: none !important; }
.ico-sun { display: none; }
:root[data-theme="dark"] .ico-sun { display: block; }
:root[data-theme="dark"] .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: block; }
  :root:not([data-theme="light"]) .ico-moon { display: none; }
}

/* ===== Accueil ===== */
.hero { text-align: center; padding: 8px 0 18px; }
.hero h1 { font-size: clamp(1.5rem, 5vw, 2.1rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.hero p { margin: 0; }
.block { margin: 0 0 22px; }
.block-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 700; }
.hint { font-size: .9rem; color: var(--muted); margin: 8px 2px 0; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card {
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, background-color .15s;
}
.mode-card.mode-mix { grid-column: 1 / -1; }
.mode-card[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.mode-visual { display: flex; align-items: center; gap: 6px; height: 34px; }
.mode-visual img { height: 30px; width: 40px; border-radius: 5px; box-shadow: 0 0 0 1px var(--border); object-fit: cover; }
.mode-visual .arrow { color: var(--muted); font-weight: 700; }
.tag {
  font-size: .75rem; font-weight: 700;
  padding: 4px 8px; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
.mode-card[aria-checked="true"] .tag { background: var(--surface); }
.mode-name { font-weight: 800; font-size: 1.02rem; }
.mode-desc { font-size: .85rem; color: var(--muted); }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 6px; background: var(--surface-2); border-radius: 16px;
}
.segmented button {
  display: flex; flex-direction: column; align-items: center;
  padding: 10px; border: 0; border-radius: 12px; background: transparent;
  transition: background-color .15s, box-shadow .15s;
}
.segmented button span { font-size: .8rem; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--surface); box-shadow: var(--shadow); }
.segmented button[aria-checked="true"] strong { color: var(--accent); }
.segmented button:disabled { opacity: .45; cursor: not-allowed; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; min-height: 40px;
  border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-weight: 600; font-size: .92rem;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip[aria-checked="true"] small { color: inherit; opacity: .8; }

.play-row { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0 16px; }
.best { margin: 0; color: var(--muted); font-size: .92rem; min-height: 1.3em; }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; padding: 12px 20px;
  border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--surface); font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform .12s, background-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn-lg { min-width: 220px; min-height: 56px; font-size: 1.1rem; border-radius: 16px; }

/* ===== Aide ===== */
.top-actions { display: flex; gap: 8px; }
.link-btn { background: none; border: 0; padding: 6px; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.help-head h1 { font-size: clamp(1.5rem, 5vw, 2rem); margin: 6px 0 6px; letter-spacing: -.02em; text-wrap: balance; }
.help-head p { margin: 0 0 16px; max-width: 62ch; }
.help-back { margin-left: -12px; min-height: 40px; padding: 8px 12px; }
.help-toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.help-toc a {
  padding: 7px 12px; border-radius: 999px; font-size: .88rem; font-weight: 600;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--text); text-decoration: none;
}
.help-sec {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 18px 10px; margin: 0 0 14px; scroll-margin-top: 16px;
}
.help-sec h2 { font-size: 1.2rem; margin: 14px 0 8px; }
.help-sec h3 { font-size: 1rem; margin: 14px 0 4px; color: var(--accent); }
.help-sec p, .help-sec li, .help-sec dd { max-width: 68ch; }
.help-sec ul, .help-sec ol { padding-left: 1.2em; }
.help-sec li { margin: 4px 0; }
.help-dl dt { font-weight: 800; margin-top: 12px; }
.help-dl dd { margin: 2px 0 0; color: var(--muted); }
.help-cols { columns: 2 260px; column-gap: 24px; }
.help-cols li { break-inside: avoid; }
.help-sec kbd { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); margin: 0 1px; }
.help-table-wrap { overflow-x: auto; }
.help-table { border-collapse: collapse; width: 100%; margin: 4px 0 8px; }
.help-table th, .help-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.help-table th { white-space: nowrap; font-weight: 600; }
.help-table tr:last-child th, .help-table tr:last-child td { border-bottom: 0; }
.help-sec details { border-bottom: 1px solid var(--border); padding: 10px 0; }
.help-sec details:last-of-type { border-bottom: 0; }
.help-sec summary { cursor: pointer; font-weight: 700; }
.help-sec details p { margin: 8px 0 2px; color: var(--muted); }
.help-foot { display: flex; justify-content: center; padding: 8px 0 4px; }

/* ===== Partie ===== */
.hud { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width .4s ease; }
.hud-stats { display: flex; gap: 6px; }
.stat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 10px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .95rem; white-space: nowrap;
}
.stat > span { color: var(--gold); }
.timer b { font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.timer.urgent { border-color: var(--ko); color: var(--ko); animation: pop .5s ease infinite; }
.progress.chrono .progress-fill { transition: width .25s linear; }
.progress.chrono.urgent .progress-fill { background: var(--ko); }
.streak.hot { animation: pop .35s ease; border-color: var(--gold); }
.quit-confirm {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; padding: 12px; border-radius: 16px;
  background: var(--surface); border: 1.5px solid var(--ko); box-shadow: var(--shadow);
  animation: rise .25s ease both;
}
.quit-confirm p { margin: 0 8px 0 0; font-weight: 700; }
.quit-confirm .btn { min-height: 40px; padding: 8px 16px; }
.qcount { text-align: center; font-size: .85rem; margin: 10px 0 0; }

.question { text-align: center; padding: 6px 0 18px; }
.q-label { font-weight: 700; color: var(--muted); margin: 6px 0 14px; font-size: 1.02rem; }
.q-card {
  display: grid; place-items: center;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 22px;
  max-width: 460px;
  animation: card-in .45s cubic-bezier(.2, .9, .3, 1.2) both;
}
.q-card.flag { padding: 16px; }
.q-card.flag img {
  display: block; width: 100%; max-width: 420px; aspect-ratio: 4 / 3; height: auto;
  border-radius: 12px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
  object-fit: cover;
}
.q-card.text { min-height: 150px; }
.q-card .big { font-size: clamp(1.7rem, 7vw, 2.6rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.q-card .sub { color: var(--muted); font-size: .9rem; margin-top: 8px; }
.q-card .mini-flag { width: 64px; height: 48px; border-radius: 6px; margin-bottom: 12px; box-shadow: 0 0 0 1px var(--border); }

.answers { display: grid; gap: 10px; }
.answers > * { min-width: 0; }
.answers.qcm { grid-template-columns: 1fr 1fr; }
.opt {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; padding: 12px 14px 12px 34px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow);
  font-weight: 700; font-size: 1.02rem; text-align: center; line-height: 1.2;
  transition: transform .12s, border-color .15s, background-color .2s, opacity .2s;
  animation: slide-in .3s ease both;
}
.opt:nth-child(2) { animation-delay: .04s; }
.opt:nth-child(3) { animation-delay: .08s; }
.opt:nth-child(4) { animation-delay: .12s; }
.opt .key {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border-radius: 6px;
  display: grid; place-items: center;
  font-size: .72rem; color: var(--muted); background: var(--surface-2);
}
.opt.flag-opt { padding: 10px 10px 10px 34px; min-height: 0; }
.opt.flag-opt img { display: block; width: 100%; aspect-ratio: 4 / 3; height: auto; border-radius: 8px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); object-fit: cover; }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); animation: pop .4s ease; }
.opt.wrong { border-color: var(--ko); background: var(--ko-soft); color: var(--ko); animation: shake .4s ease; }
.opt.dim { opacity: .5; }

.typing { display: flex; flex-direction: column; gap: 10px; }
.typing-row { display: flex; gap: 8px; }
.typing input {
  flex: 1; min-width: 0; width: 100%;
  min-height: 56px; padding: 12px 16px;
  font: inherit; font-size: 1.15rem; font-weight: 600;
  color: var(--text); background: var(--surface);
  border: 2px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow);
  transition: border-color .15s, background-color .2s;
}
.typing input:focus { outline: none; border-color: var(--accent); }
.typing input.correct { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.typing input.wrong { border-color: var(--ko); background: var(--ko-soft); color: var(--ko); animation: shake .4s ease; }
.typing .btn-skip { align-self: center; }
.typing.done .btn, .typing.done .btn-skip { display: none; }

.feedback {
  margin-top: 16px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise .3s ease both;
}
.feedback.ok { border-color: var(--ok); }
.feedback.ko { border-color: var(--ko); }
.fb-title { margin: 0 0 4px; font-weight: 800; font-size: 1.1rem; }
.feedback.ok .fb-title { color: var(--ok); }
.feedback.ko .fb-title { color: var(--ko); }
.fb-info { margin: 0 0 12px; color: var(--muted); font-size: .95rem; }
.feedback .btn { min-width: 200px; }

/* ===== Fin ===== */
.end-card {
  text-align: center; padding: 26px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  box-shadow: var(--shadow-lg);
  animation: card-in .5s cubic-bezier(.2, .9, .3, 1.2) both;
}
.end-kicker { margin: 0; font-weight: 600; }
.end-score { font-size: 4rem; font-weight: 900; margin: 4px 0 0; line-height: 1; letter-spacing: -.03em; color: var(--accent); }
.end-total { font-size: 1.8rem; color: var(--muted); }
.end-msg { font-size: 1.15rem; font-weight: 700; margin: 10px 0 6px; }
.record { display: inline-block; margin: 4px 0 0; padding: 6px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--gold); font-weight: 800; animation: pop .5s ease .2s both; }
.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.end-stats div { background: var(--surface-2); border-radius: 14px; padding: 10px 6px; display: flex; flex-direction: column; }
.end-stats b { font-size: 1.25rem; }
.end-stats span { font-size: .8rem; color: var(--muted); }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.recap { margin-top: 22px; }
.recap-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recap-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
}
.recap-list img { width: 48px; height: 36px; border-radius: 5px; flex: none; box-shadow: 0 0 0 1px var(--border); object-fit: cover; }
.recap-list .r-main { font-weight: 700; }
.recap-list .r-sub { font-size: .88rem; color: var(--muted); }
.recap-list .r-you { color: var(--ko); text-decoration: line-through; }

.foot { text-align: center; font-size: .78rem; padding-top: 24px; }

/* ===== Animations ===== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { transform: translateY(8px); } to { transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* ===== Petits écrans ===== */
@media (max-width: 420px) {
  .mode-card { padding: 12px; }
  .mode-desc { display: none; }
  .opt { font-size: .95rem; min-height: 58px; }
  .end-score { font-size: 3.2rem; }
  .brand-name { font-size: 1.02rem; }
}
@media (min-width: 640px) {
  .app { padding-top: 20px; }
  .answers.qcm.flags { grid-template-columns: 1fr 1fr; max-width: 560px; margin: 0 auto; width: 100%; }
}
