/* ---------- Base ---------- */
:root {
  --bg: #12142e;
  --bg-2: #1d2050;
  --card: rgba(255, 255, 255, 0.07);
  --card-solid: #232659;
  --border: rgba(255, 255, 255, 0.14);
  --text: #f2f4ff;
  --muted: #a6abd8;
  --accent: #6c5ce7;
  --accent-2: #00d2d3;
  --good: #2ed573;
  --bad: #ff6b81;
  --warn: #ffa502;
  --radius: 18px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 700px at 15% -10%, #34307a 0%, transparent 60%),
              radial-gradient(900px 600px at 100% 0%, #0f5f6b 0%, transparent 55%),
              linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.stars-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,.5), transparent),
    radial-gradient(2px 2px at 70% 15%, rgba(255,255,255,.35), transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, rgba(255,255,255,.35), transparent),
    radial-gradient(2px 2px at 85% 60%, rgba(255,255,255,.3), transparent),
    radial-gradient(1.5px 1.5px at 10% 85%, rgba(255,255,255,.3), transparent);
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 22px 16px 60px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Accueil ---------- */
.hero { text-align: center; margin-bottom: 22px; }

.hero-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .22em;
  font-size: .72rem;
  color: var(--accent-2);
}

.hero-title {
  margin: 4px 0 2px;
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -.02em;
  background: linear-gradient(100deg, #fff 10%, #a29bfe 45%, #00d2d3 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-title span { font-weight: 300; }

.hero-sub { margin: 0; color: var(--muted); font-size: .95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 12px;
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 10px;
}
.choice-mix { grid-column: 1 / -1; }
@media (max-width: 559px) {
  .choice-grid { grid-template-columns: repeat(2, 1fr); }
  .choice-last { grid-column: 1 / -1; }
}

.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 8px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease, border-color .15s, background .15s;
  font-family: inherit;
}
.choice:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.35); }
.choice.is-selected {
  border-color: var(--accent-2);
  background: linear-gradient(160deg, rgba(108,92,231,.35), rgba(0,210,211,.18));
  box-shadow: 0 0 0 4px rgba(0,210,211,.13);
}
.choice-ico { font-size: 1.7rem; line-height: 1.2; }
.choice-name { font-weight: 700; }
.choice-formula { font-size: .75rem; color: var(--muted); }

.choice-row { display: grid; gap: 10px; }

.pill {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.pill:hover { border-color: rgba(255,255,255,.35); }
.pill.is-selected {
  border-color: var(--accent);
  background: linear-gradient(100deg, rgba(108,92,231,.4), rgba(108,92,231,.12));
}
.pill strong { font-size: 1rem; }
.pill small { color: var(--muted); font-size: .8rem; }

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0;
}

/* ---------- Boutons ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .1s ease, filter .15s, background .15s;
}
.btn:active { transform: scale(.98); }

.btn-primary {
  background: linear-gradient(100deg, var(--accent) 0%, #8e7bff 55%, var(--accent-2) 140%);
  color: #fff;
  box-shadow: 0 8px 22px rgba(108, 92, 231, .45);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(255,255,255,.15); }

.btn-big { padding: 16px 20px; font-size: 1.08rem; }

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.07);
  color: var(--text);
  border-radius: 10px;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: rgba(255,255,255,.16); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-family: inherit;
  font-size: .85rem;
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

/* ---------- Objectif & progression ---------- */
.goal-info {
  margin: 12px 0 0;
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
}
.goal-info strong { color: #ffd86b; }

.goalbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 12px;
}
.goal-medal { font-size: 1.25rem; line-height: 1; }
.goal-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 99px;
  background: rgba(0,0,0,.3);
  overflow: hidden;
}
.goal-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #cd7f32 0%, #c0c0c0 55%, #ffd86b 100%);
  transition: width .45s ease;
}
.goal-mark {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(255,255,255,.45);
}
.goal-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }

.rank-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.rank-ico { font-size: 2.1rem; }
.rank-info { display: flex; flex-direction: column; }
.rank-info strong { font-size: 1.1rem; }
.rank-next { font-size: .8rem; color: var(--muted); margin: 0; }
.xp-track { height: 12px; margin-bottom: 12px; }

.badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}
.badge {
  text-align: center;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  font-size: 1.35rem;
  cursor: help;
}
.badge small { display: block; font-size: .6rem; color: var(--muted); line-height: 1.2; margin-top: 2px; }
.badge.locked { filter: grayscale(1); opacity: .35; }

.end-goal { margin-bottom: 14px; }
.end-goal-text { margin: 6px 0 0; font-size: .9rem; }
.end-goal-text .win { color: #ffd86b; font-weight: 700; }
.end-rank { margin-bottom: 14px; }
.end-xp { margin: 0 0 6px; font-size: .9rem; color: var(--muted); }
.end-xp strong { color: var(--accent-2); }
.end-badges { display: grid; gap: 8px; margin-bottom: 14px; }
.badge-unlocked {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(100deg, rgba(255,216,107,.22), rgba(255,216,107,.05));
  border: 1px solid rgba(255,216,107,.45);
  animation: pop .45s ease;
}
.badge-unlocked span:first-child { font-size: 1.6rem; }
.badge-unlocked b { display: block; font-size: .95rem; }
.badge-unlocked small { color: var(--muted); font-size: .78rem; }

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 50;
  background: linear-gradient(100deg, rgba(255,216,107,.95), rgba(255,165,2,.95));
  color: #2a1c00;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 99px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: toastIn .3s ease, toastOut .4s ease 2s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -14px); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, -14px); } }

/* ---------- Stats ---------- */
.stats-card { margin-top: 6px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.stat {
  background: rgba(255,255,255,.05);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.stat strong { display: block; font-size: 1.3rem; }
.stat span { font-size: .75rem; color: var(--muted); }
.stats-empty { color: var(--muted); font-size: .9rem; margin: 0; }

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  margin-top: 18px;
}

/* ---------- Barre de jeu ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.progress { flex: 1; }
.progress-track {
  height: 10px;
  border-radius: 99px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .35s ease;
}
.progress-label { font-size: .75rem; color: var(--muted); }

.score-box {
  font-weight: 800;
  font-size: .95rem;
  white-space: nowrap;
}
.streak {
  display: inline-block;
  margin-left: 6px;
  background: rgba(255,165,2,.2);
  border: 1px solid rgba(255,165,2,.5);
  border-radius: 99px;
  padding: 1px 8px;
  font-size: .8rem;
}

/* ---------- Question ---------- */
.question-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.tag {
  background: rgba(0,210,211,.16);
  border: 1px solid rgba(0,210,211,.4);
  color: #7ff0f1;
  border-radius: 99px;
  padding: 3px 12px;
  font-size: .78rem;
  font-weight: 700;
}

.figure-wrap { display: flex; justify-content: center; }
.figure {
  width: 100%;
  max-width: 260px;
  margin: 2px auto 6px;
}
.figure svg { width: 100%; height: auto; display: block; }

.question-text {
  font-size: 1.08rem;
  margin: 8px 0 16px;
  text-align: center;
}
.question-text b { color: #ffd86b; }
.question-text .hl { color: var(--accent-2); font-weight: 700; }

.input-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,.28);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 6px 14px;
  transition: border-color .15s;
}
.input-zone:focus-within { border-color: var(--accent-2); }
.input-zone input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 700;
  padding: 10px 0;
  font-family: inherit;
}
.unit { color: var(--muted); font-weight: 700; font-size: 1.05rem; }

.qcm-zone { display: grid; gap: 8px; }
.qcm-option {
  text-align: left;
  padding: 13px 15px;
  border-radius: 13px;
  border: 2px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}
.qcm-option:hover { border-color: rgba(255,255,255,.4); }
.qcm-option.is-selected { border-color: var(--accent-2); background: rgba(0,210,211,.14); }

.answer-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.answer-actions .btn { flex: 1; }

.hint-box {
  margin-top: 12px;
  background: rgba(255,165,2,.12);
  border: 1px solid rgba(255,165,2,.4);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .92rem;
}
.hint-box .formula { color: #ffd86b; }

/* ---------- Feedback ---------- */
.feedback {
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--card-solid);
  box-shadow: var(--shadow);
  animation: slideUp .25s ease;
}
.feedback.good { border-color: rgba(46,213,115,.6); background: linear-gradient(180deg, rgba(46,213,115,.16), var(--card-solid)); }
.feedback.almost { border-color: rgba(255,165,2,.6); background: linear-gradient(180deg, rgba(255,165,2,.16), var(--card-solid)); }
.feedback.bad { border-color: rgba(255,107,129,.6); background: linear-gradient(180deg, rgba(255,107,129,.14), var(--card-solid)); }

.feedback-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.feedback-head span:first-child { font-size: 1.6rem; }

.feedback-detail { font-size: .95rem; margin-bottom: 14px; }
.feedback-detail ol { margin: 8px 0 0; padding-left: 20px; }
.feedback-detail li { margin-bottom: 4px; }
.feedback-detail .formula { color: #ffd86b; font-weight: 700; }
.feedback-detail .final { color: var(--good); font-weight: 800; }
.feedback-detail .yours { color: var(--bad); font-weight: 700; }
.feedback .btn { width: 100%; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.pop { animation: pop .35s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* ---------- Fin de partie ---------- */
.end-card { text-align: center; padding: 24px 18px; }
.end-stars { font-size: 2.6rem; letter-spacing: 6px; }
.end-stars span { display: inline-block; animation: pop .5s ease backwards; }
.end-stars span:nth-child(2) { animation-delay: .15s; }
.end-stars span:nth-child(3) { animation-delay: .3s; }
.end-title { margin: 6px 0 4px; font-size: 1.6rem; }
.end-sub { margin: 0 0 18px; color: var(--muted); }

.end-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.end-numbers div {
  background: rgba(255,255,255,.06);
  border-radius: 12px;
  padding: 10px 6px;
}
.end-numbers strong { display: block; font-size: 1.3rem; }
.end-numbers span { font-size: .72rem; color: var(--muted); }

.end-review { text-align: left; }
.end-review h3 { font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.review-item {
  background: rgba(255,107,129,.1);
  border-left: 3px solid var(--bad);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: .88rem;
}
.review-item .sol { color: var(--good); font-weight: 700; }

/* ---------- Aide-mémoire ---------- */
.memo {
  border: none;
  border-radius: 20px;
  padding: 0;
  max-width: 560px;
  width: calc(100% - 28px);
  background: var(--card-solid);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
.memo::backdrop { background: rgba(8, 9, 26, .75); backdrop-filter: blur(3px); }
.memo-inner { padding: 22px 20px; }
.memo-inner h2 { margin: 0 0 14px; font-size: 1.25rem; }
.memo-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: rgba(255,255,255,.04);
}
.memo-item h3 { margin: 0 0 6px; font-size: .95rem; color: var(--accent-2); }
.memo-item p { margin: 2px 0; }
.formula {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffd86b;
}
.memo-note { font-size: .85rem; color: var(--muted); }
.memo-units p { font-size: .9rem; }
.memo .btn { width: 100%; margin-top: 6px; }

/* ---------- Figures SVG ---------- */
.fig-shape { fill: url(#gradShape); fill-opacity: .62; stroke: #cfd4ff; stroke-width: 2; }
.fig-base { fill: rgba(255, 255, 255, .09); stroke: none; }
.fig-line { stroke: #ffd86b; stroke-width: 2; fill: none; }
.fig-dash { stroke: #cfd4ff; stroke-width: 1.6; fill: none; stroke-dasharray: 5 4; opacity: .75; }
/* Arêtes cachées derrière le solide */
.fig-hidden { stroke: #e8ebff; stroke-width: 1.8; fill: none; stroke-dasharray: 6 4; opacity: .95; }
.fig-height { stroke: #ffd86b; stroke-width: 2; fill: none; stroke-dasharray: 5 4; }
.fig-tri-height { stroke: #7ff0f1; stroke-width: 2; fill: none; stroke-dasharray: 5 4; }
.fig-label {
  fill: #ffd86b;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  paint-order: stroke;
  stroke: #171a3a;
  stroke-width: 4px;
  stroke-linejoin: round;
}
.fig-label-cyan { fill: #7ff0f1; }

@media (min-width: 560px) {
  .choice-mix { grid-column: 1 / -1; flex-direction: row; justify-content: center; gap: 10px; }
  .choice-row { grid-template-columns: repeat(3, 1fr); }
  .home-actions { flex-direction: row; }
  .home-actions .btn { flex: 1; }
  .answer-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
