:root {
  --bg: #06070f;
  --panel: rgba(14, 17, 32, 0.92);
  --panel-solid: #0c0f1c;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #00e5ff;
  --accent-2: #7c4dff;
  --sel: #a78bfa;
  --radius: 10px;
  --panel-w: 350px;
  font-family: "Lato", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 13px;
}

body { display: flex; }

/* ---------- Vue ---------- */
#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
}

#view, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#view { cursor: grab; touch-action: none; image-rendering: auto; }
#view.dragging { cursor: grabbing; }
#overlay { pointer-events: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 10px 14px 12px;
  background: rgba(6, 7, 15, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 260px;
  pointer-events: none;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.logo {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 12%, var(--accent) 35%, var(--accent-2) 70%, #2a1470 100%);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.6);
}
#stats {
  font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #cbd5e1;
  white-space: pre;
}
#stats b { color: var(--text); font-weight: 600; }
#stats .paused { color: var(--accent); font-weight: 700; }
.progress {
  margin-top: 8px;
  height: 3px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.2s linear;
}

/* ---------- Barre d'outils ---------- */
#toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
}
#toolbar button {
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  background: rgba(6, 7, 15, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#toolbar button:hover { background: rgba(20, 24, 48, 0.9); border-color: var(--line-strong); }
#toolbar button.on { border-color: var(--accent); color: var(--accent); }
#toolbar svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
#toolbar button.icon { padding: 0; width: 36px; }

/* ---------- Aide ---------- */
.card {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: 380px;
  padding: 14px 16px;
  background: rgba(6, 7, 15, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); }
.card ul { margin: 0; padding-left: 0; list-style: none; line-height: 1.85; }
.card .close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer;
}
.card.hidden { display: none; }
.muted { color: var(--muted); line-height: 1.5; margin: 10px 0 0; }
kbd {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.04);
}

/* ---------- Erreur ---------- */
#error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  background: rgba(6, 7, 15, 0.95);
  padding: 30px;
  z-index: 10;
}
#error[hidden] { display: none; }
#error h2 { color: var(--accent-2); margin: 0 0 10px; }
#error pre { max-width: 80vw; max-height: 60vh; overflow: auto; white-space: pre-wrap; color: #c9b8ff; }

/* ---------- Panneau ---------- */
#panel {
  width: var(--panel-w);
  flex: none;
  height: 100%;
  background: var(--panel-solid);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}
body.panel-hidden #panel { display: none; }

