:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #687083;
  --border: #e2e5ec;
  --primary: #2f5bea;
  --primary-hover: #2449c4;
  --primary-soft: #e8eeff;
  --good: #1f9d55;
  --good-soft: #e6f6ec;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --warn-soft: #fff6e0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1217;
    --surface: #181c24;
    --text: #e7eaf0;
    --muted: #9aa2b2;
    --border: #2a303c;
    --primary: #6d8cff;
    --primary-hover: #8aa3ff;
    --primary-soft: #1f2847;
    --good: #45c27a;
    --good-soft: #15291e;
    --bad: #f07272;
    --bad-soft: #321a1c;
    --warn-soft: #2e2715;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1 { font-size: 1.5rem; margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
p { margin: 0 0 1rem; }
a { color: var(--primary); }

.container { max-width: 820px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 440px; margin: 6vh auto 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Barre du haut */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 820px; margin: 0 auto; padding: 14px 16px 0;
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--primary); }
.userbox { display: flex; align-items: center; gap: 10px; min-width: 0; }
.userbox .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

/* Cartes */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-between h2 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* Formulaires */
label { font-weight: 600; font-size: .9rem; }
input {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.code-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: .875rem; }
.linklike { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; }

.alert { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: .95rem; }
.notice { background: var(--good-soft); color: var(--good); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: .95rem; }

/* Tuiles de stats */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tile-value { font-size: 1.4rem; font-weight: 700; }
.tile-label { color: var(--muted); font-size: .85rem; }

/* Barres */
.bar { display: block; height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .25s; }
.bar-fill.good { background: var(--good); }
.bar-fill.bad { background: var(--bad); }

.domain-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.domain-row { display: grid; grid-template-columns: 190px 1fr 64px; align-items: center; gap: 12px; }
.domain-row .bar { margin: 0; }
.domain-name { font-size: .95rem; }
.domain-pct { text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; }

/* Historique */
.history { list-style: none; margin: 0; padding: 0; }
.history-item {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 14px;
  padding: 12px 4px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.history li:first-child .history-item { border-top: 0; }
.history-item:hover { background: var(--bg); }
.score-pill { font-weight: 600; font-size: .875rem; padding: 3px 10px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.score-pill.good { background: var(--good-soft); color: var(--good); }
.score-pill.bad { background: var(--bad-soft); color: var(--bad); }

/* Questionnaire */
.qmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 12px; }
.qnum { font-weight: 700; margin-right: 4px; }
.badge { font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); }
.badge-alt { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.qtext { font-size: 1.08rem; white-space: pre-line; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }

.options { display: flex; flex-direction: column; gap: 10px; margin: 0 0 18px; padding: 0; list-style: none; }
.option {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .12s, background .12s;
}
button.option:hover { border-color: var(--primary); }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.letter {
  flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg); border: 1px solid var(--border); font-weight: 700; font-size: .85rem;
}
.option.selected .letter { background: var(--primary); border-color: var(--primary); color: #fff; }

.qnav { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.qnav .btn-primary:only-child, .qnav > :last-child { margin-left: auto; }

.small-title { font-size: .95rem; margin-bottom: 10px; }
.qgrid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.qcell {
  aspect-ratio: 1; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; padding: 0;
}
.qcell.done { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary); font-weight: 600; }
.qcell.current { outline: 2px solid var(--primary); outline-offset: 1px; }
.hint { margin: 12px 0 0; }

/* Résultats */
.result { text-align: center; }
.result.good { border-top: 5px solid var(--good); }
.result.bad { border-top: 5px solid var(--bad); }
.result-score { font-size: 3.2rem; font-weight: 800; line-height: 1.1; }
.result.good .result-score { color: var(--good); }
.result.bad .result-score { color: var(--bad); }
.result-sub { font-weight: 600; margin-bottom: 10px; }
.result .domain-list { text-align: left; max-width: 520px; margin: 18px auto; }
.result .actions { justify-content: center; }

.review { list-style: none; margin: 16px 0 0; padding: 0; }
.review-item { border-top: 1px solid var(--border); padding: 18px 0; }
.review-item:first-child { border-top: 0; }
.review-item.ok .qnum { color: var(--good); }
.review-item.ko .qnum { color: var(--bad); }
.options.static .option { cursor: default; flex-wrap: wrap; }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.correct .letter { background: var(--good); border-color: var(--good); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); border-color: var(--bad); color: #fff; }
.option > span:nth-child(2) { flex: 1; min-width: 0; }
.tag { font-size: .75rem; font-weight: 600; color: var(--muted); white-space: nowrap; align-self: center; }
.explanation { background: var(--warn-soft); border-radius: 10px; padding: 12px 14px; font-size: .95rem; }

@media (max-width: 640px) {
  .card { padding: 18px 16px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .domain-row { grid-template-columns: 1fr 56px; }
  .domain-row .bar { grid-column: 1 / -1; grid-row: 2; margin-bottom: 8px; }
  .qgrid { grid-template-columns: repeat(6, 1fr); }
  .history-item { grid-template-columns: 1fr auto; }
  .history-item > :nth-child(2) { display: none; }
  .qnav .btn { flex: 1; }
  .userbox .email { display: none; }
}
.switch-login { margin: 16px 0 0; }

/* Choix du nombre de questions */
.size-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 4px 0 14px; }
.size-label { font-weight: 600; font-size: .9rem; }
.size-picker { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.size-option {
  min-width: 52px; padding: 9px 14px; border: 0; border-left: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.size-option:first-child { border-left: 0; }
.size-option:hover { background: var(--bg); }
.size-option.selected { background: var(--primary); color: #fff; }
@media (max-width: 640px) { .size-picker { width: 100%; } .size-option { flex: 1; } }
