:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #66666d;
  --border: #dadad5;
  --accent: #2f5fd0;
  --accent-soft: #e7eefc;
  --canvas: #fdfdfb;
  --edge: #2a2a2e;
  --vertex: #8a8a92;
  --vertex-text: #ffffff;
  --waiting: #e0912f;
  --done: #2f8f57;
  --current: #2f5fd0;
  --tree: #18a058;
  --back: #d93636;
  --forward: #2f6fe0;
  --cross: #9a9aa3;
  --scan: #f08c00;
  --reject: #e8a0a0;
  --conflict: #d00000;
  --candidate: #5a8fff;
  --note-bg: #fff6d6;
  --note-text: #5c4300;
  --hl: #fff2b8;
  --mono: "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1f2125;
    --text: #e8e8ea;
    --muted: #9c9ca4;
    --border: #33353b;
    --accent: #7aa2ff;
    --accent-soft: #23304f;
    --canvas: #1a1b1f;
    --edge: #cfcfd4;
    --vertex: #5d5d66;
    --waiting: #d98a2b;
    --done: #2e9a5c;
    --current: #8fb0ff;
    --tree: #3ccf86;
    --back: #ff6b6b;
    --forward: #6ea3ff;
    --cross: #74747c;
    --scan: #ffa94d;
    --reject: #8a4b4b;
    --conflict: #ff4040;
    --candidate: #7aa2ff;
    --note-bg: #3a3320;
    --note-text: #ffe8a3;
    --hl: #3d3720;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel);
}
header h1 { font-size: 1.15rem; margin: 0; }
header .sub { color: var(--muted); font-size: .88rem; }
header .spacer { flex: 1; }
header nav { display: flex; gap: .25rem; }
header nav button { border-color: transparent; background: transparent; }
header nav button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
header a { color: var(--accent); text-decoration: none; font-size: .9rem; }
header a:hover { text-decoration: underline; }

/* ---------- mise en page de l'onglet Graphes ---------- */
#page-graph {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 370px;
  gap: .8rem; padding: .8rem; max-width: 1800px; margin: 0 auto;
}
@media (max-width: 1250px) {
  #page-graph { grid-template-columns: 290px minmax(0, 1fr); }
  #right { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  #page-graph { grid-template-columns: minmax(0, 1fr); }
  #center { order: -2; }
  #right { order: -1; }
  #canvas-help { display: none; }
}
.col { display: flex; flex-direction: column; gap: .8rem; min-width: 0; }

section, details.box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: .7rem .9rem; min-width: 0;
}
h2, summary {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 .5rem; font-weight: 700;
}
summary { cursor: pointer; margin: 0; }
details[open] > summary { margin-bottom: .55rem; }

label { display: flex; align-items: center; gap: .45rem; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .35rem 0; }
.grow { flex: 1; }
.params { display: grid; grid-template-columns: 1fr 5.5rem; gap: .3rem .5rem; align-items: center; font-size: .88rem; margin: .4rem 0; }
.slider { display: grid; grid-template-columns: 5.5rem 1fr 3rem; gap: .5rem; align-items: center; font-size: .86rem; margin: .25rem 0; }
.slider output { font-family: var(--mono); font-size: .78rem; text-align: right; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
button, select, input[type=number], input[type=text] {
  font: inherit; font-size: .88rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); padding: .32rem .6rem;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.on, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
select { width: 100%; }
input[type=number] { width: 100%; }
textarea {
  width: 100%; min-height: 9rem; font: .82rem var(--mono);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem;
  background: var(--panel); color: var(--text); resize: vertical;
}
.hint { color: var(--muted); font-size: .8rem; margin: .35rem 0 0; }
.err { color: var(--back); font-size: .85rem; }
kbd {
  font: .72rem var(--mono); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 3px; padding: 0 .25rem; background: var(--panel);
}
code { font-family: var(--mono); font-size: .9em; }

/* ---------- centre : barre d'outils, canvas, pas à pas ---------- */
#center { display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .5rem;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 .15rem; }
#canvas-wrap {
  position: relative; background: var(--canvas); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; height: calc(100vh - 12.5rem); min-height: 420px;
}
@media (max-width: 820px) { #canvas-wrap { height: 62vh; min-height: 320px; } }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#canvas-help {
  position: absolute; left: .6rem; bottom: .5rem; right: .6rem; pointer-events: none;
  font-size: .78rem; color: var(--muted);
}
#floating {
  position: absolute; display: none; width: 8rem; z-index: 5;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.stepbar {
  display: flex; gap: .4rem; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem;
}
.stepbar input[type=range] { flex: 1; min-width: 120px; }
.stepbar .info { font-size: .85rem; color: var(--muted); min-width: 6.5rem; text-align: right; }
.stepbar select { width: auto; }
.legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .78rem; color: var(--muted); min-height: 1.2rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.sw { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.ln { width: 18px; height: 0; display: inline-block; border-top: 3px solid; }
.ln.dash { border-top-style: dashed; }

/* ---------- panneau de droite ---------- */
.tabs { display: flex; gap: .25rem; margin-bottom: .6rem; border-bottom: 1px solid var(--border); }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent;
  padding: .35rem .55rem; color: var(--muted); font-weight: 600;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); background: transparent; }
