/* ==========================================================================
   142 — Todo Strike
   Checklist 100 % CSS (checkbox caché + :checked). Cocher : la case pop
   (overshoot) et se remplit d'accent, le check se dessine au stroke, puis
   le texte se barre PROGRESSIVEMENT de gauche à droite (pseudo-élément
   scaleX, origin left), grise, baisse d'opacité et glisse légèrement.
   Décocher : le trait se retire en sens inverse (droite → gauche), le
   check s'efface, le texte se rallume. Compteur « n / 4 terminées » en
   pur CSS : compteurs + :has(), affiché via content. Aucun JavaScript.
   ========================================================================== */

.todo-strike {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 260px;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--ml-surface, #151a24);
  border: 1px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 18%, transparent);
  /* ts-total compte les items, ts-done ceux qui sont cochés */
  counter-reset: ts-done 0 ts-total 0;
}

.todo-strike__title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ml-muted, #8b91a3);
}

/* --- Item ------------------------------------------------------------------ */

.todo-strike__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  counter-increment: ts-total;
}

/* Un item coché incrémente les deux compteurs (la seconde déclaration
   écraserait la première, d'où la liste combinée). */
.todo-strike__item:has(.todo-strike__input:checked) {
  counter-increment: ts-total ts-done;
}

.todo-strike__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* --- Case + check dessiné --------------------------------------------------- */

.todo-strike__box {
  position: relative;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 65%, transparent);
  color: var(--ml-bg, #0d1017); /* couleur du check (currentColor) */
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.todo-strike__item:hover .todo-strike__box {
  border-color: var(--ml-accent, #7c8cff);
}

.todo-strike__input:focus-visible ~ .todo-strike__box {
  outline: 2px solid var(--ml-accent, #7c8cff);
  outline-offset: 3px;
}

.todo-strike__input:checked ~ .todo-strike__box {
  background-color: var(--ml-accent, #7c8cff);
  border-color: var(--ml-accent, #7c8cff);
  animation: todo-strike-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes todo-strike-pop {
  0%   { transform: scale(0.82); }
  55%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.todo-strike__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.todo-strike__check {
  stroke-dasharray: 15;
  stroke-dashoffset: 15;
  transition: stroke-dashoffset 0.18s ease-in;
}

.todo-strike__input:checked ~ .todo-strike__box .todo-strike__check {
  stroke-dashoffset: 0;
  /* le check se dessine juste après le pop de la case */
  transition: stroke-dashoffset 0.25s cubic-bezier(0.65, 0, 0.35, 1) 0.1s;
}

/* --- Texte : barré progressif, grisé, léger slide ---------------------------- */

.todo-strike__text {
  position: relative;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ml-fg, #e8eaf2);
  transition:
    color 0.3s ease,
    opacity 0.3s ease,
    transform 0.3s ease;
}

/* Le trait : toujours ancré à gauche → il se dessine de gauche à droite
   au check (scaleX 0→1) et se retire de droite à gauche au uncheck (1→0). */
.todo-strike__text::after {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: calc(50% - 1px);
  height: 1.5px;
  border-radius: 1px;
  background: var(--ml-muted, #8b91a3);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.3s cubic-bezier(0.55, 0, 0.45, 1);
}

.todo-strike__input:checked ~ .todo-strike__text {
  color: var(--ml-muted, #8b91a3);
  opacity: 0.55;
  transform: translateX(3px);
  transition:
    color 0.35s ease 0.12s,
    opacity 0.35s ease 0.12s,
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1) 0.12s;
}

.todo-strike__input:checked ~ .todo-strike__text::after {
  transform: scaleX(1);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1) 0.12s;
}

/* --- Compteur (pur CSS : counters + :has) ----------------------------------- */

.todo-strike__count {
  margin: 10px 0 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ml-muted, #8b91a3);
}

.todo-strike__count::before {
  content: counter(ts-done) " / " counter(ts-total) " done";
}

/* Toutes cochées : le compteur passe à l'accent secondaire */
.todo-strike:not(:has(.todo-strike__input:not(:checked))) .todo-strike__count {
  color: var(--ml-accent-2, #2dd4bf);
}

/* --- Reduced motion ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .todo-strike__box,
  .todo-strike__check,
  .todo-strike__text,
  .todo-strike__text::after {
    transition: none;
    animation: none;
  }
  .todo-strike__input:checked ~ .todo-strike__box {
    animation: none;
  }
}
