:root {
  --paper: #f1eee7;
  --paper-deep: #e7e2d8;
  --ink: #20221f;
  --ink-soft: #66675f;
  --line: rgba(32, 34, 31, 0.18);
  --line-strong: rgba(32, 34, 31, 0.42);
  --moss: #526452;
  --moss-dark: #3f4f40;
  --danger: #8b493f;
  --focus: #788d70;
  --ease: cubic-bezier(.22, .75, .25, 1);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.65), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

button, label:has(input[type="checkbox"]) { -webkit-tap-highlight-color: transparent; }

.page {
  width: min(100% - 40px, 1080px);
  margin: 0 auto;
  padding: 28px 0 64px;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  text-decoration: none;
}

.promise {
  margin: 0;
  color: var(--ink-soft);
  font-size: .76rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.protocol {
  position: relative;
  width: min(100%, 860px);
  margin: 7vh auto 0;
}

/* Le protocole rejoint plus vite la question sans modifier sa structure. */
.progress { margin-bottom: clamp(32px, 5vh, 54px); }

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 11px;
  color: var(--ink-soft);
  font-size: .7rem;
  font-weight: 650;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.progress-track {
  height: 2px;
  overflow: hidden;
  background: var(--line);
}

#progressBar {
  display: block;
  width: 20%;
  height: 100%;
  background: var(--moss);
  transition: width 450ms var(--ease);
}

/* Le contenu varie, mais le cadre et la navigation gardent une hauteur stable. */
form {
  display: flex;
  flex-direction: column;
  min-height: 620px;
}

.step {
  display: flex;
  flex: 1;
  flex-direction: column;
  margin: 0;
  padding: 0;
  border: 0;
  animation: step-in 480ms var(--ease) both;
}

.step.is-leaving { animation: step-out 180ms ease both; }

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

@keyframes step-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

.step-intro {
  order: -1;
  margin-bottom: 15px;
  color: var(--moss);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-style: italic;
}

.question-title {
  max-width: 760px;
  margin: 0;
  padding: 0;
  font-family: Georgia, "Times New Roman", serif;
  /* Le titre compact libère de la hauteur tout en gardant son rôle central. */
  font-size: clamp(1.5rem, 3vw, 2.35rem);
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: -0.04em;
}

.guidance {
  max-width: 590px;
  margin: 20px 0 32px;
  color: var(--ink-soft);
  font-size: .95rem;
  line-height: 1.6;
}

.hint {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: .78rem;
}

.field-label {
  display: block;
  margin: 22px 0 3px;
  color: var(--ink-soft);
  font-size: .72rem;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Q1 et Q5 partagent le même rythme de liste, sans marqueur de formulaire. */
.option-list,
.action-list {
  display: grid;
  /* La liste resserrée accueille naturellement une cinquième direction. */
  gap: 8px;
  margin-top: 4px;
}

/* Les éléments ajoutés gardent le même rythme que les champs initiaux. */
#q1ExtraOptions,
#q5ExtraActions {
  display: grid;
  gap: 8px;
}

#q1ExtraOptions:empty,
#q5ExtraActions:empty {
  display: none;
}

/* Le mode « aucune direction » neutralise visuellement sans effacer. */
.step[data-step="0"] .option-list {
  transition: opacity 180ms ease;
}

.step[data-step="0"]:has(#q1NoOption:checked) .option-list {
  opacity: .42;
}

.step[data-step="0"] .q1-option:disabled {
  cursor: not-allowed;
}

input[type="text"], textarea {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  transition: border-color 180ms ease;
}

/* Les champs gagnent six pixels de hauteur tout en gardant leur typographie. */
input[type="text"] { padding: 8px 0 9px; font-size: 1.05rem; }

/* Seule l'action non observable est marquée ; la liste reste stable. */
.q5-action.is-invalid { border-bottom-color: var(--danger); }

