/* Division euclidienne en images */
* { 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; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 18px; color: #fff; background: linear-gradient(135deg, #0f766e, #2563eb);
}
.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 { display: flex; gap: 8px; }
.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: inherit; font-size: .9rem; cursor: pointer; text-decoration: none;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.32); }

.layout { display: flex; min-height: calc(100vh - 60px); }
#sidebar { width: 330px; flex: 0 0 330px; 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 { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; background: #f0fdfa; border: 0; cursor: pointer; text-align: left; font: inherit; font-size: .9rem; }
.activity .head:hover { background: #ccfbf1; }
.activity .tp-num { background: #0f766e; 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: #0f766e; margin: 10px 0 4px; }
.activity .body ol { margin: 4px 0; padding-left: 20px; }
.activity .body li { margin-bottom: 3px; }
.activity .question { background: #f0fdfa; border-left: 3px solid #14b8a6; padding: 5px 8px; margin: 5px 0; border-radius: 0 6px 6px 0; }
.activity .prof-note { background: #fefce8; border: 1px solid #fde68a; border-radius: 8px; padding: 4px 10px 8px; margin-top: 10px; }

#main { flex: 1; min-width: 0; padding: 16px; max-width: 1150px; margin: 0 auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab { border: 2px solid #99f6e4; background: #fff; color: #115e59; border-radius: 999px; padding: 8px 16px; font: inherit; font-weight: 700; cursor: pointer; }
.tab.active { background: #0f766e; border-color: #0f766e; color: #fff; }
.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.center { justify-content: center; }
.spacer { flex: 1; }
.lbl, .ctrl label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.tag { display: inline-block; min-width: 1.4em; text-align: center; border-radius: 6px; color: #fff; font-style: italic; padding: 0 4px; }
.tag-a { background: #2563eb; } .tag-b { background: #9333ea; }

.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper input { width: 80px; text-align: center; font-size: 1.4rem; font-weight: 800; border: 2px solid #cbd5e1; border-radius: 10px; padding: 4px; color: #0f172a; }
.stepper input:focus { outline: none; border-color: #0f766e; }
.sbtn { width: 38px; height: 38px; border-radius: 10px; border: 2px solid #99f6e4; background: #f0fdfa; color: #0f766e; font-size: 1.3rem; font-weight: 800; cursor: pointer; }
.sbtn:hover { background: #ccfbf1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid #cbd5e1; background: #fff; border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .9rem; cursor: pointer; color: #334155; }
.chip.active { border-color: #0f766e; background: #ccfbf1; color: #115e59; font-weight: 700; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.btn { background: #0f766e; color: #fff; border: 2px solid #0f766e; border-radius: 10px; padding: 8px 16px; font: inherit; font-weight: 700; cursor: pointer; }
.btn:hover { background: #115e59; }
.btn.ghost { background: #fff; color: #115e59; border-color: #99f6e4; }
.btn.ghost:hover { background: #f0fdfa; }
.btn:disabled { opacity: .5; cursor: default; }
.speed { margin-left: auto; font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 6px; }

.question-line { font-size: 1.15rem; font-weight: 600; text-align: center; margin: 4px 0 10px; color: #0f172a; }
.question-line b { color: #2563eb; }
.question-line i { color: #9333ea; font-style: normal; font-weight: 800; }

.stage { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 16px; align-items: start; }
.zone-title { font-weight: 700; color: #475569; margin-bottom: 8px; font-size: .95rem; }
.pool {
  --tok: 30px; min-height: 120px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px;
  padding: 10px; border: 2px dashed #cbd5e1; border-radius: 14px; background: #f8fafc;
}
.pool.is-rest { border-color: #f97316; background: #fff7ed; }
.boxes { --tok: 30px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; min-height: 120px; }
.box {
  min-width: calc(var(--tok) * 3 + 26px); max-width: calc(var(--tok) * 5 + 34px); flex: 0 1 auto;
  border: 3px solid #9333ea; border-radius: 14px; background: #faf5ff; padding: 6px; transition: box-shadow .3s, border-color .3s;
}
.box.pack { border-color: #0f766e; background: #f0fdfa; }
.box.flash { box-shadow: 0 0 0 4px rgba(250, 204, 21, .7); }
.box-head { font-size: .8rem; font-weight: 700; color: #6b21a8; text-align: center; margin-bottom: 4px; white-space: nowrap; }
.box.pack .box-head { color: #115e59; }
.box-in { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; min-height: var(--tok); }
.box-count { text-align: center; font-weight: 800; color: #6b21a8; font-size: .95rem; margin-top: 4px; }
.box.pack .box-count { color: #115e59; }

.tok {
  width: var(--tok); height: var(--tok); display: inline-flex; align-items: center; justify-content: center;
  font-size: calc(var(--tok) * .78); line-height: 1; user-select: none; will-change: transform; border-radius: 50%;
}
.tok.dot { background: radial-gradient(circle at 35% 35%, #93c5fd, #2563eb); }
.tok.rest { animation: pulse 1.2s ease-in-out 2; filter: drop-shadow(0 0 3px #f97316); }
@keyframes pulse { 50% { transform: scale(1.25); } }

.result { text-align: center; }
.counters { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-bottom: 10px; }
.counter { min-width: 150px; border-radius: 14px; padding: 8px 14px; display: flex; flex-direction: column; align-items: center; }
.c-q { background: #f3e8ff; color: #6b21a8; } .c-r { background: #ffedd5; color: #9a3412; }
.counter .cl { font-weight: 700; font-size: .9rem; }
.counter .cv { font-size: 2.2rem; font-weight: 900; line-height: 1.1; }
.counter .cn { font-size: .8rem; opacity: .85; }
.equation { font-size: clamp(1.3rem, 3.4vw, 2rem); font-weight: 800; margin: 6px 0; min-height: 1.5em; }
.equation .a { color: #2563eb; } .equation .b { color: #9333ea; } .equation .q { color: #7c3aed; text-decoration: underline; } .equation .r { color: #ea580c; }
.explain { color: #334155; max-width: 760px; margin: 0 auto; line-height: 1.5; min-height: 1.5em; }
.explain .ok { color: #15803d; font-weight: 700; display: inline-block; }
.posed {
  display: inline-grid; grid-template-columns: auto auto; margin: 14px auto 2px; font-family: "Courier New", monospace;
  font-size: 1.5rem; font-weight: 700; text-align: right;
}
.posed > div { padding: 2px 12px; }
.posed .p-b { border-left: 3px solid #0f172a; border-bottom: 3px solid #0f172a; text-align: left; color: #9333ea; }
.posed .p-a { color: #2563eb; } .posed .p-q { border-left: 3px solid #0f172a; text-align: left; color: #7c3aed; }
.posed .p-sub { color: #64748b; border-bottom: 2px solid #94a3b8; } .posed .p-r { color: #ea580c; }

/* entraînement */
.train-card { text-align: center; }
.t-story { font-size: 1.1rem; color: #334155; max-width: 720px; margin: 4px auto 8px; }
.t-op { font-size: 2.4rem; font-weight: 900; margin: 6px 0 12px; }
.t-op .a { color: #2563eb; } .t-op .b { color: #9333ea; }
.t-inputs { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 14px; margin-bottom: 10px; }
.t-inputs label { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.t-inputs input { width: 80px; font-size: 1.5rem; font-weight: 800; text-align: center; border: 2px solid #cbd5e1; border-radius: 10px; padding: 4px; }
.t-inputs input:focus { outline: none; border-color: #0f766e; }
.t-feed { min-height: 3em; font-weight: 600; margin-bottom: 10px; }
.t-feed.good { color: #15803d; } .t-feed.bad { color: #b91c1c; }
.streak { font-weight: 600; color: #475569; }
.aide h3 { margin: 0 0 6px; font-size: 1rem; }
.aide ul { margin: 0; padding-left: 20px; line-height: 1.6; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  #sidebar { width: 100%; flex: none; border-right: none; border-bottom: 1px solid #e5e7eb; max-height: 45vh; }
  .brand h1 { font-size: 1.1rem; }
  #main { padding: 10px; }
  .stage { grid-template-columns: 1fr; }
  .speed { margin-left: 0; }
}
#sidebar.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { .tok.rest { animation: none; } }
