/* Velotecla · Gráficas, mapa de calor, racha y página de estadísticas */

/* ---------- Gráfica de líneas ---------- */
.chart { position: relative; }
.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-bottom: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}
.chart__legend-item { display: inline-flex; align-items: center; gap: 8px; }
.chart__key { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--accent); }
.chart__key--ref { border-top: 1.5px dashed var(--muted); }
.chart__key--marker {
  width: auto;
  height: auto;
  border: 0;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
  color: var(--error);
}
.chart__plot { position: relative; }
.chart__plot svg { display: block; width: 100%; height: auto; overflow: visible; outline-offset: 4px; }
.chart__grid line { stroke: var(--line); stroke-width: 1; }
.chart__grid text { fill: var(--pending); font-family: var(--font-mono); font-size: 0.625rem; }
.chart__line { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart__line--main { stroke: var(--accent); stroke-width: 2; }
.chart__line--ref { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .8; }
.chart__markers text { fill: var(--error); font-size: 0.75rem; font-weight: 700; }
.chart__cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart__dot { stroke: var(--bg); stroke-width: 2; }
.chart__dot--main { fill: var(--accent); }
.chart__dot--ref { fill: var(--muted); }
.chart__tip {
  position: absolute;
  min-width: 130px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgb(0 0 0 / .35);
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}
.chart__tip[hidden] { display: none; }
.chart__tip-title { margin-bottom: 6px; font-family: var(--font-mono); color: var(--muted); }
.chart__tip-row { display: flex; align-items: center; gap: 8px; }
.chart__tip-row b { min-width: 28px; font-family: var(--font-mono); font-size: 0.875rem; font-weight: 500; color: var(--text); }
.chart__table { margin-top: 10px; font-size: 0.75rem; color: var(--muted); }
.chart__table summary { cursor: pointer; width: fit-content; }
.chart__table summary:hover { color: var(--text); }
.chart__table table { margin-top: 8px; border-collapse: collapse; font-family: var(--font-mono); }
.chart__table th, .chart__table td { padding: 3px 14px 3px 0; text-align: right; font-weight: 400; }
.chart__table thead th { color: var(--pending); font-family: var(--font-ui); }
.chart__table td { color: var(--text); }

/* ---------- Bloque de resultado ampliado ---------- */
/* Aviso de récord: texto, no botón (sin borde ni forma de cápsula, para que no parezca clicable) */
.results__badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  margin-left: auto;
  align-self: center;
  text-align: right;
  color: var(--accent);
}
.results__badge[hidden] { display: none; }
.results__badge b { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 1.875rem; line-height: 1.05; }
.results__badge span { font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
.results__badge--muted b { color: var(--muted); font-size: 1.5rem; }
.results__section { margin-top: 32px; }
.results__section > .eyebrow { display: block; margin-bottom: 12px; }

/* ---------- Mapa de calor del teclado ---------- */
.kb--heat .key {
  --heat: 0;
  color: var(--text);
  background: color-mix(in srgb, var(--error) calc(var(--heat) * 70%), var(--surface));
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: default;
}
.kb--heat .key[data-f="x"] { background: transparent; color: var(--pending); }
.kb--heat .key.is-nodata { color: var(--pending); }
.kb--heat .key:hover { box-shadow: inset 0 0 0 1.5px var(--text); }
.heat-scale {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}
.heat-scale i {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--surface), color-mix(in srgb, var(--error) 70%, var(--surface)));
  box-shadow: inset 0 0 0 1px var(--line);
}
.weak {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--muted);
}
.weak__keys { display: flex; gap: 6px; }
.weak__key {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  min-width: 30px;
  min-height: 30px;
  padding: 6px 8px 0;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  color: var(--text);
}
.weak__key small { font-size: 0.5625rem; color: var(--muted); }
.btn--ghost {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn--ghost:hover { box-shadow: inset 0 0 0 1px var(--muted); filter: none; }
.heat-tip {
  position: fixed;
  z-index: 50;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}
.heat-tip b { font-family: var(--font-mono); color: var(--text); font-weight: 500; }
.heat-tip[hidden] { display: none; }

/* ---------- Fantasmita ----------
   Flota justo encima de la letra por la que va tu récord, con un leve vaivén. */
.ghost-caret {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  /* Pegado a SU fila: la base del fantasma toca la parte alta de las letras,
     dentro del espacio entre filas (no invade la fila de arriba). */
  width: .58em;
  height: .62em;
  margin-left: -.29em;
  margin-top: calc(var(--gutter) + (var(--lh) - 1.1em) / 2 - .5em);
  color: var(--ghost);
  pointer-events: none;
  transition: transform 140ms linear;
  will-change: transform;
}
.ghost-caret svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  opacity: .85;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--ghost) 55%, transparent));
  animation: ghost-bob 1.6s ease-in-out infinite;
}
@keyframes ghost-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-3px) rotate(5deg); }
}
/* Cuando el fantasma termina: más visible, flota lento y muestra "fin" */
.ghost-caret.is-done svg { opacity: 1; animation-duration: 2.6s; }
.ghost-caret.is-done::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ghost) 20%, var(--bg));
  color: var(--ghost);
  font-family: var(--font-ui);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: .08em;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
  animation: ghost-done .3s var(--ease);
}
@keyframes ghost-done { from { opacity: 0; transform: translate(-4px, -50%); } }

