:root{
  --bg:#0e1120;
  --bg-2:#141829;
  --panel:#161a2e;
  --panel-alt:#1b2036;
  --border:#282e4c;
  --border-soft:#212643;
  --text:#e8eaf6;
  --text-dim:#8991b3;
  --text-faint:#565d80;
  --accent:#f2a93c;
  --accent-dim:#f2a93c33;
  --accent-2:#6cb8ff;
  --margin-red:#c1443a;
  --error:#ff8686;
  --error-bg:#391b20;
  --success:#7fd99a;
  --glow:#1a1f38;
  --tok-logic:#c792ea;
  --tok-num:#f5789a;
  --tok-op:#9aa3c7;
  --modal-overlay:rgba(0,0,0,.6);
  --radius:10px;
  --font-ui:'Space Grotesk', sans-serif;
  --font-mono:'JetBrains Mono', monospace;
  --code-font-size:14px;
  --code-line-height:21px;
}

/* Thème clair : mêmes variables, palette inversée (fond "papier" clair,
   accents assombris pour rester lisibles sur blanc). Activé via
   <html data-theme="light">, basculé depuis le menu Affichage. */
html[data-theme="light"]{
  --bg:#f5f3ee;
  --bg-2:#efece3;
  --panel:#ffffff;
  --panel-alt:#f1eee5;
  --border:#ddd7c7;
  --border-soft:#e5e0d2;
  --text:#1c1f2b;
  --text-dim:#5b5f6e;
  --text-faint:#8b8f9c;
  --accent:#c9791c;
  --accent-dim:#c9791c22;
  --accent-2:#2f6fb0;
  --margin-red:#c1443a;
  --error:#c0392b;
  --error-bg:#fbe4e1;
  --success:#1f8a4c;
  --glow:#fbf7ec;
  --tok-logic:#8e44ad;
  --tok-num:#c2185b;
  --tok-op:#5b6270;
  --modal-overlay:rgba(20,18,10,.45);
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  height:100vh;
  overflow:hidden;
  background:
    radial-gradient(ellipse at top left, var(--glow) 0%, transparent 55%),
    var(--bg);
  color:var(--text);
  font-family:var(--font-ui);
  display:flex;
  flex-direction:column;
  transition:background-color .15s ease, color .15s ease;
}
body, body *{ transition: background-color .15s ease, border-color .15s ease, color .15s ease; }

@media (prefers-reduced-motion: reduce){
  *{animation-duration:0.001ms !important; transition-duration:0.001ms !important;}
}

/* ---------- Header ---------- */
header{
  flex:0 0 auto;
  position:relative;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  flex-wrap:wrap;
  padding:16px 22px 16px 34px;
  background:var(--panel);
  border-bottom:1px solid var(--border);
}
header::before{
  content:"";
  position:absolute;
  left:0; top:0; bottom:0;
  width:14px;
  background-image:radial-gradient(circle, var(--border) 1.6px, transparent 1.7px);
  background-size:14px 14px;
  background-position:center;
  opacity:.7;
}
.brand{display:flex; flex-direction:column; gap:2px;}
.brand h1{
  margin:0;
  font-size:1.28rem;
  font-weight:700;
  letter-spacing:-0.01em;
}
.brand h1 .dot{color:var(--accent);}
.brand p{
  margin:0;
  font-size:.8rem;
  color:var(--text-dim);
  font-family:var(--font-mono);
}

.controls{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
select, button{
  font-family:var(--font-ui);
  font-size:.85rem;
  font-weight:600;
  border-radius:8px;
  border:1px solid var(--border);
  padding:9px 14px;
  cursor:pointer;
  background:var(--panel-alt);
  color:var(--text);
  transition:border-color .15s, background .15s, transform .08s;
}
select{cursor:pointer; padding-right:10px;}
button:hover, select:hover{border-color:var(--text-faint);}
button:active{transform:translateY(1px);}
button:focus-visible, select:focus-visible, input:focus-visible{
  outline:2px solid var(--accent-2);
  outline-offset:2px;
}
button:disabled{opacity:.45; cursor:not-allowed; transform:none;}

.run-trigger{
  background:var(--accent);
  color:#1a1204;
  border-color:var(--accent);
}
.run-trigger:hover:not(:disabled){background:#ffb955;}
.toolbar-quick .run-trigger .k{opacity:.65; font-weight:500; font-size:.75em; margin-left:6px;}
.menu-item.run-trigger{background:transparent; color:var(--text); border-color:transparent;}
.menu-item.run-trigger:hover:not(:disabled){background:var(--accent-dim); border-color:var(--accent); color:var(--accent);}

.stop-trigger{background:transparent; color:var(--error); border-color:var(--border);}
.stop-trigger:hover:not(:disabled){background:var(--error-bg); border-color:var(--error);}


/* ---------- Barre de menu (façon logiciel de bureau) ---------- */
.menubar{
  display:flex;
  align-items:stretch;
  gap:2px;
  flex-wrap:wrap;
}
.menu{position:relative;}
.menu-trigger{
  background:transparent;
  border:1px solid transparent;
  border-radius:7px;
  padding:8px 12px;
  font-size:.85rem;
}
.menu-trigger:hover{background:var(--panel-alt);}
.menu.open .menu-trigger{background:var(--accent-dim); border-color:var(--accent); color:var(--accent);}
.menu-panel{
  position:absolute;
  top:100%;
  left:0;
  margin-top:6px;
  min-width:250px;
  max-width:320px;
  background:var(--panel-alt);
  border:1px solid var(--border);
  border-radius:10px;
  box-shadow:0 14px 32px rgba(0,0,0,.35);
  padding:6px;
  display:none;
  z-index:60;
}
.menu.open .menu-panel{display:block;}
.menu-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  width:100%;
  text-align:left;
  background:transparent;
  border:1px solid transparent;
  border-radius:7px;
  padding:8px 10px;
  font-size:.85rem;
  font-weight:500;
  color:var(--text);
}
.menu-item:hover:not(:disabled){background:var(--accent-dim); border-color:var(--accent);}
.menu-item .mk{opacity:.6; font-weight:500; font-size:.78em; font-family:var(--font-mono);}
.menu-sep{height:1px; background:var(--border); margin:6px 4px;}
.menu-label{
  font-family:var(--font-mono);
  font-size:.68rem;
  letter-spacing:.06em;
  text-transform:uppercase;
  color:var(--text-faint);
  padding:6px 10px 2px;
}
.menu-sublist{max-height:180px; overflow:auto;}
.menu-choice-group{display:flex; gap:6px; padding:4px 6px 8px; flex-wrap:wrap;}
.menu-choice-group button{
  flex:1 1 auto;
  padding:7px 8px;
  border-radius:7px;
  border:1px solid var(--border);
  background:transparent;
  color:var(--text);
  font-size:.78rem;
  font-family:var(--font-ui);
}
.menu-choice-group button.active{background:var(--accent); color:#1a1204; border-color:var(--accent);}

.toolbar-quick{display:flex; align-items:center; gap:10px; flex-wrap:wrap;}

/* Bouton de téléchargement Windows : couleur dédiée et fixe (ne suit pas
   --accent), pour rester un repère visuel constant quel que soit le thème
   ou la personnalisation d'établissement. */
.btn-download-win{
  display:inline-flex;
  align-items:center;
  gap:8px;
  background:#2563eb;
  color:#ffffff;
  border:1px solid #2563eb;
  border-radius:8px;
  padding:9px 14px;
  font-family:var(--font-ui);
  font-size:.85rem;
  font-weight:700;
  text-decoration:none;
  white-space:nowrap;
  transition:background .15s, border-color .15s, transform .08s;
}
.btn-download-win:hover{background:#1d4ed8; border-color:#1d4ed8;}
.btn-download-win:active{transform:translateY(1px);}
.btn-download-win:focus-visible{outline:2px solid #93c5fd; outline-offset:2px;}

/* ---------- Modales (Guide de syntaxe / À propos) ---------- */
.modal-overlay{
  position:fixed; inset:0;
  top:0; right:0; bottom:0; left:0;
  background:var(--modal-overlay);
  display:flex; align-items:center; justify-content:center;
  padding:24px;
  z-index:200;
}
.modal-overlay[hidden]{display:none;}
.modal-box{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow:0 24px 60px rgba(0,0,0,.45);
  width:100%;
  max-width:560px;
  max-height:80vh;
  display:flex;
  flex-direction:column;
}
.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 20px;
  border-bottom:1px solid var(--border-soft);
}
.modal-head h2{margin:0; font-size:1.05rem; color:var(--accent);}
.modal-close{
  background:transparent; border:1px solid transparent; border-radius:7px;
  width:32px; height:32px; padding:0; font-size:1rem; line-height:1;
  color:var(--text-dim);
}
.modal-close:hover{background:var(--panel-alt); color:var(--text);}
.modal-body{
  padding:18px 20px 22px;
  overflow:auto;
  font-size:.9rem;
  line-height:1.6;
  color:var(--text);
}
.modal-body h3{margin:16px 0 6px; font-size:.92rem; color:var(--accent-2);}
.modal-body h3:first-child{margin-top:0;}
.modal-body p{margin:0 0 10px;}
.modal-body code{
  font-family:var(--font-mono);
  background:var(--panel-alt);
  border:1px solid var(--border-soft);
  border-radius:5px;
  padding:1px 6px;
  font-size:.85em;
  color:var(--accent);
}
.modal-body dl{margin:0; display:grid; grid-template-columns:auto 1fr; gap:6px 14px;}
.modal-body dt{font-weight:700; color:var(--text-dim); white-space:nowrap;}
.modal-body dd{margin:0;}
.modal-body a{color:var(--accent-2);}
.modal-body a:hover{text-decoration:underline;}

/* ---------- Layout ---------- */
main{
  flex:1 1 auto;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:1px;
  background:var(--border);
  min-height:0;
  overflow:hidden;
}
@media (max-width:900px){
  main{grid-template-columns:1fr; grid-template-rows:1fr 1fr;}
}

.pane{
  background:var(--bg-2);
  display:flex;
  flex-direction:column;
  min-height:0;
}
.pane-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 16px;
  border-bottom:1px solid var(--border-soft);
  font-family:var(--font-mono);
  font-size:.75rem;
  letter-spacing:.06em;
  text-transform:uppercase;
  color:var(--text-dim);
}
.status{display:flex; align-items:center; gap:7px;}
.status-dot{width:8px; height:8px; border-radius:50%; background:var(--text-faint);}
.status-dot.ready{background:var(--text-faint);}
.status-dot.running{background:var(--accent); box-shadow:0 0 0 4px var(--accent-dim); animation:pulse 1s infinite;}
.status-dot.done{background:var(--success);}
.status-dot.error{background:var(--error);}
.status-dot.stopped{background:var(--error);}
@keyframes pulse{0%,100%{opacity:1;} 50%{opacity:.4;}}

/* ---------- Editor ---------- */
.editor-wrap{
  flex:1;
  display:flex;
  min-height:0;
  position:relative;
  background:var(--panel);
}
#gutter{
  flex:0 0 auto;
  width:52px;
  padding:14px 0;
  text-align:right;
  font-family:var(--font-mono);
  font-size:var(--code-font-size);
  line-height:var(--code-line-height);
  color:var(--text-faint);
  overflow:hidden;
  user-select:none;
  white-space:pre;
  border-right:2px solid var(--margin-red);
  background:var(--panel);
}
#gutter span{display:block; padding-right:12px;}

/* Couche de coloration : un <pre> en lecture seule est superposé derrière
   un <textarea> rendu transparent (texte invisible, seul le curseur et la
   sélection restent visibles). Police, taille, interligne et padding sont
   strictement identiques entre les deux couches pour un alignement parfait. */
.code-layer{
  position:relative;
  flex:1;
  min-height:0;
}
#highlight, #code{
  position:absolute;
  inset:0;
  top:0; right:0; bottom:0; left:0;
  margin:0;
  border:0;
  font-family:var(--font-mono);
  font-size:var(--code-font-size);
  line-height:var(--code-line-height);
  padding:14px 16px;
  white-space:pre;
  tab-size:4;
}
#highlight{
  color:var(--text);
  overflow:hidden;
  pointer-events:none;
  background:transparent;
}
#highlight code{ font:inherit; white-space:inherit; }
#code{
  resize:none;
  outline:0;
  background:transparent;
  color:transparent;
  caret-color:var(--text);
  overflow:auto;
}
#code::selection{background:var(--accent-dim); color:transparent;}

