/* ═══════════════════════ Djouney v3 — l'écriture qui se rejoue ═══════════════════════
   Module B (components/typing.js). Classes préfixées .ty-
   L'élément qui reçoit un rejeu garde sa propre typographie (main, couleur d'encre) :
   ces styles n'en fixent que la mise en scène. */

/* ─── Texte final et scène du rejeu ─── */
.ty-text,
.ty-ink,
.ty-sizer {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* La place finale est réservée dès le début (calque invisible) : la page ne saute pas. */
.ty-stage {
  display: grid;
  cursor: pointer;
}
.ty-stage > .ty-sizer,
.ty-stage > .ty-ink {
  grid-area: 1 / 1;
  min-width: 0;
}
.ty-sizer { visibility: hidden; }

/* ─── Lettres qui se posent ─── */
.ty-new { animation: ty-ink-in 380ms var(--ease) both; }
@keyframes ty-ink-in {
  from { opacity: 0; filter: blur(1.2px); }
}

/* ─── Ratures : un trait tiré à la main, visible un instant, puis l'encre se retire ─── */
.ty-del {
  text-decoration: none;
  opacity: .58;
  background: linear-gradient(currentColor, currentColor) no-repeat 0 60% / 100% 1.5px;
  animation:
    ty-strike 220ms var(--ease) both,
    ty-vanish 520ms ease-in 700ms forwards;
}
@keyframes ty-strike {
  from { background-size: 0 1.5px; }
}
@keyframes ty-vanish {
  55% { opacity: .18; font-size: 1em; }
  to { opacity: 0; font-size: 0; }
}

/* ─── Curseur : le seul élément qui clignote dans l'app, et doucement ───
   Inline vide (jamais inline-block) : il ne crée pas de point de coupure au milieu d'un mot
   et n'occupe aucune largeur ; le remplissage force une ligne après un retour à la ligne final. */
.ty-caret {
  position: relative;
  padding-left: 1px;
  margin-left: -1px;
}
.ty-caret::after {
  content: "";
  position: absolute;
  left: 0;
  top: .14em;
  bottom: .04em;
  width: 1.6px;
  border-radius: 1px;
  background: var(--flower, currentColor);
  animation: ty-blink 1.2s ease-in-out .55s infinite;
}
@keyframes ty-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .12; }
}

/* ─── « Afficher toute la lettre » : visible seulement au clavier ─── */
.ty-skip {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.ty-skip:focus-visible {
  position: static;
  display: flex;
  align-items: center;
  width: auto;
  height: auto;
  min-height: 44px;
  margin: 10px 0 0;
  padding: 0 16px;
  overflow: visible;
  clip: auto;
  border-radius: 999px;
  background: var(--milk);
  box-shadow: var(--emboss-sm);
  color: var(--ink); /* contraste ≥ 4,5:1 */
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  font-style: normal;
  letter-spacing: .2px;
}

/* ─── Brouillon de l'autre, en direct ─── */
.ty-live {
  padding: 4px 0 2px;
  transition: opacity var(--mid) var(--ease), transform var(--mid) var(--ease);
}
.ty-live:not([hidden]) { animation: ty-live-in var(--slow) var(--ease); }
.ty-live.is-leaving {
  opacity: 0;
  transform: translateY(4px);
}
@keyframes ty-live-in {
  from { opacity: 0; transform: translateY(6px); }
}

/* Encre fantôme : sépia à 70 %, les dernières lignes seulement si le brouillon est long. */
.ty-live-ink {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-height: calc(1.3em * 5);
  overflow: hidden;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 23px;
  line-height: 1.3;
  color: var(--sepia);
  color: color-mix(in srgb, var(--sepia) 70%, transparent);
  transition: opacity 900ms var(--ease);
}
.ty-live-ink > .ty-ink { flex: none; }
.ty-live-ink.is-long {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 1.3em);
  mask-image: linear-gradient(to bottom, transparent 0, #000 1.3em);
}
.ty-live.is-hesitating .ty-live-ink { opacity: .6; }
.ty-live.is-erased .ty-live-ink { opacity: .75; }

.ty-live-status {
  margin: 2px 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13.5px;
  line-height: 1.4;
  /* Encre adoucie mais lisible : contraste ≥ 4,5:1 sur la porcelaine comme sur le lait. */
  color: var(--ink);
  color: color-mix(in srgb, var(--ink) 84%, transparent);
}

/* ─── Mouvement réduit : plus de déplacement ni de trait tiré, seulement des fondus ─── */
@media (prefers-reduced-motion: reduce) {
  .ty-new,
  .ty-caret::after { animation: none; }
  .ty-del { animation: ty-fade-out 520ms ease-in 700ms forwards; }
  .ty-live:not([hidden]) { animation: ty-fade-in var(--mid) ease; }
  .ty-live { transition: opacity var(--mid) ease; }
  .ty-live.is-leaving { transform: none; }
  .ty-live-ink { transition: none; }
}
@keyframes ty-fade-in {
  from { opacity: 0; }
}
@keyframes ty-fade-out {
  to { opacity: 0; }
}
