/* Jeu : le tableau et le cahier */

/* Les couleurs des carreaux (plus fortes que le fond blanc d'un carreau vide) */
.tc-rouge, .tc__case.tc-rouge { background: var(--rouge); }
.tc-bleu, .tc__case.tc-bleu { background: var(--bleu); }
.tc-jaune, .tc__case.tc-jaune { background: var(--jaune); }
.tc-vert, .tc__case.tc-vert { background: var(--vert); }
.tc-violet, .tc__case.tc-violet { background: var(--violet); }
/* couleur fixe voulue : un brun moyen, lisible sur le carreau blanc du thème clair comme sur le carreau sombre
   (avec var(--encre), le tronc du sapin devenait blanc en thème sombre) */
.tc-encre, .tc__case.tc-encre { background: #9a6a3c; }

.tc__glyphe {
  display: grid;
  grid-template-columns: repeat(4, 0.9rem);
  gap: 2px;
}

.tc__glyphe span {
  aspect-ratio: 1;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px var(--trait);
}

.tc__tailles {
  justify-content: flex-start;
  justify-content: safe center;
}

.tc__etiquette {
  font-family: var(--police-titre);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--encre-2);
}

/* ---------- Le tableau : plus petit, comme vu du fond de la classe ---------- */

.tc__tableau {
  display: grid;
  justify-items: center;
  gap: var(--espace-2);
  width: min(100%, 15rem);
  padding: var(--espace-3);
  border-radius: var(--rayon);
  /* Un tableau gris ardoise : le vert pâle est réservé à « c'est juste » (code des couleurs, 22/10/2026) */
  background: color-mix(in srgb, var(--encre-2) 20%, var(--surface-2));
  box-shadow: inset 0 0 0 4px var(--bois-flanc);
}
@supports not (color: color-mix(in srgb, red 50%, blue)) { .tc__tableau { background: var(--surface-2); } }

.tc__tableau-tete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--espace-2);
  width: 100%;
}

.tc__replier {
  min-height: 40px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.tc__support {
  position: relative;
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  gap: 0.3rem;
  width: 100%;
}

.tc__tableau .tc__support { width: min(100%, 11rem); }
.tc__cahier .tc__support { width: min(100%, 20rem); }

/* ---------- Les grilles ---------- */

.tc__grille {
  --n: 6;
  --ligne: 0;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 2px;
  aspect-ratio: 1;
  padding: 2px;
  border-radius: 6px;
  background: var(--trait);
}

.tc__case {
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--surface);
  font: inherit;
}

.tc__grille--cahier {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tc__grille--cahier .tc__case { cursor: pointer; }
.tc__grille--cahier .tc__case:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* La lumière de la luciole : une bande douce sur sa ligne */
.tc__grille.a-une-luciole::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(2px + (100% - 4px) / var(--n) * var(--ligne) - 1px);
  height: calc((100% - 4px) / var(--n) + 2px);
  border-radius: 4px;
  box-shadow: 0 0 0 3px var(--jaune);
  pointer-events: none;
  transition: top 450ms ease;
}

.tc__grille.est-fini::after { box-shadow: none; }

/* Le rail, à gauche, où vit la luciole */
.tc__rail {
  position: relative;
  border-radius: 6px;
}

.tc__rail--cahier {
  cursor: pointer;
  background: var(--surface-2);
}

.tc__luciole {
  --ligne: 0;
  position: absolute;
  left: 0;
  width: 1.6rem;
  height: 1.6rem;
  top: calc((100% / var(--n)) * var(--ligne) + (100% / var(--n) - 1.6rem) / 2);
  transition: top 450ms ease;
  animation: tc-luciole 1.8s ease-in-out infinite;
  pointer-events: none;
}

.tc__luciole svg { display: block; width: 100%; height: 100%; }
.tc__luciole-halo { fill: var(--jaune); opacity: 0.35; }
.tc__luciole-aile { fill: var(--surface); stroke: var(--encre-2); stroke-width: 1; }
.tc__luciole-corps { fill: var(--jaune); stroke: var(--encre); stroke-width: 1.2; }

.tc__support { --n: inherit; }

@keyframes tc-luciole {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(2px); }
}

/* ---------- Le rideau (le tableau replié) ---------- */

