:root {
  color-scheme: dark;
  --bg: #070708; --panel: #0d0d10; --ink: #ecebef; --mute: #8f8d97; --dim: #5e5c66;
  --line: rgba(255,255,255,.08); --warm: #ffe7c7; --jin: #e15acd; --alert: #ff6b5a; --ok: #8fd6a6;
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.mute { color: var(--mute); }
[hidden] { display: none !important; }
.primary { background: var(--warm); color: #141413; border: 0; border-radius: 12px; min-height: 44px; padding: 0 16px; font-weight: 600; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; min-height: 44px; padding: 0 14px; }
.ghost.no { color: #ffb3a8; border-color: rgba(255,107,90,.35); }
button:disabled { opacity: .45; }

/* Liaison */
.pair { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 32px 24px; text-align: center; animation: rise .6s cubic-bezier(.2,.8,.2,1) both; }
.pair h1 { margin: 0; font-size: 26px; letter-spacing: .28em; font-weight: 700; }
.pair p { max-width: 320px; margin: 0; }
.pair form { display: grid; gap: 10px; width: min(320px, 100%); }
.pair input { min-height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 14px; text-align: center; }
#pairCode { font-size: 28px; letter-spacing: .4em; color: var(--warm); }
.err { color: #ffb3a8; min-height: 1.5em; }
.slab { width: 28px; height: 64px; background: #020203; border: 1px solid rgba(255,255,255,.14); display: flex; justify-content: center; box-shadow: 0 0 40px rgba(255,231,199,.08); }
.slab span { width: 1px; background: var(--warm); animation: glow 3s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .4; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* App */
.app { height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex: none; }
.top h1 { flex: 1; margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-size: 20px; line-height: 1; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mute); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.live.on i { background: var(--ok); box-shadow: 0 0 8px rgba(143,214,166,.8); }
.live b { font-weight: 500; }

.projects { flex: 1; overflow-y: auto; padding: 12px; display: grid; gap: 8px; align-content: start; }
.proj { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); animation: rise .4s both; }
.proj.current { border-color: rgba(255,231,199,.3); }
.p-name { font-weight: 600; }
.p-meta { grid-column: 1; font-size: 13px; color: var(--mute); }
.badge { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 12px; padding: 3px 9px; border-radius: 99px; }
.badge.wait { background: rgba(255,231,199,.14); color: var(--warm); }
.badge.work { background: rgba(143,214,166,.12); color: #a9e8bd; }
.empty { text-align: center; padding: 40px 0; }

/* Demandes d'autorisation */
.asks { flex: none; display: grid; gap: 8px; padding: 0 12px; }
.asks:empty { display: none; }
.ask { margin-top: 10px; padding: 12px; border-radius: 14px; border: 1px solid rgba(255,231,199,.35); background: linear-gradient(180deg, rgba(255,231,199,.08), rgba(255,231,199,.03)); animation: rise .35s both; }
.ask .who { font-size: 12px; color: var(--warm); letter-spacing: .06em; text-transform: uppercase; }
.ask p { margin: 4px 0 8px; }
.ask pre { margin: 0 0 8px; max-height: 120px; overflow: auto; font-size: 12px; background: rgba(0,0,0,.35); padding: 8px; border-radius: 8px; white-space: pre-wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row button { flex: 1; }

/* Conversation */
.conv { flex: 1; overflow-y: auto; padding: 0 12px 12px; overscroll-behavior: contain; }
.agents { position: sticky; top: 0; z-index: 1; display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; background: linear-gradient(var(--bg) 80%, transparent); scrollbar-width: none; }
.agent { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px; border: 1px solid var(--line); font-size: 13px; }
.agent i { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.agent.st-travaille i { background: var(--ok); animation: glow 1.2s infinite; }
.agent.st-attend i { background: var(--warm); }
.agent.st-erreur i { background: var(--alert); }
.agent small { color: var(--mute); }
.agent .stop { border: 1px solid rgba(255,107,90,.4); background: transparent; color: #ffb3a8; border-radius: 99px; padding: 1px 9px; font-size: 12px; min-height: 26px; }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--line); animation: rise .3s both; }
.msg .who { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: rgba(255,231,199,.10); border-color: rgba(255,231,199,.22); }
.msg.assistant { align-self: flex-start; background: rgba(255,255,255,.04); }
.msg.e-claude { background: rgba(217,119,87,.10); border-color: rgba(217,119,87,.25); }
.msg.e-codex { background: rgba(143,214,166,.08); border-color: rgba(143,214,166,.24); }
.msg.e-antigravity { background: rgba(110,155,255,.09); border-color: rgba(110,155,255,.26); }
.msg.e-grok { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); }
.msg pre { white-space: pre; overflow-x: auto; background: rgba(0,0,0,.4); padding: 8px; border-radius: 8px; font-size: 12.5px; margin: 6px 0; }
.msg code, .ask code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; background: rgba(255,255,255,.07); padding: 0 4px; border-radius: 4px; }
.line { font-size: 12.5px; color: var(--mute); padding: 0 4px; }
.line.err { color: #ffb3a8; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 9px 12px; border-radius: 12px; background: #141417; border: 1px solid var(--line); font-size: 14px; animation: rise .25s both; z-index: 5; }
.toast b { color: #f0a5e3; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; flex: none; padding-top: 2px; }
.toast.mnlth b { color: var(--warm); }

.bar { flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.bar select { max-width: 34%; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; font-size: 13px; }
.bar textarea { flex: 1; resize: none; min-height: 44px; max-height: 160px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 11px 12px; line-height: 1.35; }
.send { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--warm); color: #141413; font-size: 20px; font-weight: 700; flex: none; }

dialog { width: min(420px, 94vw); border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--ink); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
dialog h2 { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); margin: 4px 0 8px; }
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 12px; border: 1px solid var(--line); background: #141417; margin-bottom: 10px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--mute); }
.seg button[aria-pressed="true"] { background: var(--warm); color: #141413; font-weight: 600; }
dialog .row { margin-top: 12px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* Jin */
.jin-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; border: 0; background: none; }
.jin-btn img { width: 40px; height: 40px; border-radius: 50%; display: block; box-shadow: 0 0 12px rgba(225,90,205,.45); }
.jin-view { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: calc(20px + env(safe-area-inset-top)) 18px calc(14px + env(safe-area-inset-bottom));
  background: radial-gradient(120% 70% at 50% 18%, rgba(225,90,205,.16), rgba(7,7,8,.97) 60%), var(--bg); }
.jin-view.appear .jin-face { animation: glitchIn .7s steps(2, end) both; }
.jin-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; }
.jin-face { position: relative; width: min(56vw, 240px); aspect-ratio: 1; margin-top: 18px; border: 0; padding: 0; background: none; border-radius: 50%; overflow: hidden; }
.jin-face img { width: 100%; height: 100%; display: block; filter: drop-shadow(0 0 24px rgba(225,90,205,.5)); }
.jin-face .scan { position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(255,255,255,.06) 0 1px, transparent 1px 3px); mix-blend-mode: screen; pointer-events: none; animation: scan 3s linear infinite; }
.jin-view.listen .jin-face { box-shadow: 0 0 0 3px #e15acd, 0 0 50px rgba(225,90,205,.7); animation: pulse 1.2s ease-in-out infinite; }
.jin-view.talk .jin-face img { animation: talk .9s ease-in-out 2; }
.jin-state { margin: 6px 0 0; color: #f0a5e3; font-size: 14px; letter-spacing: .04em; text-align: center; }
.jin-heard { margin: 0; min-height: 1.5em; color: var(--ink); text-align: center; font-size: 16px; }
.jin-log { list-style: none; margin: 0; padding: 0; width: 100%; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.jin-log li { padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--line); font-size: 14px; }
.jin-log li b { display: block; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #f0a5e3; }
.jin-log li.me { align-self: flex-end; background: rgba(255,231,199,.08); } .jin-log li.me b { color: var(--warm); }
.jin-log li.mnlth b { color: var(--warm); }
.jin-form { display: flex; gap: 8px; width: 100%; }
.jin-form input { flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 12px; }
@keyframes glitchIn { 0% { opacity: 0; clip-path: inset(40% 0 45% 0); transform: translateX(-8px); filter: drop-shadow(4px 0 #0ff) drop-shadow(-4px 0 #f0f); }
  30% { opacity: 1; clip-path: inset(10% 0 60% 0); transform: translateX(6px); } 60% { clip-path: inset(55% 0 5% 0); transform: translateX(-3px); } 100% { clip-path: inset(0); transform: none; filter: none; } }
@keyframes scan { to { background-position: 0 60px; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #e15acd, 0 0 80px rgba(225,90,205,.9); } }
@keyframes talk { 50% { filter: drop-shadow(0 0 36px rgba(225,90,205,.9)) brightness(1.15); } }

.pair-choice { display: grid; gap: 10px; width: min(320px, 100%); }
.btn-link { display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* Entraînement (téléphone) */
.train-view { position: fixed; inset: 0; z-index: 11; display: flex; flex-direction: column; gap: 10px; padding: calc(20px + env(safe-area-inset-top)) 18px calc(16px + env(safe-area-inset-bottom)); background: var(--bg); overflow-y: auto; }
.train-view h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: .1em; text-transform: uppercase; }
.tr-bar { height: 4px; border-radius: 2px; background: rgba(255,255,255,.08); overflow: hidden; }
.tr-bar i { display: block; height: 100%; width: 0; background: var(--jin); transition: width .4s; }
.tr-count { margin: 0; font-size: 13px; }
.tr-phrase { font-size: 24px; font-weight: 700; line-height: 1.3; margin: 18px 0 6px; min-height: 2.6em; }
.tr-heard { min-height: 3em; color: var(--mute); margin: 0; }
.tr-heard .ok { color: var(--ok); } .tr-heard .ko { color: #ffb3a8; } .tr-heard .fix { color: #f0a5e3; }
.train-view.rec #trSay { background: var(--jin); color: #fff; }
.tr-score { font-weight: 700; }
.tr-fixes { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.tr-fixes label { display: flex; gap: 8px; align-items: center; }
