html, body { height: 100%; }
body {
  background: var(--navy);
  color: var(--white);
  overflow: hidden;
  --out: #1b4b57;          /* outgoing bubble: brand teal, WhatsApp's own dark-mode hue */
  --col: 680px;            /* conversation column */
}
::selection { background: var(--yellow); color: var(--navy); }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
textarea { caret-color: var(--yellow); }

/* Photo only on welcome / thanks; questions sit on plain navy */
.backdrop {
  position: fixed; inset: 0; z-index: 0;
  background: url('stone.jpg') center / cover no-repeat;
  filter: grayscale(.35);
  opacity: 0;
  transition: opacity .8s var(--ease-out);
}
.backdrop::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(15,24,41,.55) 0%, rgba(15,24,41,.2) 40%, rgba(15,24,41,.88) 100%);
}
body[data-phase="intro"] .backdrop, body[data-phase="outro"] .backdrop { opacity: .95; }

.app {
  position: relative; z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 5; }
.progress i {
  display: block; height: 100%;
  background: var(--yellow);
  transform-origin: left;
  transform: scaleX(var(--p, 0));
  transition: transform .6s var(--ease-out);
}

/* Header: back · logo · step */
.top {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  width: min(100%, calc(var(--col) + 32px)); margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 8px 0;
  height: 60px;
}
.top .logo { justify-self: center; width: 104px; color: var(--white); }
.back {
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--white);
  display: grid; place-items: center;
}
.back:hover { background: rgba(255,255,255,.08); }
.counter { justify-self: end; padding-right: 8px; font-size: 20px; color: var(--ink-mute); font-variant-numeric: tabular-nums; white-space: nowrap; }
.counter b { color: var(--white); font-weight: 600; }
body:not([data-phase="question"]) .back,
body:not([data-phase="question"]) .counter { visibility: hidden; }

/* Stage */
.stage { position: relative; overflow: hidden; }
.screen {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--navy-3) transparent;
}

/* Conversation column, anchored to the bottom like a chat */
.thread {
  width: min(100%, var(--col));
  margin: 0 auto;
  min-height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 24px 16px 12px;
}
.title {
  font-weight: 200;
  font-size: clamp(27px, 4.6vw, 40px);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
  max-width: 22ch;
}
.title strong { font-weight: 800; }
.help { margin: 12px 0 0; font-size: 16px; line-height: 1.5; color: var(--ink-soft); max-width: 46ch; }

.sys {
  align-self: center;
  margin: 28px 0 0;
  padding: 7px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  color: var(--ink-soft);
  font-size: 13.5px; line-height: 1.45; text-align: center;
  max-width: 34ch;
}

/* Bubbles */
.msgs { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-top: 22px; }
.msgs:empty { display: none; }
.msg {
  position: relative;
  max-width: min(86%, 460px);
  padding: 9px 14px;
  border-radius: 14px;
  background: var(--out);
  font-size: 16px; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
  cursor: pointer;
  transition: box-shadow .2s;
  transform-origin: bottom right;
}
.msg.new { animation: pop .26s var(--ease-out) both; }
.msg.tail { border-top-right-radius: 3px; }
.msg.sel { box-shadow: 0 0 0 2px var(--yellow); }
.msg .meta {
  float: right;
  display: inline-flex; align-items: center; gap: 3px;
  margin: 8px 0 -3px 12px;
  font-size: 11.5px; line-height: 1; color: rgba(255,255,255,.62);
  font-variant-numeric: tabular-nums;
}
.msg.voice { padding: 6px 8px 6px 6px; width: min(86%, 340px); }
.msg.voice .vn { --vn-bg: transparent; --vn-bar: rgba(255,255,255,.35); --vn-time: rgba(255,255,255,.62); grid-template-columns: 44px 1fr; padding: 0 4px 0 0; gap: 10px; }
.msg.voice .meta { position: absolute; right: 10px; bottom: 7px; margin: 0; float: none; }
.msg.voice .vn-time { position: absolute; left: 60px; bottom: 7px; min-width: 0; font-size: 11.5px; line-height: 1; text-align: left; }
.msg.voice .vn-wave { height: 28px; margin: 2px 0 14px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.92); } }

