/* Repères — entraînement à l'examen civique.
   Identité éditoriale : papier chaud, encre, bleu civique.
   Archivo (titres/interface) + IBM Plex Mono (étiquettes, minuteur, scores).
   Coins nets (4px), losanges, contraste élevé, accessible. */

:root {
  --bg: #E8E4DA;          /* fond de page */
  --paper: #F5F2EA;       /* panneaux */
  --card: #FFFFFF;        /* cartes */
  --ink: #111111;         /* encre : texte fort, blocs sombres */
  --civique: #1F3A8A;     /* bleu : action principale */
  --civique-d: #16295f;
  --juste: #2E6A4F;       /* vert : bonne réponse */
  --revoir: #B4502E;      /* terracotta : à revoir / faux */
  --amber: #E6A24E;
  --line: #DAD5C8;        /* bordures */
  --line-soft: #EDE9DE;
  --muted: #6B6659;       /* étiquettes */
  --muted-2: #56534A;     /* texte secondaire */
  --ink-soft: #2E2C26;    /* corps sur clair */
  --on-ink: #F5F2EA;      /* texte sur bloc sombre */
  --on-ink-mut: #A5A197;
  --radius: 4px;
  --shadow: 0 18px 40px rgba(17, 17, 17, .10);
  --focus: 0 0 0 3px var(--bg), 0 0 0 6px var(--civique);
  --sans: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  /* alias de compatibilité : app.js pose encore ces couleurs en inline */
  --bleu: var(--civique);
  --ok: var(--juste);
  --warn: var(--amber);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* étiquette mono réutilisable (surtitres) */
.eyebrow, .score-label, .qc-theme, .miss h3, .msg .tag {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
}

/* lien d'évitement clavier */
.skip {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--ink); color: var(--on-ink); border-radius: var(--radius);
  padding: 10px 16px; font-weight: 600; text-decoration: none;
}
.skip:focus { left: 8px; }

/* ------------------------------------------------------------ en-tête */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 26px clamp(16px, 4vw, 40px);
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  padding-top: max(26px, env(safe-area-inset-top));
  max-width: 820px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
/* le losange de marque (remplace l'ancien drapeau) */
.flag {
  width: 15px; height: 15px; flex: none; background: var(--ink);
  transform: rotate(45deg); border-radius: 1px;
}
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.035em; margin: 0; line-height: 1; }
.sub { margin: 5px 0 0; font-size: 13px; color: var(--muted-2); letter-spacing: -.005em; }

.score { text-align: right; flex: none; }
.score-main { font-family: var(--mono); font-size: 24px; font-weight: 500; color: var(--ink); line-height: 1; }
.slash { color: var(--muted); margin: 0 1px; }
.score-label { font-size: 10px; letter-spacing: .12em; margin-top: 3px; }

/* ---------------------------------------------------------- panneaux */
main { max-width: 640px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 56px; }
main {
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  padding-bottom: max(56px, calc(env(safe-area-inset-bottom) + 24px));
}
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(20px, 4vw, 32px);
}
/* entrée en fondu discrète à chaque bascule d'écran (coupée si reduced-motion) */
.panel:not(.hidden) { animation: panelIn .22s ease both; }
@keyframes panelIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.panel h2 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -.03em; }
.panel .lead { margin: 0 0 22px; font-size: 15px; color: var(--muted-2); line-height: 1.6; }
.hidden { display: none !important; }

/* --------------------------------------------------------- formulaire */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.field { display: block; margin-bottom: 2px; }
.field > span {
  display: block; font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .14em; color: var(--muted); margin-bottom: 7px;
}
.field.wide { grid-column: 1 / -1; }

select {
  width: 100%; min-height: 50px; padding: 13px 40px 13px 15px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: 500 16px/1.3 var(--sans); appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B6659' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; background-size: 18px;
  transition: border-color .15s;
}
select:hover:not(:disabled) { border-color: var(--ink); }
select:disabled { opacity: .5; cursor: not-allowed; }
select:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible {
  outline: none; box-shadow: var(--focus);
}

