/* ==========================================================================
   EvoluAI — jogo "Tokenização" (nlp-01). Classes prefixadas com "tk-".
   Estética pixel art: cantos retos, bordas de 2px, sombra dura, cores chapadas.
   ========================================================================== */

.tk {
  --tk-shadow: 2px 2px 0 rgba(0, 0, 0, 0.55);
  --tk-c0: #5b9bff; /* water */
  --tk-c1: #ff7ab6; /* pink */
  --tk-c2: #ffd23f; /* coin */
  --tk-c3: #ff8c2e; /* orange */
  --tk-c4: #8b5cf6; /* purple */
  --tk-lime: #c8f53c;
  --tk-lime-dk: #7aa418;
  --tk-ink: #0c0b10;
}

/* ---------- painéis ---------- */

.tk-panel {
  border: 2px solid var(--line-2);
  background: var(--bg-2);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55);
  border-radius: 0;
  min-width: 0;
}
.tk-panel-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px;
  padding: 8px 12px;
  border-bottom: 2px solid var(--line);
  background: var(--surface);
}
.tk-panel-head .sg-label { font-family: var(--pixel-ui); font-size: 10.5px; letter-spacing: 0.06em; }

.tk-list { display: flex; flex-direction: column; }
.tk-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px 12px;
  min-width: 0;
}
.tk-row + .tk-row { border-top: 2px solid var(--line); }

.tk-meta {
  display: inline-flex; align-items: baseline; gap: 8px; margin-left: auto;
  font: 400 11px/1 var(--pixel-ui); color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tk-meta b { font-weight: 400; color: var(--text); font-size: 13px; }
.tk-eq { color: var(--faint); }

/* ---------- fichas de token ---------- */

.tk-word { display: inline-flex; align-items: center; flex-wrap: wrap; row-gap: 6px; min-width: 0; max-width: 100%; }

.tk-tok {
  --c: var(--line-3);
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 32px; padding: 0 6px;
  border: 2px solid var(--c);
  border-radius: 0;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--c) 22%, var(--surface));
  box-shadow: var(--tk-shadow);
  font: 400 17px/1 var(--pixel);
  color: var(--text);
  white-space: nowrap;
  user-select: none;
}
.tk-tok.ch { --c: var(--line-3); background: var(--surface-2); }
.tk-tok.ch.alt { background: var(--surface-3); }
.tk-tok.c0 { --c: var(--tk-c0); }
.tk-tok.c1 { --c: var(--tk-c1); }
.tk-tok.c2 { --c: var(--tk-c2); }
.tk-tok.c3 { --c: var(--tk-c3); }
.tk-tok.c4 { --c: var(--tk-c4); }
.tk-tok.unk { border-style: dashed; background: transparent; color: var(--muted); box-shadow: none; }

/* par sob o cursor: todas as ocorrências acendem */
.tk-word .tk-tok.hl {
  background: var(--tk-lime);
  border-color: var(--tk-lime-dk);
  color: var(--tk-ink);
}

/* encaixe da fusão, em quadros (sem suavização) */
.tk-tok.fresh { animation: tk-snap 0.36s steps(3, end) both; }
@keyframes tk-snap {
  0% { transform: scale(1.16, 0.8); background: var(--tk-lime); border-color: var(--tk-lime-dk); color: var(--tk-ink); }
  60% { transform: scale(0.94, 1.08); background: var(--tk-lime); border-color: var(--tk-lime-dk); color: var(--tk-ink); }
  100% { transform: none; }
}

/* ---------- junções clicáveis ("conectores") ---------- */