.sec { border-bottom: 1px solid var(--line); }
.sec > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::before {
  content: "";
  width: 6px; height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
.sec[open] > summary::before { transform: rotate(45deg); }
.sec > summary:hover { color: #fff; }
.sec-body { padding: 2px 16px 14px; }

.row {
  display: grid;
  grid-template-columns: 120px 1fr 86px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}
.row label { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .val {
  text-align: right;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #cbd5e1;
}
.row.wide { grid-template-columns: 136px 1fr; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: #2a2e3a; border-radius: 3px; }
input[type="range"]::-moz-range-track { height: 3px; background: #2a2e3a; border-radius: 3px; }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--accent); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px; margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: pointer;
}

select, input[type="text"] {
  width: 100%;
  background: #0e1120;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
}
select:focus, input[type="text"]:focus { outline: 1px solid var(--accent); }

input[type="color"] {
  width: 100%;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; }

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.btn {
  flex: 1 1 auto;
  background: #0e1120;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #141830; border-color: rgba(255, 255, 255, 0.26); }
.btn.primary { background: linear-gradient(45deg, #00e5ff, #7c4dff); border-color: transparent; color: #fff; font-weight: 600; }
.btn.danger:hover { border-color: #ff5a4a; color: #ff8a7a; }

.note { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 6px 0 2px; }

/* Liste d'objets */
.obj-list {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 6px 0;
}
.obj-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.obj-item:last-child { border-bottom: 0; }
.obj-item:hover { background: rgba(255, 255, 255, 0.04); }
.obj-item.sel { background: rgba(167, 139, 250, 0.12); box-shadow: inset 2px 0 0 var(--sel); }
.obj-item .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(255, 255, 255, 0.2); }
.obj-item .sw.sphere { border-radius: 50%; }
.obj-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj-item .kind { color: var(--muted); font-size: 11px; }

.editor { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line-strong); }
.editor h4 { margin: 6px 0 6px; font-size: 12px; color: var(--sel); font-weight: 600; }
.sub { margin: 10px 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: #6f7588; }

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
  body { flex-direction: column; }
  #stage { flex: 1 1 55%; height: auto; }
  #panel { width: 100%; height: 45%; border-left: 0; border-top: 1px solid var(--line); }
  #hud { min-width: 0; font-size: 11px; }
  .card { max-width: calc(100% - 28px); }
}

/* =====================================================================
   Pédagogie : accueil, leçons, rayon, bulles d'aide, mode expert
   ===================================================================== */
#hud .progress-legend {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--muted); margin-top: 3px;
}

/* Carte de leçon */
#lesson {
  max-width: 440px;
  bottom: 14px;
  border-color: rgba(0, 229, 255, 0.35);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
#lesson h3 { text-transform: none; letter-spacing: 0; font-size: 16px; color: #fff; margin: 2px 0 8px; }
#lesson-text { line-height: 1.6; color: #e2e8f0; }
#lesson-text b { color: var(--accent); font-weight: 600; }
.lesson-step { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); }
.try {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--sel);
  background: rgba(167, 139, 250, 0.07);
  border-radius: 0 6px 6px 0;
  line-height: 1.5;
  color: #e0d8ff;
}
.try::before { content: "À vous : "; font-weight: 700; color: var(--sel); }
#lesson-extra:empty { display: none; }
.lesson-nav { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.lesson-nav .btn { flex: none; }
.lesson-nav .btn:disabled { opacity: 0.35; cursor: default; }
.dots { flex: 1; display: flex; justify-content: center; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #3a3f50; cursor: pointer; }
.dots i.on { background: var(--accent); }

/* Trajet d'un rayon */
#ray-info {
  left: auto;
  right: 14px;
  bottom: 14px;
  max-width: 340px;
  max-height: 60%;
  overflow-y: auto;
}
#ray-steps { margin: 0; padding-left: 22px; line-height: 1.55; }
#ray-steps li { margin-bottom: 5px; }
#ray-steps li::marker { color: #00e5ff; font-weight: 700; }
#ray-steps .t { color: var(--muted); font-size: 11.5px; }
#ray-steps:empty { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.dash { height: 0; border-top: 2px dashed; background: none; }
body.ray-mode #view { cursor: crosshair; }
#btn-ray.on, #btn-tour.on { background: rgba(0, 229, 255, 0.18); }

/* Accueil */
.modal {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(6, 7, 15, 0.72);
  backdrop-filter: blur(4px);
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-box {
  max-width: 620px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 26px 28px 22px;
  line-height: 1.6;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-box h2 { margin: 0 0 10px; font-size: 22px; }
.modal-box p { color: #cbd5e1; margin: 10px 0; font-size: 13.5px; }
.modal-box b { color: var(--accent); }
.modal-box .btns { margin-top: 18px; }
.modal-box .btn { padding: 9px 14px; font-size: 13px; }
.diagram { width: 100%; height: auto; margin: 6px 0 4px; background: #06070f; border-radius: 10px; border: 1px solid var(--line); }
.diagram text { fill: #9aa1b3; font-size: 11px; font-family: inherit; }
.diagram text.hl { fill: #00e5ff; font-size: 11.5px; font-weight: 600; }

/* Bulles d'aide */
.info {
  display: inline-grid; place-items: center;
  width: 14px; height: 14px; margin-left: 5px;
  border-radius: 50%;
  border: 1px solid #4a5063;
  color: #8a90a2;
  font-size: 9.5px; font-weight: 700; font-style: normal;
  cursor: help;
  vertical-align: 1px;
  flex: none;
}
.info:hover, .info:focus { border-color: var(--sel); color: var(--sel); outline: none; }
#tip {
  position: fixed; z-index: 50;
  max-width: 270px;
  padding: 8px 10px;
  background: #0e1120;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #e3e6ee;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#tip.show { opacity: 1; }
.row label { display: flex; align-items: center; }
.row label .txt { overflow: hidden; text-overflow: ellipsis; }

/* Mode simple / expert */
body:not(.expert) .adv { display: none !important; }
.mode-switch {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px; color: var(--muted);
}
.mode-switch label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.scene-desc {
  margin: 8px 0 4px; padding: 9px 11px;
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid rgba(0, 229, 255, 0.18);
  border-radius: 8px;
  line-height: 1.55; color: #cbd5e1; font-size: 12px;
}
.mat-help { color: #b9c0d0; font-size: 11.5px; line-height: 1.5; margin: 4px 0 6px; font-style: italic; }

@media (max-width: 800px) {
  #toolbar button span { display: none; }
  #toolbar button { padding: 0; width: 36px; }
  #lesson, #ray-info { max-width: calc(100% - 28px); left: 14px; right: 14px; }
}

/* Boutons ‹ › pour ajuster d'un pas */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.stepper .val { flex: 1; min-width: 0; text-align: center; }
.stepper .step {
  width: 20px; height: 22px; padding: 0; flex: none;
  font: inherit; font-size: 15px; line-height: 1;
  color: var(--muted); background: var(--panel-solid);
  border: 1px solid var(--line-strong); border-radius: 5px;
  cursor: pointer; user-select: none; touch-action: none;
  transition: color 0.15s, border-color 0.15s;
}
.stepper .step:hover { color: var(--accent); border-color: var(--accent); }
.stepper .step:active { background: rgba(0, 229, 255, 0.15); }
