:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --ink: #1c1c1f;
  --muted: #64646b;
  --line: #dcdad3;
  --accent: #2f45b8;
  --accent-ink: #ffffff;
  --accent-soft: #e5e8f8;
  --ai: #6d35b0;
  --ai-soft: #efe6f8;
  --ai-ink: #ffffff;
  --ok: #1f7a46;
  --warn: #a14b00;
  --danger: #b3261e;
  --ov0: #d9480f;
  --ov1: #0b7285;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17171a; --surface: #222226; --surface-2: #2b2b30; --ink: #f1f0ec; --muted: #a3a3ab; --line: #3a3a41;
    --accent: #8c9cf2; --accent-ink: #111; --accent-soft: #2b3260; --ai: #c39af0; --ai-soft: #3a2a50; --ai-ink: #1d1029;
    --ok: #6fcf97; --warn: #f0a35c; --danger: #f2827a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17171a; --surface: #222226; --surface-2: #2b2b30; --ink: #f1f0ec; --muted: #a3a3ab; --line: #3a3a41;
  --accent: #8c9cf2; --accent-ink: #111; --accent-soft: #2b3260; --ai: #c39af0; --ai-soft: #3a2a50; --ai-ink: #1d1029;
  --ok: #6fcf97; --warn: #f0a35c; --danger: #f2827a; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.hidden { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; padding: .65em .75em; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  min-height: 44px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
label.field { display: block; margin: 0 0 1rem; }
label.field > span { display: block; font-weight: 600; margin-bottom: .3rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 44px;
  padding: .55em 1em; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: .3em .7em; font-size: .9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stack > * + * { margin-top: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.notice { padding: .7rem .9rem; border-radius: 10px; background: var(--surface-2); }
.notice.err { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.notice.ok { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); color: var(--ok); }

/* choix à deux boutons (accord) */
.choice { display: grid; gap: .5rem; }
.choice button {
  text-align: left; padding: .75em .9em; border-radius: 10px; border: 2px solid var(--line); background: var(--surface);
  cursor: pointer; min-height: 48px;
}
.choice button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* éditeur de chaîne */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.step.open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.step.empty:not(.open) .step-title { color: var(--muted); }
.step-head { display: flex; align-items: center; gap: .25rem; padding: .35rem .35rem .35rem .2rem; }
.step-num {
  flex: none; width: 1.9rem; height: 1.9rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 700; font-size: .9rem;
}
.step.filled .step-num { background: var(--accent); color: var(--accent-ink); }
.step-toggle {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: .4rem .3rem; cursor: pointer;
  min-height: 44px;
}
.step-title { font-weight: 650; display: block; }
.step-sum { display: block; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  flex: none; width: 40px; height: 40px; border-radius: 9px; border: 1px solid transparent; background: none;
  cursor: pointer; display: grid; place-items: center; color: var(--muted); font-size: 1.05rem;
}
.iconbtn:hover { border-color: var(--line); color: var(--ink); }
.iconbtn[disabled] { opacity: .25; cursor: default; }
.step-body { padding: .2rem .9rem 1rem; }
.step-body h4 { margin: .9rem 0 .45rem; font-size: .92rem; }
.step-body h4:first-child { margin-top: .2rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: .4em .8em;
  min-height: 40px; cursor: pointer; font-size: .95rem;
}
.chip.ai { border-style: dashed; border-color: color-mix(in srgb, var(--ai) 55%, var(--line)); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); border-style: solid; }
.chip.ai[aria-pressed="true"] { background: var(--ai); border-color: var(--ai); color: var(--ai-ink); }
.chip.more { background: var(--surface-2); border-style: solid; }
.addline { display: flex; gap: .4rem; margin-top: .5rem; }
.addline input { flex: 1; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-left: 1.5px solid var(--line); background: var(--surface); padding: .55em .2em; min-height: 44px; cursor: pointer; font-size: .92rem; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ai); color: var(--ai-ink); font-weight: 650; }
.seg button[data-level="0"][aria-pressed="true"] { background: var(--muted); color: var(--bg); }
.step-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.step-actions .btn { flex: 1; }
.removed { margin-top: 1rem; }
.removed .chip { border-style: dashed; color: var(--muted); }

/* page participant */
.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }
.brand { display: flex; align-items: center; gap: .6rem; margin: .4rem 0 1rem; }
.brand img { width: 34px; height: 34px; }
.brand b { font-size: 1.05rem; }
.sendbar {
  position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); backdrop-filter: blur(6px);
}
.sendbar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: .6rem; align-items: center; }
.sendbar .status { flex: 1; font-size: .88rem; color: var(--muted); min-width: 0; }
.big-ok { font-size: 3rem; line-height: 1; }

/* modale (animateur) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: start center; overflow: auto; padding: 24px 12px; z-index: 50; }
.modal .panel { background: var(--bg); border-radius: 16px; width: min(760px, 100%); padding: 18px; }
.row select { width: auto; flex: 1 1 200px; }
