/* ia-retro — simulateur de combat : thème sombre "outil interne" (cohérent dashboard MoonBot) */
:root {
  --bg: #1e1f22;
  --bg-2: #232428;
  --bg-3: #2b2d31;
  --bg-4: #313338;
  --border: #3a3b40;
  --text: #e3e5e8;
  --text-dim: #949ba4;
  --text-faint: #6b6f78;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-bg: rgba(99,102,241,0.16);
  --ally: #60a5fa;
  --ally-bg: rgba(96,165,250,0.15);
  --enemy: #f87171;
  --enemy-bg: rgba(248,113,113,0.15);
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --gold: #f0d080;
  --radius: 6px;
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; line-height: 1.4;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--bg-4); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 10px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { background: #3a3c42; border-color: #4a4c52; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #5558e6; border-color: #5558e6; }
button.danger { color: var(--danger); }
button.small { padding: 2px 7px; font-size: 12px; }
button.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-2); }
input[type=text], input[type=number], input[type=search], select {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 6px; min-width: 0;
}
input[type=text]:focus, input[type=number]:focus, input[type=search]:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=number] { width: 70px; }
input[type=range] { accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
label { color: var(--text-dim); }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.team-0 { color: var(--ally); }
.team-1 { color: var(--enemy); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.team-0 { background: var(--ally); }
.dot.team-1 { background: var(--enemy); }

/* ── barre du haut ─────────────────────────────────────────── */
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: var(--bg-2);
  border-bottom: 1px solid var(--border); height: 42px; flex: none;
}
#topbar .brand { font-weight: 700; letter-spacing: 0.3px; }
#topbar .brand span { color: var(--text-dim); font-weight: 400; margin-left: 6px; }
#banner {
  flex: 1; padding: 4px 10px; border-radius: var(--radius); font-size: 12px; display: flex; align-items: center; gap: 8px;
  max-width: 760px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#banner.error { background: rgba(248,113,113,0.15); color: #fca5a5; border: 1px solid rgba(248,113,113,0.35); }
#banner.info { background: var(--accent-bg); color: var(--accent-2); border: 1px solid rgba(99,102,241,0.4); }
#banner .msg { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#banner button { padding: 0 6px; background: transparent; border: none; color: inherit; }
#topbar .spacer { flex: 1; }

/* ── disposition principale ────────────────────────────────── */
#layout { flex: 1; display: grid; grid-template-columns: 310px 1fr 290px; min-height: 0; }
aside { background: var(--bg-2); overflow-y: auto; min-height: 0; }
#left { border-right: 1px solid var(--border); }
#right { border-left: 1px solid var(--border); }
.panel { border-bottom: 1px solid var(--border); padding: 8px 10px; }
.panel h2 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.panel h2 .grow { flex: 1; }
#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ── carte : recherche + liste ────────────────────────────── */
#map-search { width: 100%; }
#map-results { max-height: 180px; overflow-y: auto; margin-top: 4px; border: 1px solid var(--border); border-radius: var(--radius); }
#map-results:empty { display: none; }
#map-results .item { padding: 4px 8px; cursor: pointer; display: flex; gap: 6px; border-bottom: 1px solid var(--bg-3); }
#map-results .item:last-child { border-bottom: none; }
#map-results .item:hover, .list .item:hover { background: var(--bg-4); }
#map-results .item.sel { background: var(--accent-bg); }
#map-results .item .id { font-family: var(--mono); color: var(--text-dim); min-width: 46px; }
#map-results .item .coords { font-family: var(--mono); min-width: 52px; }
#map-results .item .zone { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#map-info { margin-top: 6px; font-size: 12px; }
#map-info .name { font-weight: 600; }

/* ── combattants ──────────────────────────────────────────── */
#fighter-list { display: flex; flex-direction: column; gap: 5px; }
.fcard {
  border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); padding: 5px 7px; background: var(--bg-3);
}
.fcard.team-0 { border-left-color: var(--ally); }
.fcard.team-1 { border-left-color: var(--enemy); }
.fcard.sel { outline: 1px solid var(--accent); }
.fcard.unplaced { border-style: dashed; }
.fcard .head { display: flex; align-items: center; gap: 6px; }
.fcard .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcard .sub { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.fcard .actions { display: flex; gap: 4px; margin-top: 4px; }
.fcard .warn { color: var(--warn); }
.badge { display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 11px; background: var(--bg-4); color: var(--text-dim); }
.badge.manual { background: rgba(251,191,36,0.15); color: var(--warn); }
.badge.ai { background: var(--accent-bg); color: var(--accent-2); }
#fighter-empty { color: var(--text-faint); font-size: 12px; padding: 4px 0; }
#locked-note { color: var(--warn); font-size: 12px; margin-top: 6px; }

/* ── options ──────────────────────────────────────────────── */
.opts { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.opts .full { grid-column: 1 / -1; }
.opts .hpw { display: flex; align-items: center; gap: 6px; }
.opts .hpw input { flex: 1; }
.opts .hpw span { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

/* ── barre d'outils simulation ────────────────────────────── */
#toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--bg-2); flex-wrap: wrap;
}
#toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
#toolbar #speed { width: 90px; }
#sim-status { color: var(--text-dim); font-size: 12px; margin-left: auto; }
#sim-status b { color: var(--text); }
#sim-status .winner { color: var(--gold); font-weight: 600; }

/* ── zone carte ───────────────────────────────────────────── */
#map-wrap { position: relative; flex: 1; min-height: 260px; background: var(--bg); overflow: hidden; }
#map { display: block; cursor: pointer; }
#hover-info {
  position: absolute; left: 8px; bottom: 8px; background: rgba(20,21,25,0.88); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 8px; font-size: 11.5px; font-family: var(--mono); color: var(--text); pointer-events: none; max-width: 460px;
}
#hover-info:empty { display: none; }
#hover-info .ok { color: var(--ok); } #hover-info .ko { color: var(--danger); } #hover-info .sep { color: var(--text-faint); margin: 0 5px; }
#mode-hint {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(99,102,241,0.9); color: #fff;
  padding: 4px 12px; border-radius: 14px; font-size: 12px; pointer-events: none; white-space: nowrap;
}
#mode-hint:empty { display: none; }
#legend {
  position: absolute; right: 8px; bottom: 8px; background: rgba(20,21,25,0.75); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 3px 8px; font-size: 10.5px; color: var(--text-dim); pointer-events: none; display: flex; gap: 10px;
}
#legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 3px; vertical-align: -1px; }