/* Jetons colorés (coloration syntaxique) */
.tok-kw{color:var(--accent); font-weight:600;}
.tok-type{color:var(--accent-2); font-weight:600;}
.tok-func{color:var(--accent-2); font-weight:600; font-style:italic;}
.tok-logic{color:var(--tok-logic); font-weight:600;}
.tok-bool{color:var(--tok-logic);}
.tok-str{color:var(--success);}
.tok-num{color:var(--tok-num);}
.tok-com{color:var(--text-faint); font-style:italic;}
.tok-op{color:var(--tok-op);}

/* Autocomplétion */
.autocomplete-box{
  position:absolute;
  z-index:30;
  min-width:170px;
  max-width:260px;
  max-height:220px;
  overflow:auto;
  background:var(--panel-alt);
  border:1px solid var(--border);
  border-radius:8px;
  box-shadow:0 10px 28px rgba(0,0,0,.5);
  list-style:none;
  margin:0;
  padding:4px;
  font-family:var(--font-mono);
  font-size:13px;
}
.autocomplete-box[hidden]{display:none;}
.ac-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:6px 8px;
  border-radius:5px;
  cursor:pointer;
  color:var(--text);
}
.ac-item.active, .ac-item:hover{background:var(--accent-dim);}
.ac-label{white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.ac-tag{
  flex:0 0 auto;
  font-family:var(--font-ui);
  font-size:10px;
  text-transform:uppercase;
  letter-spacing:.04em;
  padding:1px 6px;
  border-radius:999px;
}
.ac-tag-kw{background:var(--accent-dim); color:var(--accent);}
.ac-tag-var{background:#6cb8ff22; color:var(--accent-2);}

/* ---------- Console ---------- */
#console{
  flex:1;
  padding:14px 16px;
  overflow:auto;
  font-family:var(--font-mono);
  font-size:13.5px;
  line-height:1.65;
  white-space:pre-wrap;
  word-break:break-word;
}
#console:empty::before{
  content:"En attente d'exécution — appuyez sur « Exécuter ».";
  color:var(--text-faint);
  font-style:italic;
}
#console .err{color:var(--error); background:var(--error-bg); border-radius:4px; padding:1px 4px;}
#console .sys{color:var(--success);}
#console .stop{color:var(--error);}
#console .userinput{color:var(--accent-2);}
.inline-read{display:inline-flex; align-items:center; gap:6px;}
.caret-mark{color:var(--accent); font-weight:700;}
.inline-input{
  background:var(--panel-alt);
  border:1px solid var(--accent);
  border-radius:5px;
  color:var(--text);
  font-family:var(--font-mono);
  font-size:13.5px;
  padding:2px 8px;
  min-width:120px;
  outline:0;
}

footer{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  flex-wrap:wrap;
  padding:8px 20px;
  font-size:.72rem;
  color:var(--text-faint);
  font-family:var(--font-mono);
  background:var(--panel);
  border-top:1px solid var(--border);
  overflow-wrap:break-word;
}
footer #devCredit{color:var(--accent); font-weight:700;}
footer .footer-sep{margin:0 8px; opacity:.5;}
.statusbar-status{
  display:flex; align-items:center; gap:7px;
  flex:0 0 auto;
  font-weight:700;
  color:var(--text);
}
.statusbar-cheatsheet{flex:1 1 auto; text-align:right; min-width:220px;}
@media (max-width:720px){
  footer{justify-content:center; text-align:center;}
  .statusbar-cheatsheet{text-align:center;}
}

/* ---------- Impression / export PDF ---------- */
#printArea{display:none;}
@media print{
  body > *:not(#printArea){display:none !important;}
  #printArea{
    display:block !important;
    position:static;
    white-space:pre-wrap;
    font-family:'Courier New', monospace;
    font-size:11pt;
    line-height:1.5;
    color:#000;
    background:#fff;
    padding:0;
  }
}
