/* Tapil, la main à essayer. Composant autonome : il lit les variables de systeme.css quand elles existent, et porte ses valeurs sinon.
   Il se pose sur un fond bleu (.sur-bleu) ou sur le papier. Tout se règle par les variables --tm-*. */
.tm {
  --tm-papier: var(--papier, #FBF5E9); --tm-nuit: var(--nuit, #2C2A5E); --tm-aplat: var(--aplat, #292B59); --tm-orange: var(--orange, #E17A2F);
  --tm-encre: var(--encre, #2C2A5E); --tm-encre-douce: var(--encre-douce, #55537D);
  --tm-titre: var(--titre, "Anybody", "Arial Narrow", Arial, sans-serif); --tm-texte: var(--texte, "Archivo", Arial, sans-serif);
  --tm-duree: var(--duree, 220ms);
  --tm-jeton: 2.75rem;            /* zone à toucher du signe : 44 px */
  --tm-disque: 1.875rem;          /* le disque qu'on voit : 30 px sur téléphone */
  --tm-col: 2.375rem;             /* place laissée au signe entre deux cartes : le disque et son cerne y tiennent en entier, ils ne recouvrent aucune carte */
  container-type: inline-size; width: 100%; max-width: 46rem; margin-inline: auto; color: var(--tm-encre); font-family: var(--tm-texte);
}
.tm * { box-sizing: border-box; }
:where(.tm) p { max-width: none; margin: 0; }
.tm-consigne { margin: 0 0 1.5rem; font-size: 1.0625rem; line-height: 1.4; color: var(--tm-encre); text-align: center; text-wrap: balance; }

/* La rangée : carte, signe, carte, signe, carte, signe, carte cachée. Dans l'ordre, de gauche à droite. */
.tm-rangee, .tm-legende { display: grid; grid-template-columns: 1fr var(--tm-col) 1fr var(--tm-col) 1fr var(--tm-col) 1fr; padding-right: 0.5rem; }
.tm-rangee { align-items: center; }
.tm-carte { position: relative; margin: 0; }
.tm-carte picture { display: block; }
.tm-carte img { display: block; width: 100%; height: auto; aspect-ratio: 673 / 1039; border-radius: 5.3% / 3.4%; }
.tm-face { position: relative; box-shadow: 0 0.1875rem 0 var(--tm-aplat); }
/* La carte cachée : sa face, et son dos qui dépasse derrière elle, comme au dos de la boîte. */
.tm-dos { position: absolute; inset: 0; transform: translate(9%, -5%) rotate(7deg); transform-origin: 50% 100%; box-shadow: 0 0.1875rem 0 var(--tm-aplat); }

/* Le signe : un jeton de papier qui s'enfonce. La zone à toucher fait 44 px, le disque un peu moins sur téléphone. */
.tm-signe {
  position: relative; z-index: 2; justify-self: center; width: var(--tm-jeton); height: var(--tm-jeton); margin-inline: calc((var(--tm-col) - var(--tm-jeton)) / 2);
  padding: 0; border: 0; background: none; color: var(--tm-nuit); cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; border-radius: 50%;
}
.tm-signe::before {
  content: ""; position: absolute; inset: calc((var(--tm-jeton) - var(--tm-disque)) / 2); border-radius: 50%; background: var(--tm-papier);
  box-shadow: 0 0 0 0.125rem var(--tm-nuit), 0 0.1875rem 0 0.125rem var(--tm-aplat); transition: transform var(--tm-duree), box-shadow var(--tm-duree);
}
.tm-signe svg { position: absolute; inset: 0; margin: auto; width: 0.9375rem; height: 0.9375rem; transition: transform var(--tm-duree); }
.tm-signe:active::before, .tm-signe.tm-appui::before { transform: translateY(0.125rem); box-shadow: 0 0 0 0.125rem var(--tm-nuit), 0 0.0625rem 0 0.125rem var(--tm-aplat); }
.tm-signe:active svg, .tm-signe.tm-appui svg { transform: translateY(0.125rem); }
.tm-signe:focus-visible { outline: 0.1875rem solid var(--tm-orange); outline-offset: -0.25rem; }
.sur-bleu .tm-signe:focus-visible { outline-color: var(--tm-papier); }

/* Sous la rangée : un trait sous les 3 cartes visibles, un trait orange sous la carte cachée, et leurs noms sur une même ligne.
   L'orange ne sert qu'à la carte cachée. */
.tm-legende { margin-top: 0.75rem; row-gap: 0.375rem; font-size: 1rem; line-height: 1.25; }
.tm-trait { grid-row: 1; height: 0.125rem; background: currentColor; }
.tm-trait--visibles { grid-column: 1 / 6; }
.tm-trait--cachee { grid-column: 7; height: 0.25rem; margin-top: -0.0625rem; background: var(--tm-orange); }
.tm-visibles, .tm-cachee { grid-row: 2; white-space: nowrap; }
.tm-visibles { grid-column: 1 / 6; justify-self: start; }
.tm-cachee { grid-column: 5 / 8; justify-self: end; }

/* Le calcul complet, avec ses parenthèses quand la carte cachée multiplie. */
.tm-calcul {
  display: flex; align-items: center; justify-content: center; gap: 0.3em; margin-top: 1.125rem; min-height: 2rem;
  font: 800 clamp(1.5rem, 7cqi, 2.25rem)/1 var(--tm-titre); font-variant-numeric: lining-nums; white-space: nowrap; color: var(--tm-encre);
}
.tm-calcul svg { width: 0.5em; height: 0.5em; flex: none; }
.tm-par { margin-inline: -0.08em; font-weight: 600; }
/* La ligne qui s'ajoute quand on multiplie. Sa place est réservée : rien ne bouge dans la page. */
.tm-multiplie { margin-top: 0.625rem; min-height: 2.875rem; font-size: 1rem; line-height: 1.4; text-align: center; text-wrap: balance; visibility: hidden; }
.tm.tm-fois .tm-multiplie { visibility: visible; }

/* Le résultat dans son carré de papier, et l'écart à la cible la plus proche. L'écart n'est pas un bouton : ni fond, ni relief. */
.tm-ligne-resultat { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-top: 0.75rem; font-size: 1.0625rem; line-height: 1.2; white-space: nowrap; }
.tm-resultat {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.9em; padding: 0.2em 0.3em 0.18em; border-radius: 0.2em;
  font: 800 clamp(1.875rem, 9cqi, 3rem)/1 var(--tm-titre); font-variant-numeric: lining-nums;
  background: var(--tm-papier); color: var(--tm-nuit); box-shadow: 0 0.1em 0 var(--tm-aplat), 0 0 0 0.125rem var(--tm-nuit);
}
.tm-ecart { font-weight: 600; }
.tm-ecart.tm-vide { visibility: hidden; }

/* Le pied : une nouvelle main, puis les deux lignes du Tapil. Leur place est réservée sous le bouton : rien ne bouge. */
.tm-pied { display: grid; justify-items: center; gap: 1rem; margin-top: 0.75rem; }
.tm-tapil-mots { min-height: 5.75rem; font-size: 1.0625rem; line-height: 1.35; text-align: center; opacity: 0; transform: translateY(-0.375rem); }
.tm-l { display: block; text-wrap: balance; }
.tm-l:first-child { font-weight: 600; }
.tm.tm-tapil .tm-tapil-mots { opacity: 1; transform: none; transition: opacity 200ms 120ms, transform 260ms 120ms cubic-bezier(.2, 1.2, .4, 1); }
.tm.tm-tapil .tm-face { animation: tm-saut 420ms cubic-bezier(.3, 0, .3, 1) both; }
.tm.tm-tapil .tm-carte:nth-of-type(2) .tm-face { animation-delay: 70ms; }
.tm.tm-tapil .tm-carte:nth-of-type(3) .tm-face { animation-delay: 140ms; }
.tm.tm-tapil .tm-carte:nth-of-type(4) .tm-face { animation-delay: 210ms; }
.tm.tm-tapil .tm-resultat { animation: tm-coup 320ms cubic-bezier(.3, 0, .3, 1) both; }
@keyframes tm-saut { 40% { transform: translateY(-0.5rem); } 100% { transform: none; } }
@keyframes tm-coup { 40% { transform: scale(1.14); } 100% { transform: none; } }
/* Une nouvelle main : les cartes se posent l'une après l'autre. */
.tm.tm-arrive .tm-carte { animation: tm-pose 240ms ease-out both; }
.tm.tm-arrive .tm-carte:nth-of-type(2) { animation-delay: 50ms; }
.tm.tm-arrive .tm-carte:nth-of-type(3) { animation-delay: 100ms; }
.tm.tm-arrive .tm-carte:nth-of-type(4) { animation-delay: 150ms; }
@keyframes tm-pose { from { opacity: 0; transform: translateY(-0.625rem); } to { opacity: 1; transform: none; } }

.tm-bouton {
  display: inline-flex; align-items: center; justify-content: center; min-height: 3rem; padding: 0 1.5rem; border: 0; border-radius: var(--rayon, 0.625rem);
  font: 800 1.125rem/1 var(--tm-titre); white-space: nowrap; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  background: transparent; color: var(--tm-encre); box-shadow: inset 0 0 0 0.125rem var(--tm-encre); transition: transform var(--tm-duree), box-shadow var(--tm-duree), background-color var(--tm-duree), color var(--tm-duree);
}
.tm-bouton:active { transform: translateY(0.125rem); }
.tm-bouton:focus-visible { outline: 0.1875rem solid var(--tm-orange); outline-offset: 0.1875rem; }
.sur-bleu .tm-bouton:focus-visible { outline-color: var(--tm-papier); }
/* Après un Tapil, le bouton devient le bouton plein. */
.tm.tm-tapil .tm-bouton { background: var(--plein, #2D4291); color: var(--sur-plein, #FBF5E9); box-shadow: 0 0.25rem 0 var(--tm-aplat); }
.tm.tm-tapil .tm-bouton:active { transform: translateY(0.1875rem); box-shadow: 0 0.0625rem 0 var(--tm-aplat); }
.tm-vocal { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Dès qu'il y a la place : les jetons grandissent, les textes aussi, et les lignes ne passent plus à la ligne. */
@container (min-width: 30rem) {
  .tm > * { --tm-col: 4rem; --tm-jeton: 3.25rem; --tm-disque: 3.25rem; }   /* un conteneur ne se règle pas lui-même : on règle ses enfants */
  .tm-signe svg { width: 1.375rem; height: 1.375rem; }
  .tm-signe::before { box-shadow: 0 0 0 0.125rem var(--tm-nuit), 0 0.25rem 0 0.125rem var(--tm-aplat); }
  .tm-rangee, .tm-legende { padding-right: 0.75rem; }
  .tm-consigne { font-size: 1.1875rem; margin-bottom: 2.25rem; }
  .tm-legende { font-size: 1.125rem; margin-top: 1rem; }
  .tm-visibles { justify-self: center; } .tm-cachee { grid-column: 7; justify-self: center; }
  .tm-calcul { margin-top: 1.75rem; }
  .tm-multiplie { min-height: 1.75rem; font-size: 1.125rem; }
  .tm-ligne-resultat { margin-top: 1rem; font-size: 1.25rem; gap: 1rem; }
  .tm-pied { margin-top: 1rem; }
  .tm-tapil-mots { min-height: 3.5rem; font-size: 1.1875rem; }
}
/* Petits téléphones (375 x 548) : la main, son résultat et les deux lignes du Tapil tiennent entre l'en-tête et la barre du bas. */
@media (max-height: 36rem) and (max-width: 30rem) {
  .tm-legende { margin-top: 0.5rem; } .tm-calcul { margin-top: 0.75rem; } .tm-ligne-resultat { margin-top: 0.5rem; } .tm-multiplie { margin-top: 0.375rem; line-height: 1.3; min-height: 2.625rem; }
  .tm-pied { margin-top: 0.375rem; gap: 0.625rem; } .tm-bouton { min-height: 2.75rem; } .tm-tapil-mots { font-size: 1rem; line-height: 1.3; }
}
@media (prefers-reduced-motion: reduce) {
  .tm *, .tm *::before { animation: none !important; transition: none !important; }
}