textarea {
  min-height: 136px;
  padding: 16px 0;
  resize: vertical;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  line-height: 1.45;
}

input[type="text"]:focus, textarea:focus { border-bottom-color: var(--focus); }
::placeholder { color: rgba(32, 34, 31, .38); }

.choice-list { display: grid; gap: 10px; }
.choice-list--grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.choice {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 54px;
  margin: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.choice:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.choice:has(input:checked) { border-color: var(--moss); background: rgba(82, 100, 82, .08); }

input[type="checkbox"] {
  appearance: none;
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

input[type="checkbox"]:checked { border: 5px solid var(--moss); }
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.choice--quiet {
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--ink-soft);
  font-size: .86rem;
}

.choice--quiet:hover { border-color: transparent; transform: none; }

.secondary-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  /* Les actions secondaires restent liées visuellement à la liste. */
  margin-top: 14px;
}

.navigation {
  position: relative;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: auto;
  /* Le repère de navigation se rapproche sans changer son ancrage. */
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.button, .text-button {
  border: 0;
  cursor: pointer;
}

.button {
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 2px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.button--primary { background: var(--moss); color: #fff; }
.button--primary:hover { background: var(--moss-dark); }
.button--primary span { margin-left: 18px; }

.button--back { margin-right: auto; background: transparent; color: var(--ink-soft); }
.button--back:hover { color: var(--ink); }

.text-button {
  padding: 5px 0;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  font-size: .82rem;
}

.text-button:disabled { opacity: .35; cursor: not-allowed; }

/* Le conteneur couvre la navigation sans participer à sa géométrie. */
.navigation-feedback {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Le feedback reste attaché à l'action qui vient d'échouer. */
.action-toast {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(320px, calc(100vw - 48px));
  padding: 10px 14px;
  border-left: 2px solid var(--danger);
  background: rgba(139, 73, 63, .08);
  color: var(--danger);
  font-size: .85rem;
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms;
  z-index: 20;
  pointer-events: none;
}

/* Seule l'opacité change : aucun mouvement ni déplacement du layout. */
.action-toast.is-visible {
  opacity: 1;
  visibility: visible;
}

/* Une vibration très courte relie discrètement l'erreur au bouton d'action. */
.button--primary.is-invalid {
  animation: action-invalid 180ms ease-out;
}

@keyframes action-invalid {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-3px); }
  70% { transform: translateX(3px); }
}

.result-panel {
  width: min(100%, 740px);
  margin: 12vh auto 0;
  animation: step-in 520ms var(--ease) both;
}

.result-kicker {
  margin: 0 0 16px;
  color: var(--moss);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.result-panel h2 {
  max-width: 660px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 6vw, 4.5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -.05em;
}

.result-panel > p:not(.result-kicker) { color: var(--ink-soft); line-height: 1.6; }
.result-panel details { margin: 40px 0 24px; border-top: 1px solid var(--line); }
.result-panel summary { padding: 16px 0; color: var(--ink-soft); cursor: pointer; font-size: .82rem; }
.json-output { overflow-x: auto; padding: 18px; background: var(--paper-deep); font-size: .72rem; line-height: 1.55; }

.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; }
[hidden] { display: none !important; }

@media (max-width: 640px) {
  .page { width: min(100% - 28px, 1080px); padding-top: 20px; }
  .masthead { align-items: center; padding-bottom: 18px; }
  .promise { max-width: 170px; text-align: right; font-size: .61rem; line-height: 1.45; }
  .protocol { margin-top: 6vh; }
  .progress { margin-bottom: 46px; }
  form { min-height: 0; }
  .question-title { font-size: clamp(2rem, 10vw, 3rem); }
  .guidance { margin: 16px 0 26px; }
  .choice-list--grid { grid-template-columns: 1fr; }
  .secondary-actions { align-items: flex-start; flex-direction: column; }
  .navigation { margin-top: 30px; }
  .button--primary { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
