/* Petit Koami — rouge profond, écarlate et graphite, selon la référence fournie. */
:root {
  --ink: #100b10;
  --bg: #140d13;
  --surface: #25151e;
  --surface-2: #3b1c29;
  --line: #633040;
  --text: #fff4f6;
  --muted: #d1b9c0;
  --accent: #dc143c;
  --accent-ink: #ffffff;
  --accent-text: #ffb3c2;
  --ok: #7cddb6;
  --danger: #ffb5ab;
  --danger-bg: #3d1720;
  --focus: #ffd4dd;

  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r-sm: 8px; --r-md: 14px; --r-lg: 22px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); font: 400 16px/1.55 var(--body); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2vw, 2.5rem); }
h2 { font-size: 1.25rem; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .875em; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); overflow-wrap: anywhere; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: var(--s3); }
.skip:focus { left: var(--s3); z-index: 50; background: var(--accent); color: var(--accent-ink); padding: var(--s2) var(--s3); border-radius: var(--r-sm); }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.quiet, .lede, .help { color: var(--muted); }
.lede { max-width: 62ch; margin-top: var(--s3); }

/* Marque */
.mark { display: flex; align-items: center; gap: var(--s2); font-family: var(--display); font-weight: 700; font-size: 1.125rem; }
.mark-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.brand-mascot { width: 48px; height: 48px; object-fit: contain; flex: none; }
.apk-download { margin-top: 24px; text-align: center; }
.apk-download a { color: var(--accent-text); }
.apk-download small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.apk-nav { text-decoration: none; }
.nav .apk-nav { display: none; }
@media (min-width: 1024px) { .nav .apk-nav { display: flex; } }
.koami-mascot { position: fixed; right: 22px; bottom: 22px; z-index: 35; display: flex; align-items: center; flex-direction: column; gap: 0; padding: 0; max-width: 190px; background: transparent; border: 0; cursor: pointer; }
.koami-mascot img { object-fit: contain; filter: drop-shadow(0 5px 8px #0006); }
.koami-mascot span { border: 1px solid var(--line); border-radius: 20px; padding: 8px 12px; background: var(--ink); color: var(--text); font: 600 12px/1.3 var(--body); box-shadow: 0 4px 20px #0004; }
.koami-mascot[data-mode="working"] img { animation: koami-bob 1.7s ease-in-out infinite alternate; }
.koami-mascot[data-mode="working"] span { border-color: var(--accent); }
.koami-mascot[data-mode="approval"] span, .koami-mascot[data-mode="question"] span { border-color: #ffd089; }
@keyframes koami-bob { to { transform: translateY(-5px) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .koami-mascot img { animation: none !important; } }
@media (max-width: 1023px) { .koami-mascot { right: 10px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: 135px; } .koami-mascot img { width: 60px; height: 60px; } .koami-mascot span { font-size: 10px; padding: 6px 8px; } }

/* Champs et boutons */
.stack { display: grid; gap: var(--s4); }
.field { display: grid; gap: var(--s1); }
label { font-weight: 600; font-size: .9375rem; }
.opt { font-weight: 400; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 48px; padding: var(--s3) var(--s4);
  background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s var(--ease-out);
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
.pin { letter-spacing: .5em; font-family: var(--mono); font-size: 1.25rem; max-width: 220px; }
.help { font-size: .875rem; }
.error { color: var(--danger); font-size: .9375rem; min-height: 1.4em; }
.error:empty { min-height: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; padding: 0 var(--s5); border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; touch-action: manipulation;
  transition: transform .12s var(--ease-out), background-color .15s var(--ease-out), border-color .15s var(--ease-out);
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-small { min-height: 40px; padding: 0 var(--s4); font-size: .9375rem; }
.btn-wide { width: 100%; }
.btn-stop { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.btn-stop:hover { background: var(--danger-bg); }
.btn-stop { white-space: nowrap; flex: none; }
.stop-short { display: none; }
@media (max-width: 520px) { .stop-long { display: none; } .stop-short { display: inline; } }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); }

/* Accès */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: var(--s5) var(--s4);
  background: radial-gradient(circle at 50% 0%, var(--surface-2), var(--bg) 60%); }
.gate-card { width: min(440px, 100%); display: grid; gap: var(--s5); }
.gate-card section { display: grid; gap: var(--s4); }

/* Coquille */
.shell { min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(72px, 1fr); overflow-x: auto;
  background: var(--ink); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav-mark { display: none; }
.nav-foot { display: contents; }
.nav-item {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; padding: var(--s1); background: none; border: 0; color: var(--muted); font-size: .75rem; cursor: pointer;
}
.nav-item[aria-current="page"] { color: var(--text); }
.nav-item[aria-current="page"] .ico { color: var(--accent); }
.count {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 700; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.main-wrap { min-width: 0; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brain { display: flex; align-items: center; gap: var(--s2); font-size: .9375rem; color: var(--muted); min-width: 0; }
.brain span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.brain.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.brain.on { color: var(--text); }
.content { max-width: 820px; margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); }
.content:focus { outline: none; }

@media (min-width: 1024px) {
  .shell { grid-template-columns: 248px 1fr; }
  .nav { position: sticky; top: 0; height: 100dvh; inset: auto; display: flex; flex-direction: column; gap: var(--s1);
    padding: var(--s5) var(--s3); border-top: 0; border-right: 1px solid var(--line); }
  .nav-mark { display: flex; padding: 0 var(--s3) var(--s5); }
  .nav-foot { display: block; margin-top: auto; }
  .nav-item { flex-direction: row; justify-content: flex-start; gap: var(--s3); min-height: 48px; padding: 0 var(--s3); border-radius: var(--r-sm); font-size: 1rem; width: 100%; }
  .nav-item:hover { background: var(--surface); color: var(--text); }
  .nav-item[aria-current="page"] { background: var(--surface); }
  .count { position: static; margin-left: auto; }
  .main-wrap { padding-bottom: 0; }
  .bar { padding: var(--s3) var(--s6); }
  .content { padding: var(--s7) var(--s6); }
}

/* Alertes */
.alert { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4); margin-bottom: var(--s5); border-radius: var(--r-md); background: var(--danger-bg); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); }
.alert-soft { background: var(--surface); border-color: var(--line); color: var(--muted); }

/* Poste de commande */
.console { display: grid; justify-items: center; text-align: center; gap: var(--s5); padding: var(--s5) 0 var(--s6); }
.greet { max-width: 18ch; }
.composer { width: 100%; display: grid; justify-items: center; gap: var(--s4); }
.mic {
  position: relative; width: 132px; height: 132px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--accent-ink);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 80%, white), var(--accent) 60%);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 14%, transparent), 0 18px 40px -12px color-mix(in srgb, var(--accent) 55%, transparent);
  transition: transform .18s var(--ease-out), box-shadow .25s var(--ease-out);
}
.mic:hover { transform: scale(1.03); }
.mic:active { transform: scale(.97); }
.mic-ico { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; position: relative; }
.wave { position: absolute; width: 240px; height: 240px; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.mic[aria-pressed="true"] { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 30%, transparent), 0 0 60px 4px color-mix(in srgb, var(--accent) 45%, transparent); }
.mic[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 2px solid var(--accent);
  animation: ring 1.6s var(--ease-out) infinite;
}
@keyframes ring { from { transform: scale(1); opacity: .8; } to { transform: scale(1.45); opacity: 0; } }
.mic[disabled] { filter: grayscale(1); opacity: .5; cursor: not-allowed; box-shadow: none; }
.voice-hint { color: var(--muted); max-width: 46ch; min-height: 3em; }
.voice-hint.live { color: var(--text); font-family: var(--display); font-size: 1.25rem; }
.prompt { position: relative; width: 100%; }
.prompt textarea { min-height: 64px; padding-right: 72px; border-radius: var(--r-lg); resize: none; background: var(--surface); line-height: 1.5; }
.send { position: absolute; right: 8px; bottom: 8px; width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--text); color: var(--bg); cursor: pointer; transition: transform .12s var(--ease-out); }
.send:active { transform: scale(.94); }
.send[disabled] { opacity: .4; }
.toggle { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 400; color: var(--muted); cursor: pointer; min-height: 44px; }
.toggle input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