.tk-seam {
  position: relative; z-index: 1;
  flex: none;
  width: 10px; height: 14px;
  margin: 0 -1px;
  border: 2px solid var(--line-3);
  border-radius: 0;
  background: var(--surface-3);
  cursor: pointer;
  transition: none;
}
.tk-seam::before { content: ''; position: absolute; inset: -12px -8px; }
.tk-seam:hover, .tk-seam.hl { background: var(--tk-lime); border-color: var(--tk-lime-dk); }
/* Fácil, fase 1: junções do par mais frequente */
.tk-seam.best { background: var(--coin); border-color: #a8841a; box-shadow: 0 0 0 2px rgba(255, 210, 63, 0.35); }
.tk-seam:focus-visible { outline: 2px solid var(--tk-lime); outline-offset: 2px; border-radius: 0; background: var(--tk-lime); border-color: var(--tk-lime-dk); }
.tk-seam:active { transform: translateY(1px); }
.tk-seam:disabled { cursor: default; width: 6px; height: 6px; border-width: 0; background: var(--line); margin: 0; }
.tk-seam:disabled::before { content: none; }

.tk-gap { flex: none; width: 4px; }

/* legenda inline da junção */
.tk-seam-key {
  display: inline-block; vertical-align: -2px;
  width: 8px; height: 12px; margin: 0 2px;
  border: 2px solid var(--tk-lime-dk); background: var(--tk-lime);
}

/* ---------- prévia do par ---------- */

.tk-peek {
  display: flex; align-items: flex-start; gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 2px dashed var(--line-2);
  font-size: 13px; line-height: 1.5; color: var(--text-2);
}
.tk-peek .icon { margin-top: 2px; color: var(--tk-lime); flex: none; }
.tk-pk { font: 400 15px/1 var(--pixel); color: var(--tk-lime); margin-right: 4px; white-space: nowrap; }
.tk-pk i { font-style: normal; color: var(--muted); margin: 0 4px; }

/* ---------- painel de teste ---------- */

.tk-test { border-color: rgba(91, 155, 255, 0.55); }
.tk-test .tk-panel-head { background: rgba(91, 155, 255, 0.08); }
.tk-test .tk-panel-head .sg-label:first-child { color: var(--info); }
.tk-test .tk-meta { margin-left: auto; }

.tk-sum { font: 400 15px/1 var(--pixel-ui); color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tk-sum small { font-size: 10.5px; color: var(--muted); }
.tk-sum.ok { color: var(--good); }
.tk-sum.bad { color: var(--bad); }

.tk-note b { color: var(--text); font-weight: 500; }
.tk-note {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 12px 10px;
  border-top: 2px solid var(--line);
  font-size: 12.5px; line-height: 1.45; color: var(--muted);
}
.tk-key { flex: none; min-width: 22px; height: 24px; font-size: 14px; font-style: normal; }

/* ---------- fase 3: frases de avaliação ---------- */

.tk-flag {
  display: inline-block; margin-right: 8px; padding: 2px 4px;
  border: 2px solid var(--line-3); background: var(--surface-3);
  font: 400 10px/1 var(--pixel-ui); color: var(--text); letter-spacing: 0.04em;
}
.tk-evrow { padding: 10px 12px 12px; }
.tk-evrow + .tk-evrow { border-top: 2px solid var(--line); }
.tk-evhead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; }
.tk-evrow.tk-pt .tk-flag { border-color: var(--orange); color: var(--orange); }
.tk-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 0 8px; min-width: 0; }
.tk-eval .tk-tok { min-width: 18px; height: 28px; padding: 0 4px; font-size: 15px; }
/* dieta com vaga livre: as frases mostram o último treino, apagadas */
.tk-eval.stale .tk-line, .tk-eval.stale .tk-meter { opacity: 0.45; }

/* bytes soltos (pedaços de ç e ã) e tokens coloridos pela língua da fusão */
.tk-b { font: 400 9.5px/1 var(--pixel-ui); font-style: normal; letter-spacing: 0; color: var(--muted); padding: 0 1px; }
.tk-tok.byte { --c: var(--bad); border-style: dashed; background: rgba(255, 97, 89, 0.08); box-shadow: none; }
.tk-tok.byte .tk-b { color: var(--text-2); font-size: 11px; }
.tk-tok.l-en { --c: var(--tk-c0); }
.tk-tok.l-pt { --c: var(--orange); }
.tk-tok.l-mix { --c: var(--tk-c4); }

.tk-meter { display: flex; flex-wrap: wrap; gap: 3px; }
.tk-meter i { width: 10px; height: 10px; background: var(--tk-c0); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.55); }
.tk-meter.tk-pt i { background: var(--orange); }
.tk-meter i.over { background: transparent; box-shadow: inset 0 0 0 2px var(--bad); }

