/* Mx Chimie : formulaire question par question, défilement vertical. */
:root {
  --ink: #f7f8fc;
  --surface: #ffffff;
  --fg: #0b0d1f;
  --mist: #565d7c;
  --line: rgb(11 13 31 / 0.14);
  --line-strong: rgb(11 13 31 / 0.28);
  --blue: #2563eb;
  --error: #c2264b;
  --brand: linear-gradient(110deg, #7c3aed 0%, #2563eb 55%, #06b6d4 100%);
  --text-brand: linear-gradient(100deg, #7c3aed 0%, #2563eb 50%, #0891b2 100%);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --dur: 0.55s;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--fg);
  font: 400 16px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

/* Barre de progression */
.progress { position: fixed; inset: 0 0 auto; height: 3px; background: rgb(11 13 31 / 0.06); z-index: 10; }
.progress-bar { display: block; height: 100%; width: 0; background: var(--brand); transition: width 0.5s var(--ease); }

/* En-tête */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px clamp(20px, 5vw, 48px) 0;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font: 700 16px/1 "Sora", sans-serif; letter-spacing: -0.02em; }
.text-gradient { background: var(--text-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.counter { font-size: 13px; color: var(--mist); font-variant-numeric: tabular-nums; }

/* Scène : toutes les étapes sont empilées dans la même cellule de grille */
.stage-wrap {
  flex: 1;
  display: grid;
  align-items: center;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 24px clamp(20px, 5vw, 32px) 96px;
}
.stage { display: grid; position: relative; }

/* L'attribut hidden doit toujours l'emporter (sinon display: grid garde le formulaire visible). */
[hidden] { display: none !important; }

/*
  Animations limitées à opacity + transform (translate3d) : ce sont les seules propriétés
  que Safari iOS et Chrome Android animent entièrement sur le GPU, donc sans saccade.
*/
.step {
  grid-area: 1 / 1;
  align-self: center;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 56px, 0) scale(0.98);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, opacity;
  transition:
    opacity 0.4s var(--ease),
    transform var(--dur) var(--ease),
    visibility 0s linear var(--dur);
}
.step.is-active {
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0);
  transition:
    opacity var(--dur) var(--ease),
    transform var(--dur) var(--ease),
    visibility 0s;
}
/* La question répondue part vers le haut ; au retour, elle revient d'en haut. */
.step.is-past { transform: translate3d(0, -56px, 0) scale(0.98); }

/* Flou de sortie : uniquement sur ordinateur (souris), trop coûteux sur mobile. */
@media (hover: hover) and (pointer: fine) {
  .step { filter: blur(6px); transition: opacity 0.4s var(--ease), transform var(--dur) var(--ease), filter 0.4s var(--ease), visibility 0s linear var(--dur); }
  .step.is-active { filter: none; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), filter var(--dur) var(--ease), visibility 0s; }
}

/* Entrée en cascade des éléments de la question active (l'ordre --i est posé par script.js). */
.step .anim {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.step.is-active .anim {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition: opacity 0.5s var(--ease), transform 0.6s var(--ease);
  transition-delay: calc(120ms + var(--i, 0) * 60ms);
}
/* En revenant en arrière, la cascade part d'en haut. */
.stage.going-back .step .anim { transform: translate3d(0, -18px, 0); }
.stage.going-back .step.is-active .anim { transform: translate3d(0, 0, 0); }

/* Mobile : cascade plus courte pour un rendu plus vif. */
@media (pointer: coarse) {
  .step.is-active .anim { transition-delay: calc(80ms + var(--i, 0) * 40ms); }
}

/* Questions */
.qnum {
  margin: 0 0 10px;
  display: flex; align-items: center; gap: 6px;
  font: 600 14px/1 "Inter", sans-serif; color: var(--blue);
}
.title {
  display: block;
  margin: 0;
  padding: 0;
  font: 600 clamp(1.5rem, 1.15rem + 1.6vw, 2.125rem)/1.2 "Sora", sans-serif;
  letter-spacing: -0.025em;
  color: var(--fg);
  text-wrap: balance;
}
h1.title { font-weight: 700; font-size: clamp(2rem, 1.5rem + 2.4vw, 2.875rem); line-height: 1.08; letter-spacing: -0.03em; }
.lead { margin: 14px 0 0; color: var(--mist); font-size: 1.125rem; max-width: 34rem; }
.sub { margin: 8px 0 0; color: var(--mist); font-size: 15px; }

/* Champs texte en ligne */
.line {
  display: block;
  width: 100%;
  margin-top: 28px;
  padding: 6px 0 10px;
  border: 0;
  border-bottom: 2px solid var(--line-strong);
  background: transparent;
  color: var(--fg);
  font: 400 clamp(1.25rem, 1.05rem + 0.9vw, 1.625rem)/1.4 "Inter", sans-serif;
  border-radius: 0;
  transition: border-color 0.2s;
}
.line::placeholder { color: rgb(86 93 124 / 0.45); }
.line:hover { border-bottom-color: rgb(11 13 31 / 0.45); }
.line:focus { outline: none; border-bottom-color: var(--blue); }
.area { resize: none; min-height: 3.2em; font-size: clamp(1.125rem, 1rem + 0.6vw, 1.375rem); }
[aria-invalid="true"] { border-bottom-color: var(--error) !important; }

/* Choix (radio / cases à cocher) */
.group { margin: 0; padding: 0; border: 0; min-width: 0; }
.options { display: grid; gap: 10px; margin-top: 26px; max-width: 30rem; }
.option {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  min-height: 52px; padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px; cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, transform 0.12s;
}
.option:hover { border-color: rgb(37 99 235 / 0.55); }
.option:active { transform: scale(0.99); }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.key {
  flex: none;
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--ink);
  font: 600 12px/1 "Inter", sans-serif; color: var(--mist);
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.option:has(input:checked) { border-color: var(--blue); background: rgb(37 99 235 / 0.06); }
.option:has(input:checked) .key { background: var(--blue); border-color: var(--blue); color: #fff; }
.option:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }
.option.flash { animation: flash 0.35s ease; }
@keyframes flash { 50% { background: rgb(37 99 235 / 0.14); } }
.invalid .option { border-color: rgb(194 38 75 / 0.55); }

/* Messages */
.error { margin: 12px 0 0; color: var(--error); font-size: 14.5px; }
.error:empty { display: none; }
.form-error { margin: 14px 0 0; color: var(--error); font-size: 14.5px; }
.form-error:empty { display: none; }

/* Actions */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; margin-top: 30px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 48px; padding: 0 26px;
  border: 0; border-radius: 999px;
  background: var(--brand); color: #fff;
  font: 500 15.5px/1 "Inter", sans-serif; cursor: pointer;
  transition: filter 0.2s, transform 0.12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.btn:disabled { cursor: progress; filter: saturate(0.6) brightness(0.95); transform: none; }
.spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.4); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.btn.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.kbd-hint { font-size: 13px; color: var(--mist); }
kbd { font: 500 12px/1 "Inter", sans-serif; padding: 3px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface); }