#algo-desc { font-size: .86rem; color: var(--muted); margin: .4rem 0; }
#algo-warn { font-size: .82rem; color: var(--waiting); margin: .3rem 0; }
#message {
  background: var(--accent-soft); border-radius: 6px; padding: .5rem .65rem;
  font-size: .92rem; min-height: 2.6rem; margin: .5rem 0;
}
ol.code {
  font: .8rem/1.55 var(--mono); margin: .4rem 0; padding: .4rem .5rem .4rem 2.2rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  overflow-x: auto;
}
ol.code li { padding: 0 .3rem 0 1.6em; text-indent: -1.6em; border-radius: 3px; white-space: pre-wrap; }
ol.code li::marker { color: var(--muted); font-size: .72rem; }
ol.code li.hl { background: var(--hl); font-weight: 600; }
.struct-name { font-size: .78rem; color: var(--muted); margin-top: .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .3rem 0 .5rem; min-height: 1.6rem; }
.chip {
  font: .8rem var(--mono); border: 1px solid var(--border); border-radius: 5px;
  padding: .1rem .45rem; background: var(--bg);
}
.chip:first-child { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chips .empty { color: var(--muted); font-size: .8rem; }
.table-wrap { overflow: auto; max-height: 20rem; margin-top: .4rem; }
table.data { border-collapse: collapse; font: .8rem var(--mono); }
table.data th, table.data td { padding: .2rem .5rem; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
table.data td:first-child, table.data th:first-child { text-align: left; font-weight: 600; }
table.data tr.cur td { background: var(--accent-soft); }
pre.repr {
  font: .8rem var(--mono); background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: .5rem; max-height: 16rem; overflow: auto; margin: .3rem 0 .7rem;
}
.stats { font-size: .86rem; color: var(--muted); margin: .2rem 0 .5rem; }
.stats b { color: var(--text); font-weight: 600; }

/* ---------- fenêtre d'export ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem;
  background: var(--panel); color: var(--text); width: min(760px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog textarea { min-height: 18rem; }
dialog h2 { font-size: .95rem; text-transform: none; letter-spacing: 0; color: var(--text); }

/* ---------- onglet Remplissage ---------- */
#page-flood { padding: .8rem; max-width: 1800px; margin: 0 auto; display: flex; flex-direction: column; gap: .8rem; }
#flood-panes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
@media (max-width: 900px) { #flood-panes { grid-template-columns: minmax(0, 1fr); } }
.pane { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; }
.pane h3 { margin: 0 0 .35rem; font-size: .9rem; display: flex; justify-content: space-between; }
.pane h3 span { color: var(--muted); font-weight: 400; font-family: var(--mono); font-size: .8rem; }
.pane canvas { width: 100%; display: block; image-rendering: pixelated; touch-action: none; cursor: crosshair; border-radius: 4px; }

/* ---------- documentation ---------- */
#doc { margin: 0 auto 2rem; max-width: 1800px; padding: 1rem 1.6rem; }
#doc-inner { max-width: 900px; }
#doc h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); }
#doc h3 { font-size: 1rem; margin: 1.4rem 0 .4rem; }
#doc p, #doc li { max-width: 80ch; }
#doc table { border-collapse: collapse; margin: .4rem 0; }
#doc td, #doc th { text-align: left; padding: .3rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
#doc th { color: var(--muted); font-size: .85rem; }
.hidden { display: none !important; }
