/* 043-typewriter — machine à écrire CSS pure : steps(), curseur, boucle écrire/effacer */

.typewriter {
  /* Options — --typewriter-chars DOIT correspondre au nombre de caractères du texte */
  --typewriter-chars: 22;
  --typewriter-duration: 7s;

  display: inline-flex;
  flex-direction: column;
  min-width: 15rem;
  max-width: 100%;
  background: var(--ml-surface, #151a24);
  border: 1px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 22%, transparent);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 34px -18px rgba(0, 0, 0, 0.7);
}

/* Barre de fenêtre façon terminal */
.typewriter__bar {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 16%, transparent);
}

.typewriter__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ml-muted, #8b91a3) 45%, transparent);
}

.typewriter__dot--accent {
  background: var(--ml-accent, #7c8cff);
  opacity: 0.75;
}

.typewriter__body {
  display: flex;
  align-items: baseline;
  gap: 0.55ch;
  padding: 1.05rem 1.15rem 1.15rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
}

.typewriter__prompt {
  color: var(--ml-accent-2, #2dd4bf);
  user-select: none;
}

.typewriter__line {
  display: inline-block;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: content-box; /* le curseur (border) ne mange pas les caractères */
  width: calc(var(--typewriter-chars, 22) * 1ch);
  color: var(--ml-fg, #e8eaf2);
  border-right: 2px solid var(--ml-accent, #7c8cff);
  /* steps(var(...)) est posé ici (et non dans les keyframes) : les var()
     ne se résolvent pas dans les timing-functions de @keyframes. Les
     segments de maintien (46→70 %, 92→100 %) gardent la même valeur,
     le steps() n'y a donc aucun effet visuel. */
  animation:
    typewriter-typing var(--typewriter-duration, 7s) steps(var(--typewriter-chars, 22)) infinite,
    typewriter-caret 0.85s step-end infinite;
}

/* Écrire (steps) → tenir → effacer (steps) → pause */
@keyframes typewriter-typing {
  0%,
  4% {
    width: 0;
  }
  46% {
    width: calc(var(--typewriter-chars, 22) * 1ch);
  }
  70% {
    width: calc(var(--typewriter-chars, 22) * 1ch);
  }
  92%,
  100% {
    width: 0;
  }
}

@keyframes typewriter-caret {
  0%,
  100% {
    border-right-color: var(--ml-accent, #7c8cff);
  }
  50% {
    border-right-color: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typewriter__line {
    animation: none;
    width: auto;
    /* curseur fixe, non clignotant */
    border-right-color: var(--ml-accent, #7c8cff);
  }
}