/* Fil de mission */
.thread { display: grid; gap: var(--s5); padding: var(--s5); margin-bottom: var(--s7); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.order { justify-self: end; max-width: 85%; padding: var(--s3) var(--s4); border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  background: var(--surface-2); overflow-wrap: anywhere; }
.state { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: .9375rem; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 var(--s3); border-radius: 999px; font-weight: 600; font-size: .875rem; background: var(--surface-2); color: var(--text); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.running, .pill.queued { color: var(--accent-text); }
.pill.running::before { animation: blink 1s steps(2) infinite; }
.pill.waiting_approval { color: var(--accent-text); }
.pill.done { color: var(--ok); }
.pill.failed, .pill.stopped, .pill.interrupted { color: var(--danger); }
@keyframes blink { 50% { opacity: .25; } }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.step { display: grid; grid-template-columns: 32px 1fr; gap: var(--s3); position: relative; padding-bottom: var(--s4); }
.step::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--line); }
.step:last-child::before { display: none; }
.step-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.step-ico .ico { width: 16px; height: 16px; }
.step-body { min-width: 0; padding-top: 5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.step-body small { display: block; color: var(--muted); font-size: .8125rem; margin-bottom: 2px; }
.step.tool .step-body, .step.result .step-body { font-family: var(--mono); font-size: .8125rem; color: var(--muted); }
.step.tool .step-ico { color: var(--accent-text); }
.step.approval .step-ico { background: var(--accent); color: var(--accent-ink); }
.step.error .step-ico { color: var(--danger); }
.step.thought .step-ico { color: var(--text); }
.step.fresh { animation: arrive .35s var(--ease-out); }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } }
.result-clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }

.report { display: grid; gap: var(--s3); padding: var(--s4) var(--s5); border-radius: var(--r-md); border-left: 4px solid var(--ok); background: color-mix(in srgb, var(--ok) 9%, var(--surface)); }
.report h3 { font-size: 1.0625rem; }
.report p { white-space: pre-wrap; overflow-wrap: anywhere; }
.waiting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4); border-radius: var(--r-md); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }

/* Historique */
.history h2 { margin-bottom: var(--s3); }
.history-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.history-list li { border-bottom: 1px solid var(--line); }
.history-item { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s4); align-items: center; text-align: left;
  min-height: 64px; padding: var(--s3) var(--s2); background: none; border: 0; cursor: pointer; border-radius: var(--r-sm); }
.history-item:hover { background: var(--surface); }
.history-item[aria-current="true"] { background: var(--surface); }
.history-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-time { grid-column: 1; color: var(--muted); font-size: .8125rem; }
.history-item .pill { grid-row: 1 / span 2; grid-column: 2; }
.empty { padding: var(--s5) 0; color: var(--muted); }

/* Listes : validations, carnet */
.stack-list { list-style: none; margin: var(--s5) 0 0; padding: 0; display: grid; gap: var(--s3); }
.card { padding: var(--s4) var(--s5); border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); display: grid; gap: var(--s3); }
.card-approval { border-left: 4px solid var(--accent); }
.card h2 { font-size: 1.125rem; }
pre { margin: 0; padding: var(--s3); border-radius: var(--r-sm); background: var(--ink); font: .8125rem/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; }
.meta { color: var(--muted); font-size: .875rem; }

