:root {
  --bg: #0f1420;
  --panel: #171d2b;
  --panel-2: #1e2637;
  --line: #2a3446;
  --text: #e6ebf5;
  --muted: #8b97ad;
  --accent: #5b8cff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
h1 { margin: 0 0 8px; font-size: 20px; font-weight: 650; }
h1 .sub { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { border-color: var(--accent); }
#playBtn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#disciplineBtn.active { background: #3a7d44; border-color: #4e9d5a; color: #fff; font-weight: 600; }
.speed { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); cursor: pointer; }
.toggle select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 12px; cursor: pointer; }
.election { display: flex; align-items: center; gap: 12px; margin-left: 14px; font-size: 12px; }
.election .approval { font-weight: 650; font-variant-numeric: tabular-nums; }
.election .term, .election .mandate { color: var(--muted); }
.year { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Groupes sociaux */
.groups { display: flex; flex-direction: column; gap: 9px; }
.group { font-size: 12px; }
.group-top { display: flex; justify-content: space-between; margin-bottom: 3px; }
.group-top .name { display: inline-flex; align-items: center; gap: 6px; }
.group-top .name i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.group-top .share { color: var(--muted); font-size: 11px; }
.group-top .appr { font-variant-numeric: tabular-nums; font-weight: 600; }
.group-bar { height: 7px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.group-bar > div { height: 100%; border-radius: 4px; transition: width 0.2s, background 0.2s; }

/* Overlay défaite */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 11, 18, 0.82);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 32px; text-align: center; max-width: 420px;
}
.overlay-card h2 { margin: 0 0 10px; font-size: 22px; }
.overlay-card p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 20px; }

/* Modal d'événement */
.event-card { max-width: 540px; text-align: left; }
.event-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.event-tag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: #ffd15b; background: rgba(255, 209, 91, 0.12);
  border: 1px solid rgba(255, 209, 91, 0.3); border-radius: 6px; padding: 3px 9px;
}
.event-crit {
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  border: 1px solid currentColor; border-radius: 6px; padding: 3px 9px; white-space: nowrap;
}
.dec-crit { font-size: 11px; font-weight: 600; margin-left: 4px; }

