/* --- Nombres & mesures : bande du décalage de virgule --- */
.ns-band {
  position: relative;
  width: min(100%, calc(var(--n) * 2.75rem));
  margin: 0 auto 0.75rem;
  padding-bottom: 0.4rem;
  user-select: none;
}

.ns-band.is-interactive { cursor: pointer; }

.ns-band.is-interactive:focus-visible {
  outline: 3px solid var(--school-primary);
  outline-offset: 4px;
  border-radius: var(--school-radius-md);
}

.ns-cells {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  border: 2px solid var(--school-border);
  border-radius: var(--school-radius-md);
  background: var(--school-surface);
  overflow: hidden;
}

.ns-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--school-text);
}

.ns-cell + .ns-cell { border-left: 1px dashed var(--school-border); }

.ns-cell.is-ghost { background: color-mix(in srgb, var(--school-border) 18%, transparent); }

[data-bs-theme="dark"] .ns-cell.is-ghost { background: color-mix(in srgb, var(--school-border) 40%, transparent); }

.ns-cell.is-zero-added {
  color: var(--school-xp);
  background: color-mix(in srgb, var(--school-xp) 12%, var(--school-surface));
  animation: ns-zero-pop 0.25s ease both;
}

.ns-cell.is-zero-removed {
  color: var(--school-text-muted);
  text-decoration: line-through;
  opacity: 0.45;
}

/* Virgule : posée sur la frontière entre deux cases, elle glisse d'un rang à l'autre */
.ns-comma {
  position: absolute;
  bottom: -0.1rem;
  left: calc(var(--k) * 100% / var(--n));
  transform: translateX(-50%);
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--school-primary);
  pointer-events: none;
  transition: left 0.25s ease, opacity 0.2s ease;
}

/* Virgule « cachée » d'un nombre entier : visible, mais plus discrète */
.ns-comma.is-hidden { opacity: 0.5; }
.ns-comma.is-start { opacity: 0.25; color: var(--school-text-muted); }

.ns-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.ns-indicator {
  padding: 0.5rem 0.75rem;
  border-radius: var(--school-radius-md);
  background: color-mix(in srgb, var(--school-border) 20%, transparent);
  color: var(--school-text);
  font-size: 0.95rem;
}

.ns-indicator.is-multiply { background: var(--mm-teal-soft); }
.ns-indicator.is-multiply strong { color: var(--mm-teal); }
.ns-indicator.is-divide { background: color-mix(in srgb, var(--school-xp) 12%, transparent); }
.ns-indicator.is-divide strong { color: var(--school-xp); }

.ns-equation {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
}

/* --- Tableau de conversion : en-têtes d'unités au-dessus de la bande --- */
.cv-table {
  width: min(100%, calc(var(--n) * 3rem));
  margin: 0 auto 0.75rem;
}

.cv-table .ns-band { width: 100%; margin-bottom: 0; }

.cv-heads {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 2px;
  margin-bottom: 0.3rem;
}

.cv-head {
  padding: 0.4rem 0;
  border: 1px solid transparent;
  border-radius: var(--school-radius-md) var(--school-radius-md) 0 0;
  background: color-mix(in srgb, var(--school-border) 25%, transparent);
  color: var(--school-text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

.cv-head.is-base { font-weight: 800; }

button.cv-head {
  cursor: pointer;
  border-color: color-mix(in srgb, var(--school-primary) 40%, transparent);
  background: color-mix(in srgb, var(--school-primary) 10%, var(--school-surface));
}

button.cv-head:hover { background: color-mix(in srgb, var(--school-primary) 25%, var(--school-surface)); }

button.cv-head:focus-visible {
  outline: 3px solid var(--school-primary);
  outline-offset: 1px;
}

.cv-head.is-from { background: var(--mm-teal-soft); color: var(--mm-teal); box-shadow: inset 0 -3px 0 var(--mm-teal); }
.cv-head.is-to { background: color-mix(in srgb, var(--school-xp) 15%, transparent); color: var(--school-xp); box-shadow: inset 0 -3px 0 var(--school-xp); }

.cv-head.is-wrong {
  background: color-mix(in srgb, var(--bs-danger) 15%, transparent);
  color: var(--bs-danger);
  text-decoration: line-through;
}

.cv-number {
  margin-bottom: 0.5rem;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
}

.cv-step {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  text-align: center;
}

/* --- Fractions : calcul du corrigé, modèle d'aire et barres d'unités --- */
.fr-chain {
  font-size: 1.05rem;
  overflow-x: auto;
}

.fr-figure {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 0.5rem;
}

.fr-cell { fill: var(--school-surface); stroke: var(--school-border); stroke-width: 1; }
.fr-cell.is-col { fill: color-mix(in srgb, var(--mm-teal) 28%, var(--school-surface)); }
.fr-cell.is-row { fill: color-mix(in srgb, var(--school-xp) 28%, var(--school-surface)); }
.fr-cell.is-both { fill: var(--mm-teal); }
.fr-bar { fill: none; stroke: var(--school-text-muted); stroke-width: 2; }
.fr-num { fill: var(--school-text); font-size: 13px; font-weight: 700; }

.fr-caption {
  font-size: 0.9rem;
  text-align: center;
}

@keyframes ns-zero-pop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ns-comma { transition: none; }
  .ns-cell.is-zero-added { animation: none; }
}