/* Línea del duelo en el resultado */
.results__duel {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 0;
  font-size: 0.9375rem;
  color: var(--text);
}
.results__duel .icon { width: 18px; height: 18px; color: var(--ghost); }
.results__duel b { font-weight: 700; font-variant-numeric: tabular-nums; }
.results__duel.is-win b { color: var(--accent); }
.results__duel.is-lose b { color: var(--ghost); }

/* ---------- Racha y meta diaria (barra lateral) ---------- */
.streak-box { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.streak-box__days { display: flex; align-items: baseline; gap: 8px; margin: 8px 0 14px; }
.streak-box__days b {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 2.5rem;
  line-height: .9;
  color: var(--streak);
}
.streak-box__days span { color: var(--muted); font-size: 0.8125rem; }
.streak-box__goal { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); }
.streak-box__goal b { font-family: var(--font-mono); font-weight: 500; color: var(--text); }
.meter { height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent); transition: width .4s var(--ease); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 14px; }
.week span {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}
.week span.is-on { background: color-mix(in srgb, var(--accent) 75%, var(--surface)); box-shadow: none; }
.week span.is-today { box-shadow: inset 0 0 0 1.5px var(--text); }

/* ---------- Página de estadísticas ---------- */
.stats-page { max-width: 960px; margin: 0 auto; padding: 24px 24px 0; }
.stats-page h1 {
  margin: 8px 0 32px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(2.75rem, 6vw, 4rem);
  line-height: 1;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stat-row > div { display: flex; flex-direction: column-reverse; gap: 8px; padding: 20px 16px 20px 0; }
.stat-row > div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.stat-row b { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 2.75rem; line-height: .9; }
.stat-row b.is-accent { color: var(--accent); }
.stats-section { margin-top: 56px; }
.stats-section > h2 { margin: 0 0 18px; }
.pb-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.pb-table th { text-align: left; font-weight: 600; padding: 0 0 10px; }
.pb-table td { padding: 12px 0; border-top: 1px solid var(--line); color: var(--muted); }
.pb-table td:nth-child(2) { font-family: var(--font-mono); color: var(--text); }
.pb-table td b { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 1.625rem; color: var(--accent); }
.empty-state {
  padding: 48px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}
.empty-state p { margin: 0 0 18px; }
.danger-zone { margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; color: var(--error); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 767px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-row > div:nth-child(3) { padding-left: 0; border-left: 0; }
  .stats-page { padding: 16px 16px 0; }
}