.tc__rideau {
  position: absolute;
  inset: 0;
  display: none;
  align-content: center;
  justify-items: center;
  gap: var(--espace-2);
  padding: var(--espace-2);
  border-radius: 6px;
  background: var(--bois);
  color: var(--bois-encre);
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.tc__rideau p { margin: 0; }
.tc__tableau.est-replie .tc__rideau { display: grid; animation: tc-rideau 260ms ease-out; }

@keyframes tc-rideau {
  from { transform: scaleY(0.2); transform-origin: top; }
  to { transform: none; }
}

/* ---------- Le cahier ---------- */

.tc__cahier {
  display: grid;
  justify-items: center;
  gap: var(--espace-2);
  width: 100%;
}

.tc__case.est-juste { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--surface) 70%, transparent); }
/* Le code des couleurs (22/10/2026) : un carreau juste garde sa couleur de peinture et reçoit une coche
   sur une pastille vert pâle (le vert pâle ne peut pas remplacer la couleur du carreau) */
.tc__case.est-juste::after {
  content: '\2713';
  display: inline-grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  max-width: 80%;
  max-height: 80%;
  border-radius: 50%;
  background: var(--fn-juste);
  color: var(--fn-juste-texte);
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
}
.tc__case.est-a-revoir { animation: tc-a-revoir 1.4s ease-in-out infinite; }

@keyframes tc-a-revoir {
  0%, 100% { box-shadow: inset 0 0 0 0 var(--fn-piege); }
  50% { box-shadow: inset 0 0 0 4px var(--fn-piege), 0 0 0 2px var(--surface); }
}

/* ---------- La palette ---------- */

.tc__palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--espace-3);
}

.tc__pot {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 2px var(--trait);
  cursor: pointer;
}

.tc__pot[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 4px var(--encre); transform: scale(1.08); }

.tc__pot--gomme {
  display: grid;
  place-items: center;
  background: var(--surface-2);
}

.tc__gomme {
  width: 26px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--rouge) 0 40%, var(--surface) 40% 100%);
  box-shadow: inset 0 0 0 2px var(--encre-2);
  transform: rotate(-25deg);
}

.tc__phrase {
  max-width: 30rem;
  margin: 0;
  min-height: 2.8em;
  text-align: center;
  font-weight: 700;
}

/* ---------- La galerie des dessins finis ---------- */

.tc__galerie {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--espace-3);
}

.tc__mini {
  --n: 6;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: 3rem;
  aspect-ratio: 1;
  padding: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--trait);
  animation: tc-arrive 500ms cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes tc-arrive {
  from { transform: translateY(-24px) scale(0.5); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.tc__truc { display: grid; gap: var(--espace-4); width: 100%; max-width: 34rem; }

/* ---------- Le dessin fini s'anime ---------- */

.anime-saute { animation: tc-saute 700ms ease-in-out 3; }
.anime-tourne { animation: tc-tourne 900ms ease-in-out 2; }
.anime-decolle { animation: tc-decolle 1.6s ease-in-out; }
.anime-nage { animation: tc-nage 1s ease-in-out 3; }
.anime-danse { animation: tc-danse 600ms ease-in-out 4; }
.anime-balance { animation: tc-balance 1s ease-in-out 3; transform-origin: bottom center; }

@keyframes tc-saute { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10%); } }
@keyframes tc-tourne { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes tc-decolle { 0% { transform: translateY(0); } 60% { transform: translateY(-40%); opacity: 0.6; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes tc-nage { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(8%); } }
@keyframes tc-danse { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes tc-balance { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(4deg); } }

@media (prefers-reduced-motion: reduce) {
  .tc__luciole,
  .tc__case.est-a-revoir,
  .tc__mini,
  .anime-saute, .anime-tourne, .anime-decolle, .anime-nage, .anime-danse, .anime-balance { animation: none; }
  .tc__case.est-a-revoir { box-shadow: inset 0 0 0 4px var(--encre); }
}

/* La zone à toucher : la phrase, le tableau, le cahier, la palette et les boutons (essai du 22/10/2026) */
.tc__jeu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--espace-3);
  width: 100%;
}

/* Au téléphone, tout tient dans l'écran : le tableau et le cahier un peu plus petits */
@media (max-width: 520px) {
  .tc__tableau .tc__support { width: min(100%, 8.5rem); }
  .tc__cahier .tc__support { width: min(100%, 17rem); }
  .tc__phrase { font-size: 1rem; min-height: 0; }
}

/* Sur un grand écran, le tableau et le cahier côte à côte, comme en classe : tout tient sans défiler */
@media (min-width: 44rem) {
  .tc__jeu {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: center;
    justify-items: center;
    align-items: start;
    column-gap: var(--espace-6);
  }
  .tc__jeu > .tc__tableau { width: 15rem; }
  .tc__jeu > .tc__cahier { width: 20rem; }
  .tc__jeu > .tc__phrase,
  .tc__jeu > .tc__palette,
  .tc__jeu > .tc__actions {
    grid-column: 1 / -1;
  }
}