.tk-strip { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 12px 12px; min-height: 44px; }
.tk-strip > span:not(.tk-empty) {
  --c: var(--line-3);
  padding: 2px 5px;
  border: 2px solid var(--c);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--c) 18%, var(--surface));
  font: 400 13px/1.1 var(--pixel); color: var(--text-2);
}
.tk-strip .l-en, .tk-legend .l-en { --c: var(--tk-c0); }
.tk-strip .l-pt, .tk-legend .l-pt { --c: var(--orange); }
.tk-strip .l-mix, .tk-legend .l-mix { --c: var(--tk-c4); }
.tk-strip .fresh { animation: tk-snap 0.3s steps(3, end) both; }
.tk-legend { display: inline-flex; gap: 6px; }
.tk-legend span { padding: 2px 5px; border: 2px solid var(--c); font: 400 10px/1 var(--pixel-ui); color: var(--text); }

/* ---------- fase 3: cartões da dieta ---------- */

.tk-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; padding: 10px 12px 12px; }
.tk-card {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 6px 8px;
  border: 2px solid var(--line-2); border-left-width: 4px; border-radius: 0;
  background: var(--surface);
  box-shadow: var(--tk-shadow);
  color: var(--text); text-align: left;
  font-size: 13.5px; line-height: 1.3;
  cursor: pointer;
}
.tk-card.en { border-left-color: var(--tk-c0); }
.tk-card.pt { border-left-color: var(--orange); }
.tk-card .tk-flag { margin-right: 0; flex: none; }
.tk-card.pt .tk-flag { border-color: var(--orange); color: var(--orange); }
.tk-card-txt { flex: 1; min-width: 0; }
.tk-card-act { flex: none; width: 18px; font: 400 15px/1 var(--pixel-ui); color: var(--muted); text-align: center; }
.tk-card:hover:not(:disabled), .tk-card:focus-visible { border-color: var(--tk-lime); }
.tk-card:hover:not(:disabled) .tk-card-act { color: var(--tk-lime); }
.tk-card:focus-visible { outline: 2px solid var(--tk-lime); outline-offset: 2px; }
.tk-card:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.tk-card:disabled { cursor: default; opacity: 0.6; box-shadow: none; }
.tk-card.dragging { opacity: 0.4; }
.tk-diet .tk-card { background: color-mix(in srgb, var(--tk-lime) 7%, var(--surface)); }
.tk-slot {
  display: flex; align-items: center; justify-content: center; min-height: 40px;
  border: 2px dashed var(--line-2);
  font: 400 10.5px/1 var(--pixel-ui); color: var(--faint); letter-spacing: 0.06em;
}
.tk-diet { border-color: rgba(200, 245, 60, 0.45); }
.tk-drop.over { border-color: var(--tk-lime); background: color-mix(in srgb, var(--tk-lime) 6%, var(--bg-2)); }
.tk-diet.shake { animation: tk-shake 0.3s steps(4, end); }
@keyframes tk-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.tk-bytes { border: 2px dashed var(--line-2); border-top-width: 2px; }

/* ---------- placar compacto (telas estreitas: meta perto do que se mexe) ---------- */

.tk-hud { display: none; }
@media (max-width: 920px) {
  .tk-hud {
    position: sticky; top: 64px; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px;
    padding: 8px 10px;
    border: 2px solid var(--line-2);
    background: var(--bg-2);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.55);
  }
  .tk-hud .tk-conds { margin-top: 0; }
  .tk-hud-left { display: inline-flex; align-items: center; gap: 8px; font: 400 10.5px/1 var(--pixel-ui); color: var(--muted); }
}

/* ---------- objetivo, números e listas do painel lateral ---------- */