.note {
  font-size: 14px; color: var(--muted-2); line-height: 1.65;
  background: var(--paper); border-left: 2px solid var(--ink);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 13px 16px; margin: 16px 0 0;
}

.check {
  display: flex; align-items: center; gap: 11px; margin: 18px 0 22px;
  font-size: 15px; color: var(--ink-soft); cursor: pointer; min-height: 44px;
}
.check input { width: 18px; height: 18px; accent-color: var(--civique); cursor: pointer; flex: none; }

button { font: inherit; cursor: pointer; border-radius: var(--radius); transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, opacity .15s; }

/* action principale : bleu civique */
.primary {
  width: 100%; min-height: 54px; padding: 15px; border: 0; font-size: 16px; font-weight: 600;
  color: #fff; background: var(--civique); letter-spacing: -.01em;
}
.primary:hover { background: var(--civique-d); }
.primary:disabled { opacity: .55; cursor: wait; }

/* secondaires : bordées, sur papier */
.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 11px 16px;
  background: var(--card); color: var(--ink-soft); border: 1px solid var(--line);
  font-size: 14px; font-weight: 500;
}
.ghost:hover { border-color: var(--ink); color: var(--ink); }
.ghost.danger:hover { border-color: var(--revoir); color: var(--revoir); }
.ghost svg { flex: none; }

.hint { font-size: 13px; color: var(--muted); text-align: center; margin: 14px 0 0; line-height: 1.6; }
.kbd kbd {
  font: 500 11.5px var(--mono); background: var(--paper);
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 6px;
}