/* ── barre manuel ─────────────────────────────────────────── */
#manual-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--border); background: rgba(251,191,36,0.06); flex-wrap: wrap;
}
#manual-bar .who { color: var(--warn); font-weight: 600; }
#manual-bar .grow { display: none; }
#manual-bar #btn-pass { order: 2; margin-left: auto; }
#manual-bar .spells { order: 3; display: flex; gap: 4px; flex: 1 1 100%; min-width: 0; overflow-x: auto; padding-bottom: 3px; }
#manual-bar .spell { flex: none; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; padding: 3px 8px; }
#manual-bar .spell small { color: var(--text-dim); font-size: 10.5px; }
#manual-bar .spell.active small { color: var(--accent-2); }
#manual-bar .spell.low { opacity: 0.55; }

/* ── journal ──────────────────────────────────────────────── */
#journal { height: 230px; flex: none; border-top: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg-2); }
#journal .jhead { display: flex; align-items: center; gap: 8px; padding: 4px 10px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); font-weight: 600; }
#journal .jhead .grow { flex: 1; }
#journal-list { flex: 1; overflow-y: auto; margin: 0; padding: 4px 10px; list-style: none; font-size: 12px; }
#journal-list li { padding: 1.5px 0; border-bottom: 1px dotted rgba(255,255,255,0.04); }
#journal-list li .t { color: var(--text-faint); font-family: var(--mono); font-size: 10.5px; margin-right: 6px; }
#journal-list li.turn { color: var(--gold); font-weight: 600; margin-top: 4px; border-bottom: 1px solid rgba(240,208,128,0.2); }
#journal-list li.dimline { color: var(--text-faint); }
#journal-list li.error { color: var(--danger); }
#journal-list li.death { color: #fca5a5; font-weight: 600; }
#journal-list li.end { color: var(--gold); font-weight: 700; margin-top: 4px; }
#journal-list li.sys { color: var(--accent-2); }
#journal-list li.ai details summary { cursor: pointer; color: var(--accent-2); }
#journal-list li.ai details summary:hover { text-decoration: underline; }
#journal-list li.ai .ai-text { white-space: pre-wrap; font-family: var(--mono); font-size: 11px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; margin: 4px 0; }
#journal-list table.cands { border-collapse: collapse; margin: 2px 0 6px; font-size: 11.5px; }
#journal-list table.cands th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 2px 8px 2px 0; border-bottom: 1px solid var(--border); }
#journal-list table.cands td { padding: 2px 8px 2px 0; border-bottom: 1px solid rgba(255,255,255,0.05); vertical-align: top; }
#journal-list table.cands tr.best td { color: var(--ok); }
#journal-list table.cands td.score { font-family: var(--mono); text-align: right; }
#journal-list .bd { display: inline-block; margin: 0 6px 1px 0; font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); }
#journal-list .bd b { color: var(--text); font-weight: 500; }
#journal-list .bd.pos b { color: var(--ok); } #journal-list .bd.neg b { color: var(--danger); }
.el-0 { color: #cbd5e1; } .el-1 { color: #c4894f; } .el-2 { color: #fb923c; } .el-3 { color: #38bdf8; } .el-4 { color: #4ade80; }
.heal { color: #4ade80; }

/* ── panneau d'état (droite) ──────────────────────────────── */
#state-head { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
#state-head b { color: var(--text); }
#order-list { display: flex; flex-direction: column; gap: 4px; }
.frow { border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); padding: 4px 7px; background: var(--bg-3); cursor: pointer; }
.frow.team-0 { border-left-color: var(--ally); }
.frow.team-1 { border-left-color: var(--enemy); }
.frow.current { background: rgba(240,208,128,0.08); outline: 1px solid rgba(240,208,128,0.5); }
.frow.dead { opacity: 0.45; }
.frow.dead .name { text-decoration: line-through; }
.frow.sel { outline: 1px solid var(--accent); }
.frow .head { display: flex; align-items: center; gap: 6px; }
.frow .idx { font-family: var(--mono); color: var(--text-faint); font-size: 10.5px; width: 14px; }
.frow .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .cell { font-family: var(--mono); color: var(--text-dim); font-size: 11px; }
.frow .stats { display: flex; gap: 8px; font-size: 11.5px; margin-top: 2px; align-items: center; }
.frow .hpbar { flex: 1; height: 5px; background: rgba(0,0,0,0.4); border-radius: 3px; overflow: hidden; }
.frow .hpbar i { display: block; height: 100%; background: var(--ok); }
.frow.team-1 .hpbar i { background: #c02020; }
.frow .pa { color: #93c5fd; } .frow .pm { color: #86efac; }
.frow .chips { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.chip { font-size: 10.5px; padding: 0 5px; border-radius: 3px; background: rgba(251,191,36,0.12); color: var(--warn); }
.chip.state { background: rgba(192,132,252,0.15); color: #d8b4fe; }
.chip.neg { background: rgba(248,113,113,0.12); color: var(--danger); }
#marks-list { font-size: 11.5px; color: var(--text-dim); }
#state-empty { color: var(--text-faint); font-size: 12px; }

/* ── dialogues ────────────────────────────────────────────── */
dialog {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0; max-width: 720px; width: 92vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog .dhead { padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 8px; }
dialog .dbody { padding: 10px 14px; max-height: 70vh; overflow-y: auto; }
dialog .dfoot { padding: 8px 14px; border-top: 1px solid var(--border); display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
dialog .dfoot .note { flex: 1; color: var(--text-dim); font-size: 11.5px; }
dialog h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); margin: 10px 0 5px; }
.list { border: 1px solid var(--border); border-radius: var(--radius); max-height: 200px; overflow-y: auto; }
.list .item { padding: 4px 8px; cursor: pointer; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--bg-3); }
.list .item.sel { background: var(--accent-bg); }
.list .item .id { font-family: var(--mono); color: var(--text-dim); min-width: 40px; }
.list .item .lvl { color: var(--text-dim); margin-left: auto; font-size: 11.5px; }
.list .empty { padding: 6px 8px; color: var(--text-faint); }
.grades { display: flex; flex-direction: column; gap: 3px; }
.grades label { display: flex; gap: 8px; align-items: center; padding: 3px 6px; border-radius: var(--radius); cursor: pointer; color: var(--text); }
.grades label:hover { background: var(--bg-4); }
.grades label .g { font-weight: 600; min-width: 62px; }
.grades label .d { color: var(--text-dim); font-size: 11.5px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px 10px; }
.stats-grid label { display: flex; flex-direction: column; font-size: 11px; }
.stats-grid input { width: 100%; }
.res-grid { display: grid; grid-template-columns: 90px repeat(5, 1fr); gap: 4px 6px; align-items: center; font-size: 11.5px; }
.res-grid .h { color: var(--text-dim); text-align: center; }
.res-grid input { width: 100%; }
table.spells { width: 100%; border-collapse: collapse; font-size: 12px; }
table.spells td { padding: 2px 4px; border-bottom: 1px solid var(--bg-3); }
table.spells td.id { font-family: var(--mono); color: var(--text-dim); width: 46px; }
table.spells select { width: 58px; }
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.form-row label { display: flex; align-items: center; gap: 4px; }
.team-pick label { margin-right: 8px; }
.loading { color: var(--text-dim); font-style: italic; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #45474d; border-radius: 5px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-track { background: transparent; }

/* ── Miniatures (icônes monstres / classes / sorts) ── */
.mini { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px; background: var(--bg-4); overflow: hidden; flex: none; border: 1px solid var(--border); }
.mini.sm { width: 22px; height: 22px; border-radius: 5px; }
.mini.team-0 { border-color: var(--ally); }
.mini.team-1 { border-color: var(--enemy); }
.mini img { width: 100%; height: 100%; object-fit: contain; display: block; }
.mini .tok { font-size: 10px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; }
.mini.spell { width: 24px; height: 24px; border-radius: 4px; }
#manual-bar .spell { flex-direction: row; align-items: center; gap: 6px; }
#manual-bar .spell .txt { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }

/* ── Défis (configuration) ── */
.chal-list { max-height: 190px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-3); margin-top: 6px; }
.chal { display: flex; align-items: center; gap: 6px; padding: 3px 6px; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--border); }
.chal:last-child { border-bottom: none; }
.chal:hover { background: var(--bg-4); }
.chal.sel { background: var(--accent-bg); }
.chal.unsupported .name { color: var(--text-dim); }
.chal .id { font-family: var(--mono); color: var(--text-faint); font-size: 10.5px; width: 24px; text-align: right; }
.chal .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge.warn { background: rgba(251,191,36,0.15); color: var(--warn); }
.chal-selected { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.chal-row { display: flex; align-items: center; gap: 6px; font-size: 12px; flex-wrap: wrap; }
.chal-row .name { font-weight: 600; flex: 1; min-width: 90px; }
.chal-row label { color: var(--text-dim); font-size: 11px; display: inline-flex; align-items: center; gap: 2px; }
.chal-row input { width: 48px; }
.small { font-size: 11px; }
#chal-search { width: 100%; margin-top: 6px; }

/* ── Défis (état du combat) ── */
.chal-st { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 3px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.chal-st:last-child { border-bottom: none; }
.chal-st .name { font-weight: 600; flex: 1; }
.chal-st .st { padding: 0 6px; border-radius: 3px; background: var(--bg-4); font-size: 11px; }
.chal-st .st.ok { background: rgba(34,197,94,0.15); color: #86efac; }
.chal-st .st.ko { background: rgba(239,68,68,0.15); color: #fca5a5; }
.chal-st .st.warn { background: rgba(251,191,36,0.15); color: var(--warn); }
.chal-st .small { width: 100%; }

/* ── Prédiction ── */
.pred-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 2px 0; }
.pred-row .k { color: var(--text-dim); width: 108px; flex: none; }
.pred-row .bar { flex: 1; height: 8px; background: var(--bg-4); border-radius: 4px; overflow: hidden; }
.pred-row .bar i { display: block; height: 100%; border-radius: 4px; }
.pred-row .chips { display: flex; flex-wrap: wrap; gap: 3px; }
.chip.ok { background: rgba(34,197,94,0.15); color: #86efac; }
#chrono { color: var(--text-dim); padding: 0 6px; }
#journal li.chal { color: #fde68a; }
table.spells.mods th { font-size: 10.5px; color: var(--text-dim); font-weight: 500; text-align: left; padding: 2px 4px; }
table.spells.mods td { padding: 2px 4px; }
h3 .small { font-weight: 400; margin-left: 6px; }

.frow .belief { font-size: 11px; color: #fde68a; margin-top: 3px; line-height: 1.3; }