.msg-actions { display: flex; gap: 2px; margin: 2px 0 6px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent;
  padding: 7px 10px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 600;
  color: var(--ink-soft);
}
.chip-btn svg { width: 17px; height: 17px; }
.chip-btn:hover { color: var(--white); background: rgba(255,255,255,.07); }
.chip-btn.danger { color: var(--coral); }
.chip-btn.danger:hover { background: rgba(255,121,121,.1); }

/* Poll (choice question) */
.poll { margin-top: 22px; border-radius: 14px; background: var(--navy-2); overflow: hidden; }
.choice {
  display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 16px 18px;
  border: 0; border-top: 1px solid rgba(255,255,255,.07);
  background: transparent;
  font-size: 16px; line-height: 1.4;
}
.choice:first-child { border-top: 0; }
.choice:hover { background: rgba(255,255,255,.04); }
.choice .box {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1.6px solid rgba(255,255,255,.4);
  display: grid; place-items: center; color: var(--navy);
  transition: background-color .2s, border-color .2s;
}
.choice .box svg { width: 16px; height: 16px; stroke-width: 2.8; opacity: 0; transform: scale(.4); transition: all .25s var(--ease-out); }
.choice[aria-checked="true"] .box { background: var(--yellow); border-color: var(--yellow); }
.choice[aria-checked="true"] .box svg { opacity: 1; transform: none; }

