:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273548;
  --accent: #38bdf8;
  --accent-2: #fbbf24;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --ok: #4ade80;
  --ko: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Header ---- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
h1 { font-size: 20px; font-weight: 600; }
.subtitle { font-size: 12px; color: var(--muted); }

nav { display: flex; gap: 8px; }
.nav-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.nav-btn:hover { border-color: var(--accent); }
.nav-btn.active { background: var(--accent); color: #082f49; font-weight: 600; }
.badge {
  background: var(--accent-2);
  color: #422006;
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
}

/* ---- Layout ---- */
.layout { display: flex; flex: 1; min-height: 0; position: relative; }

/* ---- Sidebar : panneau TP repliable, superpose la simulation ---- */
#sidebar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: min(360px, 92vw);
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 20;
  transform: none;
  transition: transform .25s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,.45);
}
#sidebar.hidden, #sidebar.collapsed {
  transform: translateX(-106%);
  box-shadow: none;
}

.sidebar-head { padding: 14px 16px 8px; }
.sidebar-head h2 { font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- Activity cards ---- */
.activity {
  margin: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  overflow: hidden;
}
.activity > button.head {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.activity > button.head:hover { background: rgba(56, 189, 248, .08); }
.activity.open > button.head { border-bottom: 1px solid var(--border); }

.tp-num {
  background: var(--accent);
  color: #082f49;
  font-weight: 700;
  font-size: 12px;
  border-radius: 6px;
  padding: 3px 7px;
  flex-shrink: 0;
}
.tp-title { flex: 1; font-size: 14px; font-weight: 600; }
.tp-level {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}
.tp-level.lycee { color: var(--accent-2); border-color: var(--accent-2); }

.activity .body { display: none; padding: 10px 14px 14px; font-size: 13px; line-height: 1.5; }
.activity.open .body { display: block; }
.body h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent);
  margin: 10px 0 4px;
}
.body h3:first-child { margin-top: 0; }
.body ul, .body ol { padding-left: 18px; }
.body li { margin: 3px 0; }
.body .conso { color: var(--muted); font-style: italic; }
.body .question {
  background: rgba(251, 191, 36, .08);
  border-left: 3px solid var(--accent-2);
  padding: 5px 8px;
  margin: 4px 0;
  border-radius: 0 6px 6px 0;
}

/* ---- Main : laboratoire ---- */
#main { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }

a.nav-btn { text-decoration: none; display: inline-block; }

/* ---- Étapes / chips ---- */
#controls {
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 14px 34px;
  flex-shrink: 0;
}
.step-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}
.step-num {
  background: var(--accent);
  color: #082f49;
  border-radius: 50%;
  width: 20px; height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  background: var(--panel-2);
  border: 2px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.selected { border-color: var(--accent); background: rgba(56,189,248,.15); }
.chip.ok { border-color: var(--ok); background: rgba(74,222,128,.12); }
.chip.ko { border-color: var(--ko); background: rgba(248,113,113,.10); }
.chip:disabled { opacity: .55; cursor: default; }

/* ---- Scène ---- */
#stage { flex: 1; position: relative; min-height: 0; padding: 10px 18px 16px; }
#scene {
  width: 100%;
  height: 100%;
  max-height: calc(100% - 4px);
  display: block;
}

/* transitions SVG (propriétés géométriques) */
#scene rect, #scene ellipse, #scene path, #scene circle, #scene g, #scene text, #scene line {
  transition:
    x .9s ease, y .9s ease, height .9s ease, width .9s ease,
    opacity .5s ease, transform .9s ease;
}
#scene .flow-line { transition: opacity .35s ease; }
#scene .dash { stroke-dasharray: 10 8; animation: dash .5s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -18; } }
#scene .vapor { animation: rise 1.6s ease-in infinite; }
@keyframes rise {
  0% { transform: translateY(0); opacity: .9; }
  100% { transform: translateY(-46px); opacity: 0; }
}
#scene .bubbles { animation: bub 1s ease-in infinite; }
@keyframes bub { to { transform: translateY(-38px); opacity: 0; } }
#scene .flame { animation: flick .3s ease-in-out infinite alternate; transform-origin: center bottom; }
@keyframes flick { to { transform: scaleY(1.15) scaleX(.95); } }
#scene .wiggle { animation: wig 1.2s ease-in-out infinite; }
@keyframes wig { 0%,100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
#scene .tilt { transform-box: view-box; transform-origin: 168px 112px; }
#scene .run-tilt { transform: rotate(-24deg); }

/* ---- Verdict ---- */
#verdict {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(560px, 92%);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  border: 2px solid var(--border);
  background: rgba(30, 41, 59, .96);
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: pop .3s ease;
}
#verdict.hidden { display: none; }
#verdict.ok { border-color: var(--ok); }
#verdict.ko { border-color: var(--ko); }
#verdict h3 { font-size: 15px; margin-bottom: 4px; }
#verdict.ok h3 { color: var(--ok); }
#verdict.ko h3 { color: var(--ko); }
#verdict .mini { color: var(--muted); font-size: 12px; margin-top: 6px; }
@keyframes pop { from { transform: translateX(-50%) translateY(12px); opacity: 0; } }

@media (max-width: 720px) {
  #controls { gap: 10px 18px; padding: 8px 12px; }
  .chip { padding: 6px 10px; font-size: 13px; }
}

/* ---- Respiration : slider + HUD + spiromètre ---- */
#slider-box { display: flex; align-items: center; gap: 10px; }
.sl-lbl { font-size: 12px; color: var(--muted); white-space: nowrap; }
#dia-slider {
  -webkit-appearance: none;
  width: 200px; height: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
#dia-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #082f49;
  cursor: grab;
}
#dia-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #082f49;
  cursor: grab;
}

#hud {
  position: absolute;
  top: 14px; left: 22px;
  display: flex; align-items: center; gap: 14px;
  pointer-events: none;
}
.phase {
  font-size: 15px; font-weight: 700;
  padding: 5px 14px; border-radius: 999px;
  border: 2px solid var(--border);
  background: rgba(30,41,59,.9);
}
.phase.in { color: var(--ok); border-color: var(--ok); }
.phase.out { color: #f87171; border-color: #f87171; }
.vol {
  font-size: 20px; font-weight: 700;
  color: var(--accent);
  background: rgba(30,41,59,.9);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 4px 12px;
  min-width: 100px; text-align: center;
}

/* flux d'air */
#scene .air-in  { stroke: var(--ok); }
#scene .air-out { stroke: #f87171; }
#scene .lbl { font-size: 12px; fill: #cbd5e1; }
#scene .lbl-dark { font-size: 12px; fill: #1e293b; }
#scene .eq { font-size: 11.5px; fill: var(--accent-2); font-style: italic; }

/* pouls lumineux du spiromètre */
#spiroDot { filter: drop-shadow(0 0 4px var(--accent)); }

/* ---- Circulation : légende + phases ---- */
.chip.static { cursor: default; display: inline-flex; align-items: center; gap: 7px; }
.chip .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.phase.in  { color: var(--accent-2); border-color: var(--accent-2); }
.phase.out { color: var(--accent);   border-color: var(--accent); }
#scene .lbl { font-size: 11.5px; fill: #cbd5e1; }
#scene .chamber { font-size: 13px; font-weight: 700; }

/* 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; }
