:root {
  --bg: #171717;
  --panel: #1a1a1a;
  --panel-alt: #1e1e1e;
  --border: #2a2a2a;
  --border-light: #333;
  --text: #e5e5e5;
  --text-dim: #a3a3a3;
  --text-dimmer: #737373;
  --accent: #F0A202;
  --accent-soft: rgba(240, 162, 2, 0.12);
  --boost: #4ade80;
  --cut: #f87171;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 0 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  padding: 24px 8px 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { font-size: 34px; line-height: 1; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.2px; }
.tagline { margin: 2px 0 0; color: var(--text-dim); font-size: 13px; }

.panel-card {
  max-width: 980px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.selectors {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}
.field { min-width: 180px; flex: 1; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
select {
  width: 100%;
  background: #262626;
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 16px;
  flex-wrap: wrap;
}
.mode-label { font-size: 13px; color: var(--text-dimmer); }
.mode-label.active { color: var(--text); font-weight: 600; }
.toggle {
  position: relative;
  width: 44px; height: 24px;
  border-radius: 999px;
  border: none;
  background: #333;
  cursor: pointer;
  padding: 0;
}
.toggle[aria-pressed="true"] { background: var(--accent); }
.toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.toggle[aria-pressed="true"] .toggle-knob { transform: translateX(20px); }
.mode-hint { font-size: 12px; color: var(--text-dimmer); margin-left: 4px; }

.manu-picker { margin-bottom: 14px; }
.manu-picker.hidden, .calibration-notice.hidden { display: none; }
.manu-picker label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 8px; }
.manu-slots { display: flex; gap: 10px; flex-wrap: wrap; }
.manu-slots select { max-width: 260px; }

.calibration-notice {
  background: rgba(240, 162, 2, 0.08);
  border: 1px solid rgba(240, 162, 2, 0.35);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #e8c37a;
}
.calibration-notice strong { color: var(--accent); }
.calibration-notice ul { margin: 6px 0 0; padding-left: 18px; }

.graph-section { margin-bottom: 20px; }
#graph-container svg { width: 100%; height: auto; display: block; }

.weights-section, .results-section { margin-top: 22px; }
.weights-section summary {
  font-size: 15px; margin: 0 0 4px; cursor: pointer; user-select: none;
  color: var(--text); font-weight: 600; list-style: none;
}
.weights-section summary::-webkit-details-marker { display: none; }
.weights-section summary::before { content: "▸ "; color: var(--accent); }
.weights-section[open] summary::before { content: "▾ "; }
.weights-section summary:hover { color: var(--accent); }
.results-section h2 { font-size: 15px; margin: 0 0 4px; }
.results-intro { font-size: 12.5px; color: var(--text-dimmer); margin: 0 0 12px; }
.weights-intro { font-size: 12.5px; color: var(--text-dimmer); margin: 8px 0 12px; }

.weight-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.weight-row:last-child { border-bottom: none; }
.weight-label { min-width: 190px; font-size: 13px; font-weight: 500; }
.weight-row.dominant .weight-label { color: var(--accent); }
.weight-bar-track {
  flex: 1;
  height: 8px;
  background: #262626;
  border-radius: 4px;
  overflow: hidden;
}
.weight-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #5a5a5a, var(--accent));
  border-radius: 4px;
}
.weight-pct { width: 42px; text-align: right; font-size: 12px; color: var(--text-dim); }
.weight-explanation { font-size: 12px; color: var(--text-dimmer); flex-basis: 100%; margin-top: 2px; padding-left: 190px; }

.mic-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.mic-card.etoile { border-left-color: var(--accent); }
.mic-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.mic-name { font-weight: 600; font-size: 14.5px; }
.star { color: var(--accent); }
.badge {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge.bon-plan { background: rgba(74, 222, 128, 0.15); color: var(--boost); border: 1px solid rgba(74,222,128,0.4); }
.mic-price { margin-left: auto; font-size: 13px; color: var(--text-dim); }
.mic-dist { font-size: 11px; color: var(--text-dimmer); }
.mic-type { font-size: 12px; color: var(--text-dimmer); margin-top: 2px; }

.criteria-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.crit-chip {
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 5px;
  background: #262626;
  color: var(--text-dim);
}
.crit-chip.high { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }

.eq-list { margin: 10px 0 0; padding: 0; list-style: none; }
.eq-list li { font-size: 12.5px; color: var(--text-dim); padding: 2px 0; }
.eq-boost { color: var(--boost); font-weight: 600; }
.eq-cut { color: var(--cut); font-weight: 600; }
.eq-source-note {
  margin: 6px 0 0; font-size: 10.5px; color: var(--text-dimmer); line-height: 1.4; font-style: italic;
}

/* Bouton "agir sur ce micro" en mode Auto — seul moyen de faire basculer un
   micro précis en mode Manu sans tout effacer, quel que soit le nombre de
   positions qu'il propose (signalé : impossible de sélectionner un micro
   en mode Auto quand il n'a qu'une seule position). */
.mic-select-btn {
  margin-top: 8px;
  background: none; border: 1px solid var(--accent); color: var(--accent);
  border-radius: 6px; padding: 5px 11px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.mic-select-btn:hover { background: var(--accent-soft); }

.mic-source {
  margin-top: 8px;
  font-size: 11px;
}
.mic-source a { color: #7dc4e8; text-decoration: none; }
.mic-source a:hover { text-decoration: underline; }

.mic-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.eye-toggle {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-dimmer);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.eye-toggle.on {
  color: var(--text);
  border-color: var(--curve-color, var(--accent));
  background: color-mix(in srgb, var(--curve-color, var(--accent)) 15%, transparent);
}
.eq-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.eq-toggle {
  position: relative;
  width: 36px; height: 20px;
  border-radius: 999px;
  border: none;
  background: #333;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.eq-toggle[aria-pressed="true"] { background: var(--boost); }
.eq-toggle .toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.eq-toggle[aria-pressed="true"] .toggle-knob { transform: translateX(16px); }

.legend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 10px; }
.legend-name {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-swatch {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0;
  border: 1.5px solid;
}
/* Légende de la ligne en pointillé (courbe "fantôme" : micro seul derrière
   micro+préampli, ou micro+préampli derrière +EQ) — demande explicite, elle
   n'était nulle part expliquée. */
.legend-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-dimmer);
}
.legend-ghost-swatch {
  width: 16px; height: 0; border-top: 1.5px dashed var(--text-dimmer);
  flex-shrink: 0;
}
.legend-toggle-all {
  margin-left: auto;
  background: none; border: 1px solid var(--border-light); color: var(--text-dimmer);
  border-radius: 999px; padding: 3px 10px; font-size: 11px; cursor: pointer;
}
.legend-toggle-all:hover { color: var(--text); border-color: var(--text-dim); }

/* --- Zones utiles/à éviter : transition douce pour éviter le scintillement
   au survol près d'une frontière de bande (signalé "clignote"). ------------ */
.band-zone { transition: opacity 0.12s ease-out; }

/* --- Modale "pourquoi ce choix" (clic sur l'étiquette Choix documenté) --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--panel-alt); border: 1px solid var(--border-light);
  border-radius: 12px; padding: 0; max-width: 460px; width: 100%;
  max-height: 80vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  position: relative;
}
.modal-box .modal-head {
  padding: 18px 46px 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(240,162,2,0.08), transparent);
}
.modal-box .modal-body { padding: 16px 20px 20px; overflow-y: auto; }
.modal-box h3 { margin: 0; font-size: 15.5px; font-weight: 700; color: var(--text); letter-spacing: 0.1px; }
.modal-box .modal-kicker {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--boost); background: rgba(74,222,128,0.12); border: 1px solid rgba(74,222,128,0.35);
  border-radius: 999px; padding: 2px 9px; margin-bottom: 8px;
}
.modal-box p { font-size: 13px; color: var(--text-dim); line-height: 1.55; margin: 0 0 12px; }
.modal-box .modal-meta-row {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px;
}
.modal-box .modal-meta-chip {
  font-size: 11px; color: var(--text-dim); background: #262626;
  border: 1px solid var(--border-light); border-radius: 6px; padding: 4px 9px;
}
.modal-box .modal-source-block {
  background: #161616; border: 1px solid var(--border-light); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 12px; margin-top: 4px;
}
.modal-box .modal-source-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-dimmer); margin-bottom: 3px;
}
.modal-box .modal-source-text { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: 0; }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: #262626; color: var(--text-dim); border: 1px solid var(--border-light);
  border-radius: 999px; width: 28px; height: 28px; line-height: 1;
  font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); border-color: var(--text-dim); }
.ref-badge.documente, .ref-badge.estime { cursor: pointer; }
.ref-badge.documente:hover, .ref-badge.estime:hover { filter: brightness(1.2); }

/* --- Spider chart (caractéristiques du micro) ----------------------------- */
.mic-card-body { display: flex; gap: 14px; align-items: flex-start; }
.mic-card-main { flex: 1; min-width: 0; }
.mic-spider { flex-shrink: 0; width: 120px; }
.mic-spider svg { width: 120px; height: 120px; }

/* --- Sélecteur de position (directivité/filtre) : rendu plus visible,
   demande explicite (il se perdait dans la ligne de commentaire "type"). --- */
.mic-switch-row { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.mic-switch-row label { font-size: 11px; color: var(--text-dimmer); }
.card-switch-select {
  background: #262626; color: var(--text); border: 1px solid var(--accent);
  border-radius: 6px; padding: 4px 8px; font-size: 12px;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.graph-title { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.graph-subtitle { font-size: 10.5px; color: var(--text-dimmer); cursor: help; }
.eq-global-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--text-dim); cursor: pointer;
}

/* --- Chaîne du son --------------------------------------------------- */
.chain-section { margin: 4px 0 16px; }
.chain-title { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.signal-chain {
  display: flex;
  align-items: stretch;
  gap: 0;
  /* C'est une CHAÎNE : elle reste horizontale (pas de retour à la ligne,
     demande explicite — le retour à la ligne cassait la lecture "étape
     après étape"). Le défilement horizontal reste le bon outil quand elle
     déborde ; ce qui manquait, c'est de l'air entre le bas des boîtes et
     la barre de défilement elle-même (signalé : la barre se posait dessus). */
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 16px;
  margin-bottom: 4px;
}
.chain-stage {
  background: var(--panel-alt);
  border: 1px solid var(--border-light);
  border-radius: 7px;
  padding: 8px 12px;
  min-width: 108px;
  max-width: 190px;
  flex-shrink: 0;
  text-align: center;
}
.chain-stage-label { font-size: 10px; color: var(--text-dimmer); text-transform: uppercase; letter-spacing: 0.4px; }
.chain-stage-value {
  font-size: 12.5px; font-weight: 600; margin-top: 2px; color: var(--text);
  /* Texte long -> retour à la ligne DANS la boîte plutôt qu'une boîte qui
     s'étire à l'infini, mais la CHAÎNE elle-même reste sur une ligne. */
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}
/* Barre de défilement horizontale : assez d'air en dessous des boîtes pour
   qu'elle ne se pose jamais dessus (signalé). */
.chain-section { overflow: visible; }
.signal-chain::-webkit-scrollbar { height: 8px; }
.signal-chain::-webkit-scrollbar-track { background: transparent; }
.signal-chain::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
.chain-stage.chain-active { border-color: var(--accent); background: var(--accent-soft); }
.chain-stage.chain-off .chain-stage-value { color: var(--text-dimmer); font-weight: 400; }
.chain-arrow { align-self: center; color: var(--text-dimmer); font-size: 16px; padding: 0 8px; flex-shrink: 0; }

/* --- Préampli --------------------------------------------------------- */
.preamp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.preamp-note-field { flex: 1.6; }
.preamp-note { font-size: 11.5px; color: var(--text-dimmer); padding-top: 6px; line-height: 1.4; }
.preamp-note .unverified { color: #e0a030; }

/* --- Panneau "Caractère" du préampli ------------------------------------ */
.preamp-character {
  padding: 12px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
}
.preamp-character.hidden { display: none; }
#preamp-gain { width: 100%; margin-top: 4px; }
.character-gauges { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.gauge-row { display: flex; align-items: center; gap: 10px; }
.gauge-label { font-size: 12px; color: var(--text-dim); min-width: 150px; }
.gauge-track { flex: 1; height: 8px; background: #262626; border-radius: 4px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.15s ease; }
.gauge-fill.headroom { background: linear-gradient(90deg, var(--boost), var(--accent), var(--cut)); }
.gauge-fill.harmonic { background: linear-gradient(90deg, #5a5a5a, var(--accent)); }
.character-hint { font-size: 11.5px; color: var(--text-dimmer); margin: 10px 0 0; line-height: 1.4; }

/* --- Vue de courbe ----------------------------------------------------- */
.curve-view-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.curve-view-label { font-size: 12px; color: var(--text-dim); }
.curve-view-toggle { display: flex; gap: 6px; }
.cv-btn {
  background: #262626;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.cv-btn.active { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 600; }

.proximity-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.proximity-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.proximity-toggle input { accent-color: var(--accent); }
.proximity-hint { font-size: 11.5px; color: var(--text-dimmer); margin: 0; }

.mic-tier { margin-left: auto; font-size: 12px; color: var(--text-dim); background: #262626; border-radius: 999px; padding: 2px 10px; }

/* --- Points de réglage EQ sur la courbe + info-bulle ------------------- */
/* pointer-events:none est le cœur du correctif anti-scintillement : ces
   cercles sont peints par-dessus le rectangle invisible qui suit la souris
   (hit-overlay) — sans ça, ils lui volent les événements souris pile là où
   l'utilisateur regarde le plus (les points de réglage EQ), causant des
   mouseleave/mousemove réels en boucle (crosshair et zone qui clignotent). */
.eq-marker { transition: r 0.1s ease; pointer-events: none; }
.eq-point-tooltip {
  margin-top: 6px;
  background: #0f0f0f;
  border: 1px solid var(--border-light);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 420px;
}
.eq-point-tooltip.hidden { display: none; }
.eq-tip-head { font-weight: 700; margin-bottom: 2px; }
.eq-tip-setting { color: var(--text); margin-bottom: 2px; }
.eq-tip-why { color: var(--text-dimmer); font-size: 11.5px; }

/* --- Badge de confiance / fiche de décision ---------------------------- */
.mic-decision { font-size: 12px; color: var(--text-dim); margin-top: 6px; font-style: italic; }
.ref-badge { font-size: 10.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.ref-badge.documente { background: rgba(74, 222, 128, 0.15); color: var(--boost); border: 1px solid rgba(74,222,128,0.4); }
.ref-badge.estime { background: #262626; color: var(--text-dimmer); border: 1px solid var(--border-light); }

.manu-slot-group { display: flex; flex-direction: column; gap: 6px; }
.manu-slots select.switch-select { max-width: 200px; margin-top: 2px; }

.foot-note {
  max-width: 980px;
  margin: 20px auto 0;
  font-size: 11.5px;
  color: var(--text-dimmer);
  text-align: center;
}

@media (max-width: 640px) {
  .weight-label { min-width: 130px; font-size: 12px; }
  .weight-explanation { padding-left: 0; }
}
