:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1c2027;
  --line: #2a2f38;
  --text: #e8eaee;
  --muted: #9aa3b2;
  --accent: #ff6a3d;
  --p: #ef233c;       /* principaux */
  --s: #ff9f1c;       /* secondaires */
  --st: #e9d985;      /* stabilisateurs */
  --o: #3b82f6;       /* origine */
  --t: #22c55e;       /* terminaison */
  --ok: #22c55e;
  --ko: #ef4444;
  --radius: 10px;
  --top: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

/* ── Barre du haut */
.topbar { height: var(--top); display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; transition: opacity .2s, background .2s; }
.logo:hover { background: var(--panel-2); }
.logo img { width: 24px; height: auto; display: block; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--bg); padding: 4px; border-radius: 12px; }
.tab { white-space: nowrap; border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 var(--line) inset; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); display: grid; place-items: center; flex: none; }

/* ── Disposition */
.layout { position: absolute; inset: var(--top) 0 0 0; display: flex; }
.sidebar { width: 320px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; z-index: 10; }
.stage { flex: 1; position: relative; min-width: 0; background: radial-gradient(ellipse at 50% 40%, #232a33 0%, #12151a 55%, #0b0d10 100%); }
#c { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.info { width: 380px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 20px; position: relative; z-index: 10; }
.info .close { position: absolute; top: 14px; right: 14px; }
.sheet-handle { display: none; }

.pane { display: none; }
.pane.active { display: block; }
.block { margin-bottom: 22px; }

/* ── Recherche */
.search { position: relative; margin-bottom: 18px; }
.search input { width: 100%; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
.search input:focus { border-color: var(--accent); }
.results { list-style: none; margin: 6px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.results:empty { display: none; }
.results li { padding: 9px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.results li:hover, .results li.kb { background: var(--panel-2); }
.results li small { color: var(--muted); flex: none; }

/* ── Interrupteurs */
.switch { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 36px; height: 20px; border-radius: 20px; background: var(--line); position: relative; transition: .2s; flex: none; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 18px; }
.range { display: block; font-size: 14px; margin-top: 10px; color: var(--muted); }
.range input { width: 100%; accent-color: var(--accent); margin-top: 6px; }
.hidden-info { margin-top: 10px; font-size: 13px; color: var(--muted); }
.link { background: none; border: 0; color: var(--accent); padding: 0; text-decoration: underline; font-size: 13px; }

/* ── Parcourir */
.browse details { border-bottom: 1px solid var(--line); }
.browse summary { padding: 10px 2px; cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; display: flex; justify-content: space-between; }
.browse summary::after { content: '+'; color: var(--muted); }
.browse details[open] summary::after { content: '–'; }
.browse summary small { color: var(--muted); font-weight: 400; margin-left: auto; margin-right: 10px; }
.browse ul { list-style: none; padding: 0 0 10px; margin: 0; }
.browse li { padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; color: #cfd4dc; }
.browse li:hover { background: var(--panel-2); color: var(--text); }

/* ── Mouvements */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 14px; align-items: center; }
.legend .mini { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.p { background: var(--p); } .dot.s { background: var(--s); } .dot.st { background: var(--st); }
.dot.o { background: var(--o); } .dot.t { background: var(--t); }
.move-list h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; }
.move { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.move:hover { background: var(--panel-2); }
.move.on { background: rgba(255,106,61,.12); border-color: rgba(255,106,61,.5); }

/* ── Fiche */
.info h2 { margin: 0 40px 4px 0; font-size: 22px; line-height: 1.2; }
.info .sub { color: var(--muted); font-size: 13px; font-style: italic; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); color: #cfd4dc; }
.chip.accent { border-color: rgba(255,106,61,.5); color: #ffb49c; }
.info section { margin-bottom: 16px; }
.info h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; }
.info p { margin: 0; line-height: 1.5; font-size: 14.5px; }
.info ul, .info ol { margin: 0; padding-left: 18px; line-height: 1.55; font-size: 14.5px; }
.info li { margin-bottom: 2px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card.o { border-left: 3px solid var(--o); }
.card.t { border-left: 3px solid var(--t); }
.tip { background: rgba(255,159,28,.08); border: 1px solid rgba(255,159,28,.3); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; line-height: 1.5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 9px 14px; border-radius: 9px; font-size: 14px; font-weight: 600; }
.btn:hover { border-color: #3a414d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide { width: 100%; margin-top: 16px; padding: 12px; }
.mlist { display: flex; flex-wrap: wrap; gap: 6px; }
.mlink { border: 1px solid var(--line); background: var(--bg); border-radius: 20px; padding: 4px 10px; font-size: 13px; }
.mlink:hover { border-color: var(--accent); }
.mlink.p { border-color: rgba(239,35,60,.6); } .mlink.s { border-color: rgba(255,159,28,.6); } .mlink.st { border-color: rgba(233,217,133,.5); }
.back { background: none; border: 0; color: var(--accent); padding: 0; margin-bottom: 10px; font-size: 13px; }

/* ── Barres flottantes */
.viewbar, .quickbar { position: absolute; display: flex; gap: 4px; background: rgba(21,24,29,.85); backdrop-filter: blur(8px); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.viewbar { bottom: 16px; left: 50%; transform: translateX(-50%); }
.quickbar { top: 14px; right: 14px; }
.viewbar button, .quickbar button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.viewbar button:hover, .quickbar button:hover { background: var(--panel-2); color: var(--text); }
.quickbar button.on { background: var(--panel-2); color: var(--text); }
.tooltip { position: absolute; pointer-events: none; background: rgba(13,15,18,.92); border: 1px solid var(--line); padding: 5px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap; transform: translate(14px, 14px); z-index: 5; }
.mode-banner { position: absolute; top: 14px; left: 14px; background: rgba(21,24,29,.9); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; max-width: calc(100% - 200px); }
.mode-banner b { color: var(--text); }

/* ── Chargement */
.loader { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(13,15,18,.85); z-index: 8; transition: opacity .4s; }
.loader.done { opacity: 0; pointer-events: none; }
.loader-box { text-align: center; width: 260px; }
.loader p { margin: 14px 0 10px; }
.bar { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.loader small { color: var(--muted); display: block; margin-top: 8px; }
.spinner { width: 34px; height: 34px; margin: 0 auto; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Quiz */
.seg { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 7px; font-size: 14px; color: var(--muted); font-weight: 600; line-height: 1.2; }
.seg button small { font-weight: 400; font-size: 11px; }
.seg button.on { background: var(--panel-2); color: var(--text); }
.quiz-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.quiz-q { font-size: 18px; font-weight: 600; line-height: 1.35; margin: 0 0 14px; }
.choices { display: grid; gap: 8px; }
.choice { text-align: left; border: 1px solid var(--line); background: var(--panel-2); padding: 12px 14px; border-radius: 10px; font-size: 15px; }
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice.ok { border-color: var(--ok); background: rgba(34,197,94,.15); }
.choice.ko { border-color: var(--ko); background: rgba(239,68,68,.15); }
.quiz-feedback { min-height: 22px; font-size: 14px; margin: 12px 0; line-height: 1.45; }
.quiz-feedback.ok { color: #6ee7a0; } .quiz-feedback.ko { color: #fca5a5; }
.row { display: flex; gap: 8px; justify-content: space-between; margin-bottom: 14px; }
.big-score { font-size: 44px; font-weight: 800; margin: 6px 0; }

/* ── Aide */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; max-width: 560px; width: calc(100% - 32px); padding: 22px 24px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; }
dialog li { margin-bottom: 8px; line-height: 1.45; }
.c-o { color: #7fb0ff; } .c-t { color: #6ee7a0; } .c-p { color: #ff6b7d; } .c-s { color: #ffc266; } .c-st { color: var(--st); }
.credits { font-size: 12px; color: var(--muted); line-height: 1.5; }
.credits a { color: var(--muted); }

/* ── Tablette / mobile */
@media (max-width: 1100px) {
  .info { width: 340px; }
  .sidebar { width: 280px; }
}
@media (max-width: 860px) {
  :root { --top: 52px; }
  .brand-text { display: none; }
  .topbar { padding: 0 10px; gap: 8px; }
  .tabs { margin: 0; flex: 1; }
  .tab { flex: 1; padding: 8px 6px; font-size: 13px; }
  .layout { display: block; }
  .stage { position: absolute; inset: 0; }
  .sidebar { position: absolute; left: 0; right: 0; bottom: 0; width: auto; max-height: 62%; border-right: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 0 16px 16px; transition: transform .25s; box-shadow: 0 -10px 30px rgba(0,0,0,.4); }
  .sidebar.collapsed { transform: translateY(calc(100% - 64px)); overflow: hidden; }
  .sheet-handle { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0 12px; position: sticky; top: 0; background: var(--panel); z-index: 2; cursor: pointer; }
  .sheet-handle span { width: 44px; height: 5px; border-radius: 5px; background: var(--line); }
  .sheet-handle b { font-size: 14px; }
  .sidebar.collapsed .sheet-handle b::after { content: ' ▲'; color: var(--muted); font-size: 11px; }
  .tab { font-size: 12.5px; padding: 8px 4px; }
  .mode-banner { bottom: 76px; }
  .info { position: absolute; left: 0; right: 0; bottom: 0; width: auto; max-height: 70%; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; z-index: 15; box-shadow: 0 -10px 30px rgba(0,0,0,.5); padding: 18px 16px 24px; }
  .viewbar { bottom: auto; top: 12px; left: 12px; transform: none; }
  .viewbar button { padding: 6px 8px; font-size: 12px; }
  .quickbar { top: 56px; left: 12px; right: auto; }
  .quickbar button { padding: 6px 8px; font-size: 12px; }
  .mode-banner { top: auto; bottom: 76px; left: 12px; right: 12px; max-width: none; }
}