.skip-row { display: flex; justify-content: flex-end; margin-top: 16px; }
.skip-row:empty { display: none; }
.go {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0;
  height: 52px; padding: 0 26px 0 28px;
  border-radius: var(--r-pill);
  background: var(--yellow); color: var(--navy);
  font-family: var(--f-label); font-weight: 600; font-size: 23px; letter-spacing: .04em; text-transform: uppercase;
  text-decoration: none;
  transition: transform .2s var(--ease-out), background-color .2s;
}
.go svg { width: 20px; height: 20px; stroke-width: 2.2; }
.go:hover { background: #ffcd80; }
.go:active { transform: scale(.97); }
.go.ghost { height: 44px; padding: 0 18px 0 20px; font-size: 20px; background: transparent; color: var(--ink-soft); box-shadow: inset 0 0 0 1px rgba(255,255,255,.22); }
.go.ghost:hover { color: var(--white); box-shadow: inset 0 0 0 1px rgba(255,255,255,.5); }

.error { margin: 10px 0 0; text-align: right; color: var(--coral); font-size: 14px; font-weight: 600; }
.error:empty { display: none; }

/* ---------- Dock: WhatsApp input bar ---------- */
.dock {
  width: min(100%, calc(var(--col) + 16px));
  margin: 0 auto;
  padding: 6px 8px max(10px, env(safe-area-inset-bottom));
}
body:not([data-phase="question"]) .dock, .dock:empty { display: none; }

.composer { position: relative; }
.c-row { display: flex; align-items: flex-end; gap: 6px; }
.pill {
  flex: 1; min-width: 0;
  min-height: 50px;
  display: flex; align-items: center;
  padding: 0 18px;
  border-radius: 25px;
  background: var(--navy-2);
  overflow: hidden;
}
.pill textarea {
  flex: 1; min-width: 0;
  border: 0; background: transparent; resize: none;
  padding: 13px 0; margin: 0;
  max-height: 148px;
  font-size: 16px; line-height: 1.5;
  color: var(--white);
}
.pill textarea:focus { outline: none; }
.pill textarea::placeholder { color: var(--ink-mute); }

/* Mic: WhatsApp's big round button while nothing is answered… */
.c-mic {
  flex: none; position: relative; z-index: 2;
  width: 50px; height: 50px; border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: var(--yellow); color: var(--navy);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .18s var(--ease-out), background-color .2s, width .25s var(--ease-out), height .25s var(--ease-out), margin .25s var(--ease-out);
}
.c-mic svg { width: 24px; height: 24px; pointer-events: none; }
.c-mic:active { transform: scale(.94); }

/* …then it tucks into the field and the round button becomes "Suivant" */
.c-next {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 50px; padding: 0 16px 0 20px;
  border: 0; border-radius: 25px;
  background: var(--yellow); color: var(--navy);
  font-family: var(--f-label); font-weight: 600; font-size: 22px; letter-spacing: .04em; text-transform: uppercase;
  animation: pop .28s var(--ease-out) both; transform-origin: right;
  transition: opacity .2s, background-color .2s;
}
.c-next svg { width: 20px; height: 20px; stroke-width: 2.2; }
.c-next:hover { background: #ffcd80; }
.c-next:active { transform: scale(.96); }
.c-next[aria-disabled="true"] { opacity: .4; }
.composer.with-voice:not(.has-answer) .c-next { display: none; }
.composer.with-voice.has-answer .pill { padding-right: 46px; }
.composer.with-voice.has-answer .c-mic {
  width: 40px; height: 40px; margin: 0 0 5px -52px;
  background: transparent; color: var(--ink-soft);
}
.composer.with-voice.has-answer .c-mic:hover { color: var(--white); background: rgba(255,255,255,.08); }
.kind-choice .c-row { justify-content: flex-end; }
.kind-choice .c-next { padding: 0 24px 0 28px; }

/* Hold-to-record */
.c-hold { display: none; flex: 1; align-items: center; gap: 10px; height: 50px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--coral); flex: none; animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-time { font-weight: 600; font-size: 15px; min-width: 38px; }
.slide {
  flex: 1; text-align: center;
  display: inline-flex; justify-content: center; align-items: center; gap: 2px;
  font-size: 14px; color: var(--ink-soft); white-space: nowrap;
  opacity: var(--slide-o, 1);
  transform: translateX(calc(var(--dx, 0px) * .5));
}
.slide svg { width: 18px; height: 18px; animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(-4px); } }
.lock-hint {
  display: none;
  position: absolute; right: 7px; bottom: 80px;
  width: 36px; padding: 10px 0 8px;
  border-radius: 18px;
  background: var(--navy-2);
  color: var(--ink-soft);
  flex-direction: column; align-items: center; gap: 4px;
  transform: translateY(calc(var(--dy, 0px) * .45));
}
.lock-hint svg { width: 18px; height: 18px; }
.lock-hint svg + svg { animation: lift 1.1s ease-in-out infinite; }
@keyframes lift { 50% { transform: translateY(-4px); } }

.composer[data-state="hold"] textarea { display: none; }
.composer[data-state="hold"] .c-hold { display: flex; }
.composer[data-state="hold"] .lock-hint { display: flex; }
.composer[data-state="hold"] .c-mic {
  width: 50px; height: 50px; margin: 0;
  background: var(--coral); color: var(--white);
  transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(1.45);
  transition: background-color .2s;
}
.composer[data-state="hold"] .c-next { display: none; }
.composer[data-state="hold"] .pill { padding-right: 18px; }

/* Locked recording */
.c-locked { display: none; flex-direction: column; gap: 6px; }
.composer[data-state="locked"] .c-row { display: none; }
.composer[data-state="locked"] .c-locked { display: flex; animation: pop .22s var(--ease-out) both; transform-origin: bottom; }
.lk-top { display: flex; align-items: center; gap: 12px; height: 50px; padding: 0 18px; border-radius: 25px; background: var(--navy-2); font-variant-numeric: tabular-nums; }
.lk-top canvas { flex: 1; min-width: 0; height: 30px; }
.lk-actions { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.lk-btn {
  width: 50px; height: 50px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-soft);
  display: grid; place-items: center;
}
.lk-btn svg { width: 24px; height: 24px; }
.lk-btn:hover { background: rgba(255,255,255,.07); color: var(--white); }
.lk-btn.trash:hover { color: var(--coral); }
.lk-btn.pause { color: var(--coral); }
.lk-btn.send { background: var(--yellow); color: var(--navy); }
.lk-btn.send svg { width: 22px; height: 22px; transform: translateX(1px); }
.composer.paused .rec-dot { animation: none; background: var(--ink-mute); }

/* ---------- Intro / sending / thanks ---------- */
.screen-inner {
  width: min(100%, 820px);
  margin: 0 auto;
  min-height: 100%;
  padding: clamp(28px, 7vh, 72px) clamp(20px, 5vw, 56px) 48px;
  display: flex; flex-direction: column; justify-content: center;
}
.title.xl { font-size: clamp(44px, 9vw, 96px); max-width: 12ch; line-height: 1; letter-spacing: -0.025em; }
.lede { margin: 24px 0 0; font-size: clamp(17px, 1.9vw, 21px); line-height: 1.55; color: #e3e2e2; max-width: 44ch; }
.meta-line { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 26px; font-size: 21px; color: var(--ink-soft); }
.intro-actions { margin-top: 36px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.intro-actions .go { height: 58px; font-size: 25px; padding: 0 30px 0 32px; }
.restart {
  flex-basis: 100%;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  font-size: 15px; color: #e3e2e2;
}
.restart-link {
  border: 0; background: none; padding: 6px 0;
  color: var(--ink-soft); font-size: 15px; font-weight: 500;
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: rgba(255,255,255,.35);
}
.restart-link:hover { color: var(--white); text-decoration-color: currentColor; }
.restart-link.strong { color: var(--coral); font-weight: 700; text-decoration-color: currentColor; }
.link-label {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 40px;
  color: var(--white); text-decoration: none; font-size: 26px;
}
.link-label svg { width: 20px; height: 20px; transition: transform .3s var(--ease-out); }
.link-label:hover svg { transform: translate(3px, -3px); }
.sendbar { margin-top: 32px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; max-width: 420px; }
.sendbar i { display: block; height: 100%; background: var(--yellow); transform-origin: left; transform: scaleX(var(--p, .05)); transition: transform .5s var(--ease-out); }

.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 10;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 440px);
  padding: 12px 16px; border-radius: 12px;
  background: var(--white); color: var(--navy);
  font-size: 14.5px; font-weight: 600; line-height: 1.4; text-align: center;
  box-shadow: 0 14px 32px -12px rgba(0,0,0,.6);
  transition: all .35s var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { display: grid; place-items: center; height: 100%; color: var(--ink-mute); font-size: 24px; }

@media (max-width: 640px) {
  .top .logo { width: 96px; }
  body[data-phase="intro"] .screen-inner, body[data-phase="outro"] .screen-inner { justify-content: flex-end; padding-bottom: 7vh; }
  .intro-actions .go { width: 100%; }
  .restart { justify-content: center; text-align: center; }
}

/* ---------- Conversation history ---------- */
.qinner { display: contents; }
.qblock { display: flex; flex-direction: column; }
.history:empty { display: none; }
.past { display: flex; flex-direction: column; margin-bottom: 30px; }
.past-q { margin: 0 0 10px; max-width: 36ch; font-size: 16px; line-height: 1.4; font-weight: 300; color: var(--ink-soft); }
.past-q strong { font-weight: 700; color: var(--white); }
.past-msgs { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.past .msg { cursor: default; }
.past .past-skip { align-self: flex-end; margin: 0; }
.past-edit {
  align-self: flex-end;
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 4px; padding: 6px 8px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-mute);
  font-size: 13px; font-weight: 600;
}
.past-edit svg { width: 14px; height: 14px; }
.past-edit:hover { color: var(--white); background: rgba(255,255,255,.06); }
.msg.picks { display: flex; flex-direction: column; gap: 6px; white-space: normal; }
.msg.picks > span:not(.meta) { display: flex; gap: 8px; align-items: flex-start; }
.msg.picks svg { flex: none; width: 17px; height: 17px; margin-top: 2px; color: var(--yellow); stroke-width: 2.6; }
.history:not(:empty) + .qblock { padding-top: 14px; border-top: 1px solid rgba(255,255,255,.07); }

/* ---------- White ground for the questions; welcome / thanks keep the photo ---------- */
body {
  --ink: #0f1829;
  --ink-2: #4a5670;
  --ink-3: #7a8499;
  --field: #f1f3f6;
  --line: rgba(15, 24, 41, .09);
  --out: #e4eef0;             /* answer bubble: pale brand teal */
  background: #ffffff;
  color: var(--ink);
  transition: background-color .6s var(--ease-out), color .6s var(--ease-out);
}
body[data-phase="intro"], body[data-phase="outro"] { background: var(--navy); color: var(--white); }
textarea { caret-color: var(--blue); }
:focus-visible { outline-color: var(--blue); }

.progress i { background: var(--yellow-deep); }
.top .logo, .back { color: var(--ink); }
body[data-phase="intro"] .top .logo, body[data-phase="outro"] .top .logo { color: var(--white); }
.back:hover { background: var(--field); }
.counter { color: var(--ink-3); }
.counter b { color: var(--ink); }
.screen { scrollbar-color: #d5dae2 transparent; }

/* Question */
.help { color: var(--ink-2); }
.sys { background: var(--field); color: var(--ink-2); }
.sys b { color: var(--ink); }
.error { color: #c93c3c; }

/* Answers */
.msg { background: var(--out); color: var(--ink); }
.msg.sel { box-shadow: 0 0 0 2px var(--yellow-deep); }
.msg.voice .vn { --vn-bar: rgba(15, 24, 41, .22); --vn-bar-on: var(--teal); --vn-time: var(--ink-2); --vn-btn: var(--yellow); }
.msg.picks svg { color: var(--teal); }
.chip-btn { color: var(--ink-2); }
.chip-btn:hover { color: var(--ink); background: var(--field); }
.chip-btn.danger { color: #c93c3c; }
.chip-btn.danger:hover { background: #fdecec; }

/* History */
.past-q { color: var(--ink-3); }
.past-q strong { color: var(--ink); }
.past-edit { color: var(--ink-3); }
.past-edit:hover { color: var(--ink); background: var(--field); }
.history:not(:empty) + .qblock { border-top-color: var(--line); }

/* Poll */
.poll { background: #f7f8fa; box-shadow: inset 0 0 0 1px var(--line); }
.choice { color: var(--ink); border-top-color: var(--line); }
.choice:hover { background: var(--field); }
.choice .box { border-color: rgba(15, 24, 41, .3); background: #fff; }

/* Buttons */
.go.ghost { color: var(--ink-2); box-shadow: inset 0 0 0 1px rgba(15, 24, 41, .2); }
.go.ghost:hover { color: var(--ink); box-shadow: inset 0 0 0 1px rgba(15, 24, 41, .45); }

/* Input bar */
.pill { background: var(--field); }
.pill textarea { color: var(--ink); }
.pill textarea::placeholder { color: var(--ink-3); }
.composer.with-voice.has-answer .c-mic { color: var(--ink-2); }
.composer.with-voice.has-answer .c-mic:hover { color: var(--ink); background: rgba(15, 24, 41, .06); }
.slide { color: var(--ink-2); }
.lock-hint { background: #fff; color: var(--ink-2); box-shadow: 0 4px 14px -4px rgba(15, 24, 41, .25); }
.lk-top { background: var(--field); color: var(--ink); }
.lk-btn { color: var(--ink-2); }
.lk-btn:hover { color: var(--ink); background: var(--field); }
.lk-btn.pause { color: var(--coral); }
.lk-btn.send { color: var(--navy); }

/* Sending */
body[data-phase="sending"] .help { color: var(--ink-2); }
.sendbar { background: var(--field); }
.sendbar i { background: var(--yellow-deep); }

.toast { background: var(--navy); color: var(--white); }
.loading { color: var(--ink-3); }