/* -------------------------------------------------------- progression */
.progress { height: 4px; background: var(--line); border-radius: 100px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--ink); transition: width .4s ease; }
.meta {
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12px; color: var(--muted-2); margin: 14px 0 4px;
}
.dot { opacity: .4; }
.timer {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-weight: 500; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 9px;
}
.timer.low { color: #fff; background: var(--revoir); border-color: var(--revoir); }
.timer svg { opacity: .7; }

/* bouton son */
.sound-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); color: var(--muted); cursor: pointer;
}
.sound-btn:hover { color: var(--ink); border-color: var(--ink); }
.sound-btn .ic-off { display: none; }
.sound-btn.off { color: var(--revoir); }
.sound-btn.off .ic-on { display: none; }
.sound-btn.off .ic-off { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ------------------------------------------------------- orbe vocale */
.orb { position: relative; width: 108px; height: 108px; margin: 22px auto 12px; }
.orb .core {
  position: absolute; inset: 28px; border-radius: 50%;
  background: var(--civique); transition: background .3s, box-shadow .3s;
}
.orb .ring { position: absolute; inset: 10px; border-radius: 50%; border: 1.5px solid rgba(31, 58, 138, .35); opacity: 0; }
.orb.speaking .ring, .orb.listening .ring { animation: pulse 2s ease-out infinite; }
.orb.speaking .ring.r2, .orb.listening .ring.r2 { animation-delay: 1s; }
@keyframes pulse { 0% { transform: scale(.75); opacity: .8; } 100% { transform: scale(1.35); opacity: 0; } }
.orb.listening .core { background: var(--juste); }
.orb.listening .ring { border-color: rgba(46, 106, 79, .4); }
.orb.thinking .core { background: var(--amber); animation: breathe 1.1s ease-in-out infinite; }
.orb.idle .core { background: #B8B2A4; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }

.state { text-align: center; color: var(--muted-2); font-size: 14px; margin: 0 0 20px; min-height: 22px; }

/* -------------------------------------------------- propositions QCM */
.choices { display: grid; gap: 10px; margin-bottom: 20px; }
.choice {
  display: flex; gap: 14px; align-items: center; text-align: left;
  min-height: 52px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 16px; width: 100%; line-height: 1.45;
}
.choice:hover:not(:disabled) { border-color: var(--ink); border-width: 2px; padding: 13px 15px; }
.choice:disabled { cursor: default; }
.choice .letter {
  flex: none; width: 16px; text-align: center;
  font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--muted);
}
.choice.right { border: 2px solid var(--juste); padding: 13px 15px; }
.choice.right .letter { color: var(--juste); }
.choice.wrong { border: 2px solid var(--revoir); padding: 13px 15px; }
.choice.wrong .letter { color: var(--revoir); }

/* ------------------------------------------------------ transcription */
.log { display: grid; gap: 10px; margin-bottom: 22px; max-height: 320px; overflow-y: auto; scrollbar-width: thin; padding-right: 2px; }
.msg { padding: 12px 15px; border-radius: var(--radius); font-size: 15px; max-width: 90%; white-space: pre-wrap; line-height: 1.6; overflow-wrap: break-word; }
.msg.ai { background: var(--paper); border: 1px solid var(--line); }
.msg.me { background: var(--ink); color: var(--on-ink); margin-left: auto; }
.msg .tag { display: block; font-size: 10px; margin-bottom: 4px; opacity: .8; }
.msg.me .tag { color: var(--on-ink-mut); }
.msg.verdict-ok { border-left: 3px solid var(--juste); }
.msg.verdict-ko { border-left: 3px solid var(--revoir); }

/* --------------------------------------------------------- commandes */
.controls { display: flex; gap: 9px; align-items: stretch; flex-wrap: wrap; justify-content: center; }
.mic {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 54px; padding: 14px 26px; border: 0;
  color: var(--on-ink); font-weight: 600; font-size: 15.5px; background: var(--ink);
}
.mic:hover { background: #000; }
.mic.on { background: var(--juste); color: #fff; }
.mic[disabled] { opacity: .45; cursor: not-allowed; }

/* -------------------------------------------------------------- bilan */
.report-head { text-align: center; padding: 12px 0 26px; }
.report-score { font-family: var(--mono); font-size: 60px; font-weight: 500; letter-spacing: -.02em; line-height: .95; color: var(--ink); }
.report-score span { color: var(--muted); }
.report-verdict { font-size: 15px; color: var(--muted-2); margin-top: 10px; font-weight: 500; }
.report-verdict.pass { color: var(--juste); font-weight: 600; }
.report-verdict.fail { color: var(--revoir); font-weight: 600; }

.theme-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); font-size: 15px; min-height: 44px; }
.theme-row .name { flex: 1; min-width: 0; color: var(--ink); }
.theme-row .track { width: 88px; height: 6px; border-radius: 100px; background: var(--line-soft); overflow: hidden; flex: none; }
.theme-row .fill { display: block; height: 100%; border-radius: 100px; background: var(--juste); }
.theme-row .num { width: 46px; text-align: right; font-family: var(--mono); font-size: 13px; color: var(--muted-2); flex: none; }

.miss { margin-top: 26px; }
.miss h3 { font-size: 10px; letter-spacing: .14em; margin: 0 0 12px; }
.miss-item { border: 1px solid var(--line); border-left: 3px solid var(--revoir); border-radius: var(--radius); padding: 15px 16px; margin-bottom: 10px; background: var(--card); font-size: 15px; overflow-wrap: break-word; }
.miss-item .q { font-weight: 600; margin-bottom: 8px; line-height: 1.4; color: var(--ink); }
.miss-item .a { color: var(--juste); font-size: 14.5px; font-weight: 600; }
.miss-item .w { color: var(--ink-soft); font-size: 14px; margin-top: 8px; line-height: 1.65; }
.miss-item a { display: inline-block; margin-top: 10px; color: var(--civique); font-size: 13px; font-weight: 500; text-decoration: none; }
.miss-item a:hover { color: var(--ink); }
#report .primary { margin-top: 26px; }
.review { width: 100%; margin-top: 12px; }

/* ------------------------------------------------------ bandeau question */
.qcard {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin: 18px 0 6px;
}
.qc-theme { display: block; font-size: 10px; letter-spacing: .14em; margin-bottom: 8px; }
.qc-text { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.3; letter-spacing: -.02em; color: var(--ink); overflow-wrap: break-word; }

/* --------------------------------------------------- tableau de bord */
.dash {
  display: grid; grid-template-columns: 1fr; gap: 16px; align-items: stretch;
  background: var(--ink); border-radius: var(--radius); padding: 20px; margin: 0 0 22px; color: var(--on-ink);
}
.dash-ring { display: flex; align-items: center; gap: 14px; min-width: 0; padding-bottom: 14px; border-bottom: 1px solid #3A3A38; }
.ring-num { font: 500 17px var(--mono); fill: var(--on-ink); }
.dash-ring-label { font-size: 14px; line-height: 1.45; color: var(--on-ink); min-width: 0; }
.dash-ring-label strong { font-family: var(--mono); font-weight: 500; }
.dash-ring-label span { color: var(--on-ink-mut); font-size: 12px; }
.dash-themes { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dash-theme { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.dt-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--on-ink); }
.dt-track { width: 72px; height: 6px; border-radius: 100px; background: #3A3A38; overflow: hidden; flex: none; }
.dt-fill { display: block; height: 100%; border-radius: 100px; background: var(--juste); }
.dt-num { width: 40px; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--on-ink-mut); flex: none; }
.dash-hist { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid #3A3A38; }
.hist-chip { font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--on-ink); border: 1px solid #3A3A38; border-radius: 100px; padding: 5px 11px; }
.hist-chip small { color: var(--on-ink-mut); margin-left: 5px; font-family: var(--sans); }
.hist-chip.ok { border-color: var(--juste); color: #8FD0B0; }
.hist-chip.ko { border-color: var(--amber); color: var(--amber); }
@media (max-width: 560px) { .dash { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- compte */
.account { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-soft); }
.quota-line { font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }
.quota-line strong { color: var(--civique); }
.acc-label { font-size: 14px; color: var(--muted-2); margin: 0 0 10px; }
.acc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.acc-row input {
  flex: 1; min-width: 200px; font-family: var(--sans); font-size: 15px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
}
.acc-row input:focus { outline: 2px solid var(--civique); outline-offset: 1px; }
button.small { padding: 10px 16px; font-size: 14px; }
#accountIn { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
#accountIn.hidden { display: none; }

/* -------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--ink); color: var(--ink);
  padding: 13px 18px; border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 14px; max-width: min(560px, 92vw); z-index: 50;
}
.toast.err { border-color: var(--revoir); }

/* ------------------------------------------------------- mention légale */
.disclaimer {
  max-width: 640px; margin: 8px auto 0;
  padding: 20px clamp(16px, 4vw, 40px);
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  padding-bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  font-family: var(--mono); font-size: 11px; line-height: 1.65; letter-spacing: .01em;
  color: var(--muted); text-align: center; border-top: 1px solid var(--line);
}

/* ------------------------------------------------------ motion réduite */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ------------------------------------------------------------- mobile */
@media (max-width: 480px) {
  .top { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: 16px; }
  .sub { display: none; }
  h1 { font-size: 21px; }
  .score-main { font-size: 21px; }
  main { padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 16px)); }
  .panel { padding: 18px 16px; }
  .panel h2 { font-size: 20px; }
  .orb { width: 88px; height: 88px; margin: 16px auto 8px; }
  .orb .core { inset: 22px; }
  .qcard { padding: 15px 16px; margin: 14px 0 4px; }
  .qc-text { font-size: 19px; }
  .log { max-height: 34vh; }
  .controls { gap: 8px; }
  .mic { flex: 1 0 100%; width: 100%; }
  .controls .ghost { flex: 1 1 0; min-width: 0; padding: 11px 8px; font-size: 13.5px; }
  .report-score { font-size: 48px; }
  .theme-row .track { width: 72px; }
}
@media (max-width: 340px) {
  .controls .ghost { font-size: 12.5px; gap: 4px; }
  .controls .ghost svg { width: 15px; height: 15px; }
  .qc-text { font-size: 17px; }
}
