:root {
  --light: #ebecd0; --dark: #779556; --sel: #f6f669; --hint: #00000022;
  --bg: #f4f4f2; --panel: #fff; --border: #d7d7d2; --accent: #3a7bd5;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: #222; font-size: 12px;
       display: flex; flex-direction: column; overflow: hidden; }
h1 { font-size: 15px; margin: 0; }
h2 { font-size: 12px; margin: 0 0 5px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
button { font: inherit; padding: 4px 8px; border: 1px solid var(--border); background: #fff; border-radius: 4px; cursor: pointer; }
button:hover { background: #f0f0f0; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
input[type=number], input[type=text], select, textarea { font: inherit; padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; }

header { display: flex; align-items: center; gap: 16px; padding: 6px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
#status { margin-left: auto; font-size: 12px; color: #555; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; background: #eee; margin-left: 4px; }
.badge.run { background: #d8f0d8; color: #275c27; }

main { flex: 1 1 auto; min-height: 0; display: grid;
       grid-template-columns: 240px max-content 240px 1fr;  /* plateau au plus juste, panneau droit absorbe le reste */
       gap: 8px; padding: 8px; align-items: stretch; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px;
         overflow: auto; }
.config .row { display: flex; align-items: center; gap: 6px; margin: 3px 0; flex-wrap: wrap; }
.config label { font-size: 13px; }
.config input[type=number] { width: 60px; }
.config textarea { width: 100%; height: 38px; font-size: 12px; }
.muted { color: #999; font-size: 12px; }
.term { padding: 5px 0; }
.term + .term { border-top: 1px solid var(--border); }

/* échiquier — grid 8x8 à rangées ET colonnes égales (fix du bug de hauteur) */
/* plateau adaptatif : borné par la largeur (vw) ET la hauteur (vh) disponibles */
#board { width: min(560px, 42vw, 74vh); aspect-ratio: 1 / 1; margin: 0 auto; display: grid;
         grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
         border: 2px solid #555; user-select: none; }
.sq { display: flex; align-items: center; justify-content: center; font-size: min(56px, 5vw, 6.4vh); line-height: 1; position: relative; cursor: pointer; }
.sq.light { background: var(--light); } .sq.dark { background: var(--dark); }
.sq.sel { background: var(--sel) !important; }
.sq.hint::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: var(--hint); }
.sq .pc.ghost { opacity: 0.38; }   /* pion fantôme sur la case en passant */
.sq .pc.white { color: #f7f7f2; -webkit-text-stroke: 2px #1b1b1b; }    /* fond clair, trait sombre */
.sq .pc.black { color: #1c1c1c; -webkit-text-stroke: 1.6px #eee; }     /* fond sombre, trait clair */
.center { text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.navend { min-width: 74px; }

/* sous le plateau : éval blancs | boutons | éval noirs */
/* colonnes de LARGEUR FIXE : les nombres qui changent ne déplacent plus rien */
#under-board { display: grid; grid-template-columns: 145px 250px 145px; justify-content: center; gap: 10px; align-items: start; margin-top: 8px; }
#under-board .evalcol { font-size: 12px; }
#under-board .evalcol > .center { border-bottom: 1px solid var(--border); padding-bottom: 3px; margin-bottom: 4px; }

/* onglets (4e panneau) — colonne flex : listes étirées, cache collé en bas */
#tabpanel { display: flex; flex-direction: column; overflow: hidden; }
.tabs { flex: 0 0 auto; display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tabs button { border: none; border-bottom: 2px solid transparent; background: none; border-radius: 0; padding: 5px 8px; color: #555; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: bold; }
.tabcontent { display: none; }
.tabcontent.active { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.grow { flex: 1 1 auto; min-height: 0; overflow: auto; }

/* infos moteur / éval / arbre */
.info { font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; background: #fafafa; padding: 6px; border-radius: 4px; min-height: 18px; }
#tree { font-size: 13px; line-height: 1.7; margin-top: 6px; flex: 1 1 auto; min-height: 60px; overflow: auto; }
#tree .mv { cursor: pointer; padding: 0 3px; border-radius: 3px; }
#tree .mv:hover { background: #eee; }
#tree .mv.cur { background: var(--sel); }
#tree .var { color: #666; }
#tree .tline { padding: 1px 0; border-left: 1px solid transparent; }
#tree .tline:not(:first-child) { border-left-color: var(--border); }
#turn { font-weight: bold; margin-bottom: 6px; }
#turn .disc { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid #555; vertical-align: middle; margin-right: 4px; }
.evalrow { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.pvline { margin-left: 10px; padding: 1px 4px; border-radius: 3px; cursor: pointer;
          white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pvline:hover { background: #eef4ff; }
#engine-info b { color: var(--accent); }
/* hauteur fixe : « Réflexion… » ou 5 variantes occupent la même place (l'arbre ne bouge plus) */
#engine-info { height: 188px; overflow: auto; }
.evalrow > span:first-child, .evalrow > b:first-child { white-space: nowrap; }
.evalrow.off { color: #aaa; }

/* listes */
.list { flex: 1 1 auto; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 4px; margin-top: 6px; }
.list .item { padding: 4px 6px; border-bottom: 1px solid #eee; cursor: pointer; font-size: 13px; }
.list .item:hover { background: #f0f6ff; }
.eco { color: #999; font-size: 11px; }
.games { width: 100%; border-collapse: collapse; margin-top: 6px; }
.games td { font-size: 12px; padding: 2px 5px; border-bottom: 1px solid #eee; }
.st { font-weight: bold; text-align: center; }
.st-pending { color: #bbb; } .st-inprogress { color: var(--accent); }
.st-white { color: #1a7f1a; } .st-black { color: #b00; } .st-draw { color: #888; }
.statline { font-size: 13px; margin: 4px 0; }
fieldset { border: 1px solid var(--border); border-radius: 4px; margin: 6px 0; padding: 6px; }
legend { font-size: 12px; color: #666; }