.tk-conds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tk-cond {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 7px;
  border: 2px solid var(--line-2);
  font: 400 10.5px/1.2 var(--pixel-ui); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tk-cond .icon { width: 12px; height: 12px; margin: 0; color: var(--bad); }
.tk-cond.ok { border-color: var(--good); color: var(--good); }
.tk-cond.ok .icon { color: var(--good); }

.tk-stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tk-stats dd small { font-size: 12px; color: var(--muted); margin-left: 1px; }

.tk-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tk-block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tk-faint { color: var(--faint); }
.tk-empty { font-size: 13px; color: var(--muted); }

.tk-pairs { display: flex; flex-wrap: wrap; gap: 6px; }
.tk-pair {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px;
  border: 2px solid var(--line-2);
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--tk-shadow);
  color: var(--text);
  cursor: pointer;
}
.tk-pair:hover, .tk-pair.hl, .tk-pair:focus-visible { border-color: var(--tk-lime); background: rgba(200, 245, 60, 0.08); }
.tk-pair:focus-visible { outline: 2px solid var(--tk-lime); outline-offset: 2px; border-radius: 0; }
.tk-pair:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.tk-pair:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.tk-pp { display: inline-flex; gap: 2px; }
.tk-pp span, .tk-mini {
  --c: var(--line-3);
  display: inline-block;
  min-width: 18px; padding: 2px 5px;
  border: 2px solid var(--c);
  background: var(--surface-2);
  font: 400 14px/1.1 var(--pixel); color: var(--text); text-align: center;
  white-space: nowrap;
}
.tk-mini.c0 { --c: var(--tk-c0); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.tk-mini.c1 { --c: var(--tk-c1); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.tk-mini.c2 { --c: var(--tk-c2); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.tk-mini.c3 { --c: var(--tk-c3); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.tk-mini.c4 { --c: var(--tk-c4); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }

/* iniciantes: ranking com contagens */
.tk-pairs.ranked { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.tk-pairs.ranked .tk-pair { display: grid; grid-template-columns: auto minmax(0, 1fr) 30px; gap: 10px; width: 100%; padding: 4px 8px 4px 4px; }
.tk-pairs.ranked .tk-pair b { font: 400 13px/1 var(--pixel-ui); text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.tk-bar { display: block; height: 8px; background: var(--surface-3); }
.tk-bar i { display: block; height: 100%; background: var(--line-3); }
.tk-pair.top { border-color: var(--coin); }
.tk-pair.top .tk-bar i { background: var(--coin); }
.tk-pair.top b { color: var(--coin); }
/* fase 2: contagem no corpus e efeito no teste lado a lado */
.tk-pairs.ranked.two .tk-pair { grid-template-columns: auto minmax(0, 1fr) 30px 62px; }
.tk-pairs.ranked .tk-pair em { font: 400 10.5px/1 var(--pixel-ui); font-style: normal; color: var(--faint); text-align: right; white-space: nowrap; }
.tk-pairs.ranked .tk-pair em.on { color: var(--info); }

.tk-merges { display: flex; flex-direction: column; }
.tk-merges li {
  display: flex; align-items: center; flex-wrap: wrap; gap: 5px;
  padding: 6px 0;
}
.tk-merges li + li { border-top: 2px solid var(--line); }
.tk-merges .n { min-width: 24px; font: 400 11px/1 var(--pixel-ui); color: var(--faint); }
.tk-merges .op { font: 400 13px/1 var(--pixel); color: var(--muted); }
.tk-merges .gain { margin-left: auto; font: 400 11px/1 var(--pixel-ui); color: var(--good); white-space: nowrap; }
.tk-merges .gain em { font-style: normal; color: var(--info); margin-left: 4px; }

/* segmentações citadas nas mensagens */
.tk-seg { font: 400 15px/1 var(--pixel); color: var(--text); white-space: nowrap; }
.tk-dot { color: var(--tk-lime); margin: 0 1px; }

/* ---------- telas estreitas ---------- */

@media (max-width: 640px) {
  .tk-tok { min-width: 20px; height: 28px; padding: 0 4px; font-size: 15px; }
  .tk-seam { width: 8px; height: 12px; }
  .tk-seam::before { inset: -10px -8px; }
  .tk-row { padding: 9px 10px; }
  .tk-line { gap: 8px 10px; }
  .tk-evrow, .tk-strip, .tk-cards { padding-left: 10px; padding-right: 10px; }
  .tk-cards { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .tk-card { min-height: 36px; font-size: 13px; }
  .tk-eval .tk-tok { min-width: 16px; height: 26px; padding: 0 3px; font-size: 14px; }
  .tk-meter i { width: 8px; height: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .tk-tok.fresh, .tk-strip .fresh, .tk-diet.shake { animation: none; }
}

/* texto só para leitores de tela */
.tk-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* aula: quadros desenhados com chart.js (só leitura ou toque): o dedo que começa neles ainda rola a página
   (duas classes porque lesson.css carrega depois e põe touch-action: none em .ls-canvas) */
.ls-canvas.tka-canvas { touch-action: pan-y; }
