: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 {
  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; }
a.nav-btn { text-decoration: none; display: inline-block; }

.layout { display: flex; flex: 1; min-height: 0; position: relative; }
#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;
  transition: transform .25s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,.45);
}
#sidebar.hidden { 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 {
  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; }
.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 ol { padding-left: 18px; }
.body li { margin: 3px 0; }
.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 { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

#controls {
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px 34px; flex-shrink: 0;
}
.step-title { display: flex; align-items: center; gap: 8px; font-size: 13px;
  font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.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: 6px; align-items: center; }
.chip {
  background: var(--panel-2); border: 2px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font-size: 13.5px; cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.selected { border-color: var(--accent); background: rgba(56,189,248,.15); }
.toggles { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tog {
  display: inline-flex; align-items: center; gap: 7px; font-size: 14px;
  cursor: pointer; user-select: none;
  padding: 5px 12px; border: 2px solid var(--border); border-radius: 999px;
  background: var(--panel-2);
}
.tog input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

#stage { flex: 1; position: relative; min-height: 0; padding: 10px 18px 12px; }
#scene {
  width: 100%; height: 100%; border-radius: 12px;
  touch-action: none; display: block;
}

#angle-label {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.85); color: #fde68a;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 18px; font-size: 16px; font-weight: 700;
  pointer-events: none;
}
#angle-label .deg { color: var(--accent); margin-left: 10px; }

#quiz-box {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 2px solid var(--accent-2);
  border-radius: 12px; padding: 8px 16px; font-size: 15px; font-weight: 600;
}
#quiz-box input {
  width: 80px; font-size: 18px; font-weight: 700; text-align: center;
  background: var(--panel-2); color: var(--text);
  border: 2px solid var(--border); border-radius: 8px; padding: 4px 6px;
}
#quiz-box input:focus { border-color: var(--accent); outline: none; }
#quiz-score { font-size: 14px; color: var(--accent); font-weight: 700; }

#feedback {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  border-radius: 10px; padding: 8px 16px; font-size: 15px; font-weight: 600;
  border: 2px solid var(--border); background: var(--panel); z-index: 5;
}
#feedback.ok { border-color: var(--ok); color: var(--ok); }
#feedback.ko { border-color: var(--ko); color: var(--ko); }
.hidden { display: none !important; }

/* ---- Éléments SVG ---- */
.ray { stroke: #1f2937; stroke-width: 3; stroke-linecap: round; }
.handle { fill: #dc2626; stroke: #fff; stroke-width: 2.5; cursor: grab; }
.handle:active { cursor: grabbing; }
.vertex { fill: #1f2937; stroke: #fff; stroke-width: 2.5; cursor: grab; }
.sector { fill: #22c55e; opacity: .35; }
.sector.rentrant { fill: #f97316; }
.arc-arrow { fill: none; stroke: #16a34a; stroke-width: 3; }
.arc-txt { font-size: 15px; font-weight: 700; fill: #15803d; }
.tool { cursor: grab; }
.tool-rot { cursor: crosshair; fill: #f59e0b; stroke: #fff; stroke-width: 2; }

/* ---- Droite numérique ---- */
.axis { stroke: #1f2937; stroke-width: 3; }
.tick { stroke: #334155; stroke-width: 2; }
.tick-minor { stroke: #94a3b8; stroke-width: 1.2; }
.tick-lbl { font-size: 17px; font-weight: 600; fill: #334155; }
.tick-lbl.neg { fill: #b91c1c; }
.marker { fill: #1e3a8a; cursor: default; }
.marker.placed { fill: #2563eb; cursor: pointer; }
.mark-lbl { font-size: 19px; font-weight: 800; fill: #fff; }
.bond { fill: none; stroke: #16a34a; stroke-width: 2.5; stroke-dasharray: 6 4; }
.bond-txt { font-size: 13px; font-weight: 700; fill: #15803d; }
#info {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.85); color: #fde68a;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 18px; font-size: 15px; font-weight: 700; pointer-events: none;
  white-space: nowrap;
}

/* ---- Surface et contour : cartes ---- */
#cards {
  flex: 1; display: grid;
  grid-template-columns: repeat(3, minmax(150px, 230px));
  grid-auto-rows: minmax(170px, 1fr);
  gap: 12px; justify-content: center; align-content: center;
  padding: 6px 10px 60px;
}
.card {
  background: #fff; border: 3px solid #f97316; border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.card svg { flex: 1; width: 100%; }
.card .cap {
  text-align: center; font-size: 14px; font-weight: 600;
  color: #334155; padding: 5px 4px; border-top: 1px solid #fed7aa;
}
.card.quiz { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(56,189,248,.25); }

.shape-fill { fill: rgba(251,146,60,.28); transition: fill .2s; }
.show-surface .shape-fill { fill: #fb923c; }
.shape-line { fill: none; stroke: #475569; stroke-width: 2.5; }
.show-contour .shape-line { stroke: #0f172a; stroke-width: 6; }
.side-hl { stroke-width: 8; fill: none; opacity: 0; transition: opacity .2s; }
.show-cotes .side-hl { opacity: 1; }
.vert { fill: #dc2626; stroke: #fff; stroke-width: 2.5; opacity: 0; transition: opacity .2s; }
.show-sommets .vert { opacity: 1; }
.diag { stroke: #7c3aed; stroke-width: 3.5; stroke-dasharray: 9 5; opacity: 0; transition: opacity .2s; }
.show-diag .diag { opacity: 1; }
.hit { fill: transparent; stroke: transparent; cursor: pointer; }

#quiz-score {
  position: absolute; bottom: 22px; right: 24px;
  background: var(--panel); border: 2px solid var(--accent);
  border-radius: 999px; padding: 6px 16px; font-weight: 700; color: var(--accent);
}

#stage {
  background-color: #f7fafc;
  background-image:
    linear-gradient(#e3eaf2 1px, transparent 1px),
    linear-gradient(90deg, #e3eaf2 1px, transparent 1px),
    linear-gradient(#b0bfd1 1.4px, transparent 1.4px),
    linear-gradient(90deg, #b0bfd1 1.4px, transparent 1.4px);
  background-size: 20px 20px, 20px 20px, 100px 100px, 100px 100px;
}

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