:root {
  --accent: #5b4bff;
  --bg: #ffffff;
  --text: #16161d;
  --on-accent: #fff;
  --radius: 14px;
  color-scheme: light;
  --safe-top: env(safe-area-inset-top, 0px);
}
/* iOS : certains navigateurs (Brave, vues intégrées) renvoient 0 pendant le chargement
   alors que la page passe sous la barre d'état ; on garde un plancher stable. */
@supports (-webkit-touch-callout: none) {
  :root { --safe-top: max(env(safe-area-inset-top, 0px), 47px); }
}

/* Thème sombre : activé par app.js quand la couleur de fond du formulaire est sombre. */
:root[data-scheme="dark"] {
  color-scheme: dark;
  --surface: color-mix(in srgb, var(--text) 7%, var(--bg));
  --surface-on: color-mix(in srgb, var(--accent) 22%, var(--bg));
  --line: color-mix(in srgb, var(--text) 18%, transparent);
  --line-strong: color-mix(in srgb, var(--text) 32%, transparent);
  --error: #ff8a80;
}
:root[data-scheme="dark"] body { background-image: radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%); background-attachment: fixed; }
:root[data-scheme="dark"] .progress { background: color-mix(in srgb, var(--text) 14%, transparent); }
:root[data-scheme="dark"] .subtitle, :root[data-scheme="dark"] .description { opacity: .78; }
:root[data-scheme="dark"] .hint, :root[data-scheme="dark"] .scale-labels { opacity: .7; }
:root[data-scheme="dark"] .ghost { border-color: var(--line-strong); }
:root[data-scheme="dark"] .primary { box-shadow: 0 6px 24px color-mix(in srgb, var(--accent) 35%, transparent); }
:root[data-scheme="dark"] .primary:disabled { box-shadow: none; }
:root[data-scheme="dark"] .field { border-bottom-color: var(--line-strong); caret-color: var(--accent); }
:root[data-scheme="dark"] .field::placeholder { color: color-mix(in srgb, var(--text) 40%, transparent); }
:root[data-scheme="dark"] .field:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--bg) inset;
}
:root[data-scheme="dark"] .choice:not(.on),
:root[data-scheme="dark"] .cell:not(.on) { background: var(--surface); border-color: var(--line); }
:root[data-scheme="dark"] .choice:hover:not(.on),
:root[data-scheme="dark"] .cell:hover:not(.on) { border-color: var(--line-strong); }
:root[data-scheme="dark"] .choice.on { background: var(--surface-on); border-color: var(--accent); }
:root[data-scheme="dark"] .choice:not(.on) .key { border-color: var(--line-strong); color: var(--text); }
:root[data-scheme="dark"] .star { color: color-mix(in srgb, var(--text) 28%, transparent); }
:root[data-scheme="dark"] .star.on { color: var(--accent); }
:root[data-scheme="dark"] .error { color: var(--error); }
:root[data-scheme="dark"] :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
body[data-font="serif"] { font-family: "New York", "Iowan Old Style", Georgia, serif; }
body[data-font="rounded"] { font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif; }

.progress { position: fixed; inset: var(--safe-top) 0 auto 0; height: 6px; background: color-mix(in srgb, var(--text) 8%, transparent); z-index: 2; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 0 6px 6px 0; transition: width .5s cubic-bezier(.2, .8, .2, 1); }

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(68px + var(--safe-top)) max(20px, env(safe-area-inset-right)) 32px max(20px, env(safe-area-inset-left));
}

.screen {
  width: 100%;
  max-width: 640px;
  animation: enter .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes enter { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.screen.back { animation-name: enter-back; }
@keyframes enter-back { from { opacity: 0; transform: translateX(-22px); } to { opacity: 1; transform: none; } }
.screen.still { animation: none; }
.screen.leaving { animation: leave .19s cubic-bezier(.4, 0, 1, 1) forwards; pointer-events: none; }
@keyframes leave { to { opacity: 0; transform: translateY(-14px) scale(.985); } }
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; } .progress-bar { transition: none; }
  .pop, .star.fresh, .choice.on .key { animation: none !important; }
}

h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.02em; }
h2 { font-size: clamp(22px, 5vw, 28px); line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.01em; }
.subtitle, .description { opacity: .7; margin: 0 0 24px; }
.counter { font-size: 14px; font-weight: 500; letter-spacing: .02em; font-variant-numeric: tabular-nums; margin: 0 0 10px; color: color-mix(in srgb, var(--text) 60%, transparent); }
.counter strong { color: var(--accent); font-weight: 700; }
.req { color: var(--accent); }
.hint { font-size: 14px; opacity: .55; margin-top: 14px; }

