:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eef1f8; --text: #1b2236; --muted: #5a6480;
  --border: #d9deea; --accent: #2d5bd7; --accent-ink: #ffffff; --accent-soft: #e3eafc;
  --orange: #f08a24; --scratch: #ffab19; --ok: #1f9d55; --ko: #c0392b;
  --deepseek: #4d6bfe; --gemini: #8e5cf0; --claude: #d97757;
  --radius: 16px; --shadow: 0 2px 10px rgba(27, 34, 54, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151f; --surface: #1a2030; --surface-2: #222a3d; --text: #e8ecf5; --muted: #9aa5c0;
    --border: #2e3850; --accent: #7a9bff; --accent-ink: #0d1220; --accent-soft: #24305a;
    --shadow: 0 2px 10px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ---------- connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px; padding: 32px 28px;
  box-shadow: var(--shadow); text-align: center; border: 1px solid var(--border);
}
.login-card .planete { font-size: 64px; line-height: 1; }
.login-card h1 { font-size: 1.5rem; margin: 12px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.champ {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--surface-2); font-size: 1.1rem; text-align: center;
}
.champ:focus { outline: none; border-color: var(--accent); }
.btn {
  border: 0; border-radius: 12px; padding: 12px 20px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.large { width: 100%; margin-top: 12px; padding: 14px; font-size: 1.1rem; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.erreur { color: var(--ko); min-height: 1.5em; margin-top: 10px; font-weight: 600; }

/* ---------- en-tête */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.marque { font-weight: 800; display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.marque span { font-size: 26px; }
.topbar .spacer { flex: 1; }
.lien-btn { background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; }
.lien-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- accueil */
.hero { padding: 40px 0 8px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin: 0 0 8px; line-height: 1.15; }
.hero p { color: var(--muted); font-size: 1.1rem; max-width: 720px; margin: 0; }
h2.section { font-size: 1.25rem; margin: 36px 0 14px; }

.schema {
  display: grid; grid-template-columns: 1fr auto 1.3fr auto 1.6fr auto 1fr; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
.etape { text-align: center; }
.etape .pastille {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px;
  font-size: 30px; background: var(--surface-2);
}
.etape b { display: block; }
.etape small { color: var(--muted); display: block; line-height: 1.3; }
.fleche { font-size: 26px; color: var(--muted); text-align: center; }
.equipiers { display: flex; flex-direction: column; gap: 8px; }
.equipier {
  display: grid; grid-template-columns: auto 92px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px;
  background: var(--surface-2); border-left: 5px solid var(--c, var(--accent));
}
.equipier b { line-height: 1.2; }
.equipier small { color: var(--muted); line-height: 1.25; }
.equipier .prix { margin-left: auto; white-space: nowrap; font-size: .85rem; color: var(--muted); }
.etat { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.etat.ko { background: var(--ko); }
.note { color: var(--muted); font-size: .95rem; margin: 12px 2px 0; }

.projets { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 48px; }
.projet {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); border-top: 6px solid var(--c); display: flex; flex-direction: column;
  gap: 6px; transition: transform .12s;
}
.projet:not(:disabled):hover { transform: translateY(-3px); }
.projet .ico { font-size: 40px; }
.projet b { font-size: 1.15rem; }
.projet span { color: var(--muted); }
.projet:disabled { opacity: .55; cursor: default; }
.projet .go { margin-top: auto; padding-top: 8px; color: var(--accent); font-weight: 700; }

/* ---------- blocs ScratchJr */
.sjr-script-img { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 3px; padding: 10px; background: #fff;
  border-radius: 10px; margin: 6px 0 10px; border: 1px solid var(--border); }
.sjr-bloc { position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 58px; height: 58px; border-radius: 10px; background: var(--c); box-shadow: inset 0 -4px 0 rgba(0,0,0,.18); flex: none; }
.sjr-ico { width: 44px; height: 38px; background: #fff; border-radius: 7px; display: grid; place-items: center; }
.sjr-ico img { max-width: 40px; max-height: 34px; }
.sjr-val { position: absolute; bottom: -9px; background: #fff; color: #222; border: 1px solid #bbb; border-radius: 999px;
  font-size: .72rem; font-weight: 700; padding: 0 6px; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sjr-bloc.inconnu { background: #ccc; width: auto; padding: 0 8px; font-size: .8rem; color: #222; }
.sjr-repeter { display: inline-flex; align-items: flex-end; gap: 3px; border: 4px solid var(--c); border-radius: 12px;
  padding: 4px; background: color-mix(in srgb, var(--c) 12%, #fff); }
.sjr-boucle { display: inline-flex; flex-wrap: wrap; gap: 3px; align-items: flex-end; }

/* ---------- page projet */
.projet-page { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 20px; padding: 20px 0 24px; }
.panneau {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; min-width: 0;
}
.panneau h2 { margin: 0 0 10px; font-size: 1.15rem; }
.depot {
  border: 3px dashed var(--border); border-radius: 14px; padding: 22px 14px; text-align: center; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.depot.survol { border-color: var(--scratch); background: color-mix(in srgb, var(--scratch) 12%, var(--surface)); }
.depot .gros { font-size: 40px; }
.depot p { margin: 6px 0 12px; }
.aide-fichier { font-size: .92rem; color: var(--muted); margin-top: 12px; }
.aide-fichier details { margin-top: 6px; }
.aide-fichier summary { cursor: pointer; color: var(--text); font-weight: 600; }
.resume {
  background: color-mix(in srgb, var(--scratch) 16%, var(--surface)); border-radius: 12px; padding: 10px 12px;
  margin: 12px 0; font-weight: 600;
}
.lutin { margin-top: 12px; }
.lutin > summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.lutin .meta { color: var(--muted); font-size: .88rem; margin: 2px 0 6px; }
.script-box { overflow-x: auto; background: #fff; border-radius: 10px; padding: 8px; margin: 6px 0; border: 1px solid var(--border); }
.sjr-script { white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: .9rem; background: var(--surface-2); padding: 8px; border-radius: 8px; }

.chat { display: flex; flex-direction: column; min-height: 70vh; max-height: calc(100vh - 110px); padding: 0; }
.chat-tete { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.chat-tete h2 { margin: 0; flex: 1; }
.fil { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.bulle { max-width: 92%; padding: 12px 16px; border-radius: 16px; overflow-wrap: anywhere; }
.bulle.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.bulle.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bulle p { margin: 0 0 .6em; } .bulle p:last-child { margin-bottom: 0; }
.bulle ul, .bulle ol { margin: .2em 0 .6em; padding-left: 1.3em; }
.bulle code { background: color-mix(in srgb, var(--text) 9%, transparent); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.bulle pre.code { background: var(--surface); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bulle .blocs { background: #fff; border-radius: 10px; padding: 8px; overflow-x: auto; margin: 6px 0 10px; }
.qui {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); margin-bottom: 6px;
}
.badge { padding: 2px 9px; border-radius: 999px; color: #fff; font-weight: 700; background: var(--c, var(--accent)); }
.attente { display: inline-flex; gap: 4px; }
.attente i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: rebond 1s infinite; }
.attente i:nth-child(2) { animation-delay: .15s; } .attente i:nth-child(3) { animation-delay: .3s; }
@keyframes rebond { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
.vide { text-align: center; color: var(--muted); margin: auto; padding: 20px; }
.vide .gros { font-size: 48px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; }
.suggestions button:hover { border-color: var(--accent); }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer .ligne { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 180px; padding: 12px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface-2);
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.piece { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.piece img { height: 44px; border-radius: 6px; border: 1px solid var(--border); }
.icone-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; width: 48px; height: 48px; font-size: 22px; flex: none; }
.prudence { font-size: .8rem; color: var(--muted); text-align: center; }
.cache { display: none !important; }

@media (max-width: 520px) {
  .marque { font-size: 0; } .marque span { font-size: 26px; }
}
@media (max-width: 860px) {
  .projet-page { grid-template-columns: 1fr; }
  .chat { max-height: none; min-height: 60vh; }
  .schema { grid-template-columns: 1fr; }
  .fleche { transform: rotate(90deg); }
}
