/* Multiplier & diviser par 10, 100, 1 000, 0,1… */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f4f6fb;
  color: #1f2937;
}
.hidden { display: none !important; }

header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #f97316, #db2777);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 280px; min-width: 0; }
.brand > div { min-width: 0; }
.brand .logo { font-size: 2rem; }
.brand h1 { margin: 0; font-size: 1.35rem; }
.brand .subtitle { margin: 0; font-size: .85rem; opacity: .92; overflow-wrap: anywhere; }
.nav-btn {
  background: rgba(255,255,255,.18); color: #fff;
  border: 1px solid rgba(255,255,255,.4); border-radius: 8px;
  padding: 6px 12px; font-size: .9rem; cursor: pointer; text-decoration: none;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.32); }
nav { display: flex; gap: 8px; }

.layout { display: flex; min-height: calc(100vh - 60px); }

/* ---- Sidebar activités ---- */
#sidebar {
  width: 320px; flex-shrink: 0;
  background: #fff; border-right: 1px solid #e5e7eb;
  padding: 14px; overflow-y: auto;
}
.sidebar-head h2 { margin: 0 0 4px; font-size: 1.1rem; }
.sidebar-head .hint { margin: 0 0 10px; font-size: .85rem; color: #6b7280; }
.activity { border: 1px solid #e5e7eb; border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.activity .head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px;
  background: #f8fafc; border: none; cursor: pointer; font-size: .92rem; text-align: left;
}
.activity .head:hover { background: #fff1e6; }
.activity .tp-num { background: #ea580c; color: #fff; border-radius: 6px; padding: 2px 6px; font-size: .75rem; font-weight: 700; }
.activity .tp-title { flex: 1; font-weight: 600; }
.activity .tp-level { font-size: .75rem; color: #6b7280; white-space: nowrap; }
.activity .body { display: none; padding: 10px 12px; font-size: .88rem; border-top: 1px solid #e5e7eb; }
.activity.open .body { display: block; }
.activity .body h3 { font-size: .8rem; text-transform: uppercase; color: #ea580c; margin: 10px 0 4px; }
.activity .body ol { margin: 4px 0; padding-left: 20px; }
.activity .body li { margin-bottom: 3px; }
.activity .question { background: #fff7ed; border-left: 3px solid #f97316; padding: 5px 8px; margin: 5px 0; border-radius: 0 6px 6px 0; }
.prof-note { background: #fffbeb; border-left: 3px solid #f59e0b; padding: 6px 8px; margin-top: 8px; border-radius: 0 6px 6px 0; }
.prof-note h3 { color: #b45309 !important; }

/* ---- Zone principale ---- */
#main { flex: 1; padding: 16px; min-width: 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  border: 2px solid #fed7aa; background: #fff; color: #9a3412;
  border-radius: 10px; padding: 8px 16px; font-weight: 700; font-size: .95rem; cursor: pointer;
}
.tab.active { background: #ea580c; border-color: #ea580c; color: #fff; }

#controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; align-items: stretch; }
.step { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 14px; }
.step.go { display: flex; align-items: center; gap: 8px; }
.step-title { font-weight: 600; font-size: .85rem; margin-bottom: 8px; color: #374151; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: #ea580c; color: #fff; font-size: .75rem; margin-right: 4px;
}
#num {
  font-size: 1.4rem; font-weight: 700; width: 170px; padding: 6px 10px;
  border: 2px solid #fdba74; border-radius: 8px; color: #1f2937;
}
#num:focus, #q-answer:focus { outline: none; border-color: #ea580c; box-shadow: 0 0 0 3px rgba(234,88,12,.2); }
#num.bad { border-color: #dc2626; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.small { margin-top: 6px; }
.chips.center { justify-content: center; margin: 10px 0; }
.chip {
  border: 1px solid #d1d5db; background: #f9fafb; color: #1f2937;
  border-radius: 999px; padding: 6px 12px; font-size: .95rem; font-weight: 600; cursor: pointer;
}
.chips.small .chip { padding: 2px 9px; font-size: .8rem; font-weight: 500; }
.chip:hover { border-color: #ea580c; }
.chip.active { background: #ea580c; border-color: #ea580c; color: #fff; }

.btn {
  border: none; background: #ea580c; color: #fff;
  padding: 10px 20px; border-radius: 10px; font-size: 1rem; font-weight: 700; cursor: pointer;
}
.btn:hover { background: #c2410c; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #ffedd5; color: #9a3412; }
.btn.ghost:hover { background: #fed7aa; }

/* ---- Tableau de numération ---- */
#stage { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px; }
#equation { text-align: center; font-size: 1.7rem; font-weight: 700; min-height: 2.4rem; margin-bottom: 10px; }
#equation .op { color: #db2777; }
#equation .res { color: #16a34a; }
#equation .q { color: #9ca3af; }
#table-wrap { overflow-x: auto; padding-bottom: 4px; }

.pv { --n: 9; min-width: calc(var(--n) * 46px); max-width: calc(var(--n) * 78px); margin: 0 auto; user-select: none; }
.pv-row { display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.pv-head .cell {
  text-align: center; padding: 4px 2px; border: 1px solid #e5e7eb; border-bottom: none;
  background: #f8fafc; line-height: 1.1;
}
.pv-head .cell b { display: block; font-size: 1.05rem; }
.pv-head .cell small { display: block; font-size: .62rem; color: #6b7280; min-height: 1.5em; }
.pv-head .cell.int { background: #eff6ff; }
.pv-head .cell.dec { background: #fdf2f8; }
.pv-head .cell.unit { background: #dbeafe; }
.pv-body { position: relative; height: 74px; }
.pv-body .cell { border: 1px solid #e5e7eb; height: 74px; }
.pv-body .cell.unit { background: #eff6ff; }
.pv-body .cell.k3 { border-left: 2px solid #9ca3af; }

.pv-comma {
  position: absolute; bottom: 6px; width: 0; z-index: 3;
  font-size: 2.6rem; font-weight: 900; color: #dc2626; line-height: 1;
}
.pv-comma span { position: absolute; left: -7px; bottom: 0; }

.tok {
  position: absolute; top: 0; height: 74px; z-index: 2;
  width: calc(100% / var(--n));
  left: calc(var(--i) * 100% / var(--n));
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: 800; color: #1e3a8a;
  transition: left .55s cubic-bezier(.45,.05,.3,1), opacity .35s;
}
.tok.zero { color: #9ca3af; }
.tok.zero.new { color: #ea580c; animation: pop .4s ease; }
.tok.gone { opacity: 0; }
.tok.moving { color: #db2777; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

.pv-arrow { text-align: center; font-size: 1.1rem; font-weight: 700; color: #db2777; min-height: 1.6rem; margin-top: 6px; }
#steps-info { text-align: center; font-weight: 600; color: #6b7280; min-height: 1.4rem; margin-top: 4px; }

.explain { margin-top: 12px; }
.explain p {
  margin: 6px 0; padding: 8px 12px; border-radius: 8px;
  background: #fff7ed; border-left: 4px solid #f97316;
}
.explain p.same { background: #f0fdf4; border-left-color: #16a34a; }
.explain p.warn { background: #fef2f2; border-left-color: #dc2626; }
.explain p.err { background: #fef2f2; border-left-color: #dc2626; color: #991b1b; }

.aide { margin-top: 14px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 16px; }
.aide h3 { margin: 4px 0 6px; font-size: 1rem; }
.aide ul { margin: 0; padding-left: 20px; }
.aide li { margin-bottom: 4px; }
.z-demo { color: #ea580c; font-weight: 800; }

/* ---- Entraînement ---- */
.card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 14px;
  padding: 20px; max-width: 720px; margin: 0 auto 14px; text-align: center;
}
.card h2 { margin-top: 0; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 12px 0 18px; }
.level {
  border: 2px solid #e5e7eb; background: #f9fafb; border-radius: 12px;
  padding: 12px; cursor: pointer; font-weight: 700; font-size: .95rem; color: #1f2937;
}
.level small { display: block; font-weight: 500; color: #6b7280; margin-top: 4px; }
.level:hover { border-color: #f97316; }
.level.active { border-color: #ea580c; background: #fff7ed; }
.hud { display: flex; justify-content: space-between; font-weight: 700; color: #6b7280; }
.hud b { color: #ea580c; }
.q-text { font-size: 2rem; font-weight: 800; margin: 18px 0; }
.q-text .op { color: #db2777; }
.q-text .blank { display: inline-block; min-width: 2.2em; border-bottom: 3px dashed #ea580c; color: #ea580c; }
#q-form { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#q-answer {
  font-size: 1.5rem; font-weight: 700; width: 220px; padding: 8px 12px; text-align: center;
  border: 2px solid #fdba74; border-radius: 10px;
}
.feedback { min-height: 2.6rem; margin: 12px 0 6px; font-size: 1.1rem; font-weight: 600; }
.feedback.ok { color: #16a34a; }
.feedback.ko { color: #dc2626; }
.feedback small { display: block; font-weight: 500; color: #6b7280; margin-top: 4px; }
.center { text-align: center; }
.center .btn { margin: 4px; }
.stars { font-size: 3rem; }
#end-text { font-size: 1.2rem; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  #sidebar { width: 100%; border-right: none; border-bottom: 1px solid #e5e7eb; max-height: 45vh; }
  .brand h1 { font-size: 1.1rem; }
  .tok { font-size: 1.6rem; }
  #equation { font-size: 1.3rem; }
  .q-text { font-size: 1.5rem; }
}