.media { display: block; width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius); margin: 0 0 20px; background: color-mix(in srgb, var(--text) 5%, transparent); }
.media.video { position: relative; aspect-ratio: 16 / 9; max-height: none; overflow: hidden; }
.media.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.primary {
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  font-weight: 600;
  min-height: 50px;
  transition: transform .12s ease, opacity .2s;
}
.primary:active { transform: scale(.97); }
.primary:disabled { opacity: .6; }
.ghost {
  background: transparent; color: var(--text); border: 1px solid color-mix(in srgb, var(--text) 15%, transparent);
  border-radius: 999px; width: 50px; height: 50px; font-size: 20px;
}

/* 353 px = largeur utile d'un iPhone : sur grand écran, les boutons gardent la même taille. */
.actions { display: flex; gap: 12px; margin-top: 28px; max-width: 353px; }
.actions .primary { flex: 1; }

.field {
  width: 100%;
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 2px solid color-mix(in srgb, var(--text) 20%, transparent);
  padding: 12px 2px;
  border-radius: 0;
  outline: none;
  resize: vertical;
}
.field:focus { border-bottom-color: var(--accent); }

.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 14px 16px; min-height: 52px;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
  border: 1.5px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius);
  transition: background .15s, border-color .15s;
}
.choice.on { background: color-mix(in srgb, var(--accent) 16%, var(--bg)); border-color: var(--accent); }
.key {
  display: inline-grid; place-items: center; width: 26px; height: 26px; flex: none;
  border-radius: 7px; font-size: 13px; font-weight: 700;
  border: 1.5px solid color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent);
}
.choice.on .key { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.rating { display: flex; gap: 8px; flex-wrap: wrap; }
.star { font-size: 40px; background: none; border: 0; color: color-mix(in srgb, var(--text) 18%, transparent); padding: 4px; line-height: 1; }
.star.on { color: var(--accent); }

.scale { display: grid; grid-template-columns: repeat(auto-fit, minmax(40px, 1fr)); gap: 6px; }
.cell {
  height: 48px; border-radius: 10px; color: var(--text); font-weight: 600;
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
  border: 1.5px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.cell.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.scale-labels { display: flex; justify-content: space-between; font-size: 14px; opacity: .6; margin-top: 8px; }

.error { color: #d92d20; font-size: 15px; margin: 12px 0 0; }

.thanks { text-align: center; }
.check {
  width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 34px; color: var(--on-accent); background: var(--accent);
}

.loader { display: flex; align-items: center; gap: 10px; opacity: .6; }
.loader span {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Image de fond du thème : derrière tout le formulaire, avec un voile de la couleur d'arrière-plan
   (réglable par le créateur) pour garder le texte lisible, en clair comme en sombre. */
#bg { position: fixed; inset: 0; z-index: 0; display: none; background-size: cover; background-position: center; }
#bg.on { display: block; }
#bg::after { content: ""; position: absolute; inset: 0; background: var(--bg); opacity: var(--veil, .6); }
main, footer { position: relative; z-index: 1; }

footer { text-align: center; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); font-size: 13px; }
footer a { color: inherit; opacity: .55; text-decoration: none; }

.scheme-toggle {
  position: fixed; z-index: 3;
  top: calc(var(--safe-top) + 12px); right: max(14px, env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px; line-height: 1;
  color: var(--text);
  background: color-mix(in srgb, var(--text) 8%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--text) 15%, transparent);
}
.scheme-toggle:active { transform: scale(.94); }

/* Retour visuel à la sélection */
.choice { transition: transform .12s ease, background .18s, border-color .18s, box-shadow .18s; }
.choice:active, .cell:active { transform: scale(.985); }
.choice.on { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.key { transition: background .18s, color .18s, border-color .18s; }
.choice.on .key { animation: key-in .28s cubic-bezier(.3, 1.6, .5, 1); }
.pop { animation: pop .3s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes pop { 0% { transform: scale(.96); } 55% { transform: scale(1.02); } 100% { transform: none; } }
@keyframes key-in { from { transform: scale(.6) rotate(-12deg); } to { transform: none; } }
.cell { transition: transform .12s ease, background .18s, border-color .18s; }
.star { transition: transform .12s ease, color .18s; }
.star:active { transform: scale(.9); }
.star.fresh { animation: star-in .32s var(--d, 0ms) cubic-bezier(.3, 1.7, .5, 1) both; }
@keyframes star-in { from { transform: scale(.6); } to { transform: none; } }
.primary { transition: transform .12s ease, opacity .2s, box-shadow .2s; }
.screen.leaving .primary { transform: scale(.97); }

/* Champ piège anti-robots : hors écran (une classe, car la CSP interdit les styles en ligne). */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