/* Flèches haut / bas */
.arrows {
  position: fixed; right: clamp(16px, 4vw, 40px); bottom: clamp(16px, 4vw, 32px);
  display: flex; overflow: hidden;
  border-radius: 10px; background: var(--brand);
  box-shadow: 0 8px 24px -10px rgb(37 99 235 / 0.5);
}
.arrows button {
  display: grid; place-items: center;
  width: 42px; height: 38px; border: 0; background: transparent; color: #fff; cursor: pointer;
  transition: background-color 0.2s;
}
.arrows button + button { border-left: 1px solid rgb(255 255 255 / 0.25); }
.arrows button:hover:not(:disabled) { background: rgb(255 255 255 / 0.15); }
.arrows button:disabled { opacity: 0.4; cursor: default; }
.arrows button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.arrows[hidden] { display: none; }

/* Champ piège anti-spam */
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Confirmation */
.success { outline: none; }
.success > * { animation: rise 0.7s var(--ease) both; }
.success > :nth-child(2) { animation-delay: 0.08s; }
.success > :nth-child(3) { animation-delay: 0.16s; }
.success > :nth-child(4) { animation-delay: 0.24s; }
.success svg { animation: pop 0.6s var(--ease) both; }
.success svg path { stroke-dasharray: 14; stroke-dashoffset: 14; animation: draw 0.45s 0.3s ease-out forwards; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
.success svg { color: #0891b2; }
.success .title { margin-top: 18px; }
.success a { color: inherit; }
.link {
  margin-top: 22px; padding: 0; border: 0; background: none;
  color: var(--blue); font: 500 15px "Inter", sans-serif; cursor: pointer;
}
.link:hover { text-decoration: underline; text-underline-offset: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }

/* Mobile */
@media (max-width: 560px) {
  .stage-wrap { align-items: start; padding-top: 12vh; }
  .kbd-hint { display: none; }
  .btn { height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .step, .step.is-active, .step.is-past, .step .anim, .stage.going-back .step .anim { transform: none !important; filter: none !important; }
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