/* Onglet Détail */
.detail-card { max-width: min(1000px, 95vw); width: 95vw; max-height: 90vh; overflow-y: auto; text-align: left; }
.detail-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -28px; background: var(--panel); padding-top: 4px; }
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-sec { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.detail-sec h3 { font-size: 13px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.budget-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.budget-bar > div { display: flex; align-items: center; justify-content: center; font-size: 10px; color: #0c111b; font-weight: 700; min-width: 0; }
.budget-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; font-size: 12.5px; }
.budget-list .bl { display: flex; align-items: center; gap: 6px; }
.budget-list .bl i { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.budget-sum { margin-top: 10px; font-size: 13px; }
.budget-sum b { font-variant-numeric: tabular-nums; }
.detail-axes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.detail-axis { background: var(--panel-2); border-radius: 8px; padding: 8px; }
.detail-axis .da-lab { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.detail-axis canvas { width: 100%; height: 70px; background: #0c111b; border-radius: 6px; }
.detail-axis .da-leg { font-size: 10px; color: var(--muted); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.detail-axis .da-leg i { display: inline-block; width: 9px; height: 3px; border-radius: 2px; margin-right: 3px; }
.params-table { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; font-size: 12.5px; }
.params-table .pk { color: var(--muted); }
.params-table .pv { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.params-dyn { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.params-dyn b { color: var(--accent); font-variant-numeric: tabular-nums; }
.reality { font-size: 13px; line-height: 1.55; color: var(--text); }
.reality .muted { color: var(--muted); }
.reality button { margin-top: 12px; }

/* Frise chronologique */
#timelineOverlay { z-index: 30; } /* au-dessus de l'écran de fin */
.recap-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.recap-card .recap-actions button { margin: 0; }
.timeline-card { max-width: min(1140px, 96vw); width: 96vw; text-align: left; }
.timeline-head { display: flex; justify-content: space-between; align-items: center; }
.timeline-head h2 { margin: 0; font-size: 18px; }
.timeline-sub { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }
#timelineCanvas { width: 100%; height: auto; background: #0c111b; border-radius: 8px; }

/* Console de commandes (façon Minecraft) */
.console {
  position: fixed; left: 16px; bottom: 16px; z-index: 25; width: min(560px, 92vw);
  background: rgba(12, 16, 26, 0.92); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  transition: opacity 0.2s; opacity: 0.55;
}
.console:focus-within { opacity: 1; }
.console-log {
  max-height: 168px; overflow-y: auto; padding: 8px 10px 4px; font-size: 12px; line-height: 1.5;
  display: flex; flex-direction: column; gap: 1px;
}
.console-log:empty { display: none; }
.console-log .cl-echo { color: #7fb0ff; }
.console-log .cl-ok { color: #8fe6a0; }
.console-log .cl-err { color: #ff8a8a; }
.console-log .cl-info { color: var(--muted); }
.console-log b { color: #fff; font-weight: 600; }
.console-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); }
.console-prompt { color: var(--accent); font-weight: 700; }
#consoleInput {
  flex: 1; background: transparent; border: none; outline: none; color: var(--text);
  font-family: inherit; font-size: 13px;
}
#consoleInput::placeholder { color: rgba(139, 151, 173, 0.6); }

/* Notifications non-bloquantes (décisions auto du pilote) */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast {
  background: var(--panel); border: 1px solid #4e9d5a; border-left-width: 3px;
  border-radius: 8px; padding: 9px 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.25s ease; transition: opacity 0.4s, transform 0.4s;
}
.toast.out { opacity: 0; transform: translateX(20px); }
.toast-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: 700; color: #8fe6a0; margin-bottom: 3px; }
.toast-crit { text-transform: uppercase; letter-spacing: 0.03em; }
.toast-body { font-size: 12.5px; color: var(--text); line-height: 1.4; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.event-options { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.event-opt {
  text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; cursor: pointer; width: 100%;
}
.event-opt:hover { border-color: var(--accent); background: #232c40; }
.event-opt .opt-label { font-size: 14px; font-weight: 650; color: var(--text); margin-bottom: 3px; }
.event-opt .opt-desc { font-size: 12px; color: var(--muted); line-height: 1.45; }
.event-opt.recommended { border-color: #4e9d5a; background: rgba(78, 157, 90, 0.1); }
.event-opt.recommended:hover { background: rgba(78, 157, 90, 0.18); }
.rec-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em;
  color: #8fe6a0; margin-bottom: 6px;
}

/* Bilan de fin de partie */
.recap-card { max-width: 560px; max-height: 86vh; overflow-y: auto; text-align: left; }
.recap-card h2 { text-align: center; }
.recap-section { margin-top: 16px; }
.recap-section h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.recap-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.recap-stats .rc { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; font-size: 13px; }
.recap-stats .rl { color: var(--muted); }
.recap-stats .rv { font-weight: 600; font-variant-numeric: tabular-nums; }
.recap-decisions { display: flex; flex-direction: column; gap: 6px; }
.dec-row { display: flex; gap: 10px; font-size: 12.5px; align-items: baseline; }
.dec-year { color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; min-width: 44px; }
.dec-body { line-height: 1.4; }
.dec-ok { color: #8fe6a0; margin-left: 6px; white-space: nowrap; }
.dec-ko { color: #e0b35b; margin-left: 6px; }
.dec-none { color: var(--muted); font-size: 13px; }

.metric.signpos .value { color: #5bd07a; }
.metric.signneg .value { color: #ff7a6b; }

/* Finances de l'État */
.debt-headline { text-align: center; padding: 6px 0 12px; }
.debt-big { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.debt-cap { font-size: 11px; color: var(--muted); margin-top: 6px; }
.fin-lines { display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--line); padding-top: 10px; }
.fin-line { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; }
.fin-line .lbl { color: var(--muted); }
.fin-line .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.fin-line .v.pos { color: #5bd07a; }
.fin-line .v.neg { color: #ff7a6b; }
.fin-bar { height: 6px; width: 90px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.fin-bar > div { height: 100%; border-radius: 3px; }

main {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}
/* Inputs (curseurs) à l'extrême gauche, collés au défilement */
.inputs { order: -1; position: sticky; top: 16px; }
.viz { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--muted);
  margin-bottom: 10px;
}
.pyramid-cap { font-size: 11px; font-weight: 600; color: var(--muted); }
.panel-head select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px;
}
canvas { width: 100%; height: auto; display: block; background: #0c111b; border-radius: 8px; }
.hint { font-size: 11px; color: var(--muted); margin: 8px 2px 0; }

/* Curseurs de politiques */
.slider { margin-bottom: 14px; }
.slider-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 5px; gap: 8px; }
.slider-meta { display: inline-flex; gap: 8px; align-items: baseline; white-space: nowrap; }
.slider-meta .share { font-size: 10.5px; color: var(--muted); }
.slider-top .val { color: var(--accent); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.slider .desc { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* Tableau de bord */
.dash { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--panel-2); border-radius: 8px; padding: 10px; }
.metric .label { font-size: 11px; color: var(--muted); }
.metric .value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric .value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.metric[title] { cursor: help; }
.metric .info { font-size: 10px; color: var(--muted); opacity: 0.6; }

/* Axes d'analyse (sliders en lecture seule) */
.axes { display: flex; flex-direction: column; gap: 11px; }
.axis-row { font-size: 12px; cursor: help; }
.axis-top { display: flex; justify-content: space-between; margin-bottom: 5px; }
.axis-top .av { font-variant-numeric: tabular-nums; font-weight: 650; }
.axis-body { display: flex; align-items: center; gap: 9px; }
.axis-track { position: relative; height: 6px; background: var(--panel-2); border-radius: 4px; flex: 1; }
.axis-body .axis-spark { width: 96px; height: 24px; flex-shrink: 0; background: transparent; border-radius: 0; }
.axis-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 4px; transition: width 0.25s, background 0.25s; }
.axis-handle { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); border: 2px solid var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,0.4); transition: left 0.25s, background 0.25s; }
.axis-poles { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--muted); margin-top: 3px; opacity: 0.7; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

@media (max-width: 1180px) {
  main { grid-template-columns: 260px 1fr 280px; gap: 12px; }
}
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  .inputs { position: static; }
}
