:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273548;
  --accent: #38bdf8;
  --warn: #f87171;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --wire: #cbd5e1;
  --electron: #60a5fa;
  --conventional: #fb923c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
}

/* ---- Barre d'outils ---- */
#toolbar {
  display: flex; align-items: center; gap: 18px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.group { display: flex; align-items: center; gap: 8px; }
.group.status { margin-left: auto; }
.tb-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 14px; cursor: pointer;
}
.tb-btn:hover { border-color: var(--accent); }
.tb-btn.primary { background: var(--accent); color: #082f49; font-weight: 700; }
.tb-btn.danger:hover { border-color: var(--warn); color: var(--warn); }
.tb-btn.on { background: var(--accent); color: #082f49; }
.tb-select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
.tb-check { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.warn { color: var(--warn); font-weight: 700; }
.hidden { display: none !important; }

/* ---- Espace de travail ---- */
#workspace { display: flex; flex: 1; min-height: 0; }

#palette {
  width: 170px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 10px;
}
#palette h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 10px 0 6px;
}
#palette h3:first-child { margin-top: 0; }
.pal-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; margin-bottom: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px;
  color: var(--text); font-size: 13px; cursor: pointer; text-align: left;
}
.pal-item:hover { border-color: var(--accent); }
.pal-icon {
  width: 34px; height: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.pal-icon svg { display: block; }
.pal-icon.voltmeter-icon {
  border: 1.5px solid var(--wire); border-radius: 50%;
  font-weight: 700; font-size: 13px;
}

/* ---- Canevas : page quadrillée claire ---- */
#canvas {
  flex: 1; min-width: 0;
  background: #f7fafc;
  touch-action: none;
  outline: none;
  /* palette adaptée au fond clair */
  --wire: #1f2937;
  --accent: #0284c7;
  --muted: #475569;
  --electron: #2563eb;
  --conventional: #ea580c;
}
.comp { cursor: grab; }
.comp.dragging { cursor: grabbing; }
.comp.selected .body-sym { stroke: var(--accent); }
.comp .lead { stroke: var(--wire); stroke-width: 2.5; }
.comp .body-sym { stroke: var(--wire); stroke-width: 2; fill: none; }
.comp .fill-part { fill: var(--wire); stroke: none; }
.comp .label { fill: var(--muted); font-size: 11px; pointer-events: none; }
.comp .val-label { fill: var(--accent); font-size: 11px; font-weight: 600; pointer-events: none; }
.comp.selected .sel-box { display: block; }
.sel-box {
  display: none; fill: none;
  stroke: var(--accent); stroke-dasharray: 4 3; stroke-width: 1.2;
}
.term {
  fill: #94a3b8; stroke: var(--wire); stroke-width: 1.5;
  cursor: crosshair;
}
.term:hover, .term.hot { fill: var(--accent); }
.junction {
  fill: #fbbf24; stroke: #422006; stroke-width: 1;
  pointer-events: none;
}
.bulb-light { pointer-events: none; }

/* ---- Points de courant ---- */
.dot-e { fill: var(--electron); }
.dot-c { fill: var(--conventional); }

/* ---- Sondes voltmètre ---- */
.probe { cursor: grab; }
.probe circle { stroke-width: 2; }
.probe.p-plus circle { fill: #7f1d1d; stroke: #f87171; }
.probe.p-minus circle { fill: #111827; stroke: #94a3b8; }
.probe text { fill: #fff; font-size: 12px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.probe-line { stroke-dasharray: 4 4; stroke-width: 1.5; pointer-events: none; }
.probe.p-plus .probe-line { stroke: #f87171; }
.probe.p-minus .probe-line { stroke: #94a3b8; }

/* ---- Panneau latéral ---- */
#sidepanel {
  width: 300px; flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 14px;
}
#sidepanel h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 8px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.red { color: #f87171; font-weight: 700; }
.blk { color: #94a3b8; font-weight: 700; }

.prop-row { margin-bottom: 10px; }
.prop-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.prop-row input[type=range] { width: 100%; }
.prop-row .val { font-size: 13px; color: var(--accent); font-variant-numeric: tabular-nums; }
.prop-measure {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-top: 4px; font-size: 13px;
}
.prop-measure b { color: var(--accent); font-variant-numeric: tabular-nums; }

.voltmeter-read {
  font-size: 26px; font-weight: 700; color: var(--accent);
  background: #082f49; border-radius: 8px;
  padding: 8px 14px; text-align: center;
  font-variant-numeric: tabular-nums;
}
#chart { width: 100%; background: #0b1220; border-radius: 8px; border: 1px solid var(--border); }
.chart-legend { display: flex; gap: 14px; margin-top: 4px; font-size: 11px; }
.lg::before { content: "—"; margin-right: 4px; font-weight: 700; }
.lg.u { color: #f87171; } .lg.i { color: #60a5fa; }

/* ---- Aide ---- */
#help {
  padding: 6px 14px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
}
kbd {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 4px; font-size: 11px;
}

/* Note enseignant dans les fiches TP */
.prof-note { margin-top: 12px; background: rgba(245,158,11,.10);
  border-left: 3px solid #f59e0b; border-radius: 8px; padding: 8px 10px; }
.prof-note h3 { color: #fbbf24; }
.prof-note p { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