/* Cerveau */
.engines { list-style: none; margin: var(--s5) 0 var(--s4); padding: 0; display: grid; gap: var(--s3); counter-reset: engine; }
.engine { display: grid; grid-template-columns: 40px 1fr; gap: var(--s2) var(--s4); padding: var(--s4); border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.engine-rank { counter-increment: engine; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-family: var(--display); font-weight: 700; }
.engine-rank::before { content: counter(engine); }
.engine:first-child .engine-rank { background: var(--accent); color: var(--accent-ink); }
.engine.off { opacity: .6; }
.engine-name { font-family: var(--display); font-weight: 700; font-size: 1.125rem; }
.engine-meta { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.engine-tools { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--s2); }
.engine-test { grid-column: 2; font-size: .875rem; color: var(--muted); }
.engine-test.ok { color: var(--ok); }
.engine-test.bad { color: var(--danger); }
.add { border-radius: var(--r-md); border: 1px dashed var(--line); }
.add summary { min-height: 56px; display: flex; align-items: center; padding: 0 var(--s5); font-weight: 600; cursor: pointer; list-style: none; }
.add summary::before { content: "+"; font-family: var(--display); font-size: 1.5rem; color: var(--accent-text); margin-right: var(--s3); }
.add[open] summary::before { content: "−"; }
.add form { padding: 0 var(--s5) var(--s5); }
.view h1 { margin-bottom: 0; }

/* Dialogue PIN */
dialog { width: min(400px, calc(100vw - 32px)); padding: var(--s6); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(5 8 25 / .7); backdrop-filter: blur(3px); }
dialog[open] { animation: rise .2s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* Surfaces et reliefs inspirés de la charte, sans inclinaison du contenu lisible. */
body { background: radial-gradient(ellipse at 85% 0%, #4d1024 0, transparent 45%), var(--bg); }
a { color: var(--accent-text); text-underline-offset: 3px; }
a:hover { color: var(--text); }
.nav { background: linear-gradient(160deg, #360d1d, var(--ink) 65%); }
.nav-item { min-width: 0; }
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.nav-item[aria-current="page"] { background: linear-gradient(120deg, #8b1532, #491427); box-shadow: inset 0 1px 0 #ffffff12; }
.nav-item[aria-current="page"] .ico { color: #ffc0ce; }
.bar { background: linear-gradient(110deg, #2e111edb, #140d13ed); }
.console { padding: 32px 20px; border: 1px solid #8b294550; border-radius: 28px; background: radial-gradient(ellipse at 12% 0%, #9d163a66, transparent 65%), linear-gradient(135deg, #3a1625, #1b1118 75%); box-shadow: 0 24px 60px #00000040, inset 0 1px 0 #ffffff12; margin-bottom: 32px; }
.mic { background: radial-gradient(circle at 32% 22%, #ff5573, #df173d 48%, #a00c29 90%); box-shadow: 0 0 0 10px #e7224530, 0 16px 36px -12px #f51e4e80, inset 0 2px 3px #ffffff60, inset 0 -8px 14px #59001566; }
.mic:hover { transform: translateY(-2px); }
.send, .btn-accent { background: linear-gradient(135deg, #e92348, #b20b2e); color: #fff; box-shadow: inset 0 1px 0 #ffffff30, 0 6px 18px #00000025; }
.card, .engine { background: linear-gradient(140deg, #351822, #21131b 80%); box-shadow: inset 0 1px 0 #ffffff0a; }
.card h2, .card h3 { overflow-wrap: anywhere; }
.gate-card { padding: 28px; border-radius: 28px; border: 1px solid var(--line); background: linear-gradient(140deg, #4a152a, #1a1018); box-shadow: 0 28px 70px #00000050; }
.report { border-left-color: var(--accent); background: linear-gradient(120deg, #471528, #24131d); }
.pill.waiting_input, .pill.waiting_provider, .pill.waiting_device { color: var(--accent-text); }
.view > h2 { margin-top: 36px; }
.video-card video { display: block; width: 100%; max-height: 520px; margin: 16px 0; background: #140d13; border-radius: 14px; }
.video-file { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-block: 14px; }
.video-file a { overflow-wrap: anywhere; }
.view > .stack-list + h2 { margin-top: 36px; }
@media (max-width: 420px) {
  .nav-item { font-size: .65rem; }
  .console { padding: 28px 14px; border-radius: 22px; }
  .content { padding-inline: 12px; }
  .card { padding: 16px; }
}
