/* ============================================================
   figuras.css — las visualizaciones interactivas (js/viz/)

   De integracion-i3, con su piel de póster: lienzo oscuro, trazos finos.
   Cada figura es una «Nota de estudio · Visualización»: lleva el filete
   lila de lo que añadimos nosotros.

   Un color, un papel dentro de las figuras:
     crema   el objeto que se estudia (la bola, la función, el convexo)
     cian    lo que se calcula con él (P(t) exacta, la pendiente, π)
     hielo   lo que el lector mueve (el cursor, la partícula, lo simulado)
     lila    conjuntos y bandas (las cotas, la cola)
   y cada ESTADO de una cadena tiene su color (--e0…--e5), en todas.
     alerta  lo que falla (el contraejemplo, lo que no se alcanza), en rosa
   ============================================================ */

.b-estudio {
  border-left: 2px solid var(--lila);
  background: var(--lila-velo);
  border-radius: 0 var(--radio) var(--radio) 0;
  padding: .85rem 1rem 1rem;
}
.b-estudio-cab .etq { color: var(--lila); }
.b-estudio-tit { font-size: 1.12rem; font-style: normal; margin: .1rem 0 .55rem; color: var(--crema); }
.b-fig { --fg-fondo: var(--hoja); margin: 0; }
.b-estudio.tono-visual { background: color-mix(in srgb, var(--lila-velo) 60%, transparent); }

.fg-escena { min-height: 280px; }
.fg-espera { margin: 0; font-style: normal; color: var(--crema-3); }

.b-fig-pie { margin-top: .9rem; font-size: .95rem; color: var(--crema-2); }
.b-fig-pie p + p { margin-top: .5rem; }
.b-fig-pie strong { color: var(--crema); }

/* ---------------------------------------------------------------- lienzo */

.fg-lienzo { background: var(--fg-fondo); border: 1px solid var(--filete); border-radius: 2px; }
.fg-svg {
  display: block; width: 100%; height: auto;
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
}
.fg-svg.fg-arrastrable { cursor: crosshair; }
.fg-svg.fg-arrastrando { cursor: grabbing; }

/* Cifras alineadas en todo lo que es de la figura («p = 1», «(1,1,1,…)»). */
.fg-svg text, .fg-lect, .fg-controles { font-variant-numeric: lining-nums; }

.fg-svg text {
  font-family: var(--f-texto);
  fill: var(--crema-2);
  paint-order: stroke; stroke: var(--fg-fondo); stroke-width: 3px; stroke-linejoin: round;
}
.fg-svg .fg-t  { font-size: 13.5px; fill: var(--crema-2); }
.fg-svg .fg-tb { font-size: 13.5px; fill: var(--crema); font-weight: 600; }
.fg-svg .fg-tk { font-size: 12px; fill: var(--crema-3); stroke-width: 2px; font-variant-numeric: lining-nums; }
.fg-svg .fg-ti { font-size: 15px; font-style: italic; fill: var(--crema); }
.fg-svg .fg-tv { font-size: 13.5px; fill: var(--acento); font-style: normal; }
.fg-svg .fg-tx { font-size: 13.5px; fill: var(--alerta); font-style: normal; }
.fg-svg .fg-ta { font-size: 13.5px; fill: var(--lila); font-style: normal; }
.fg-svg .fg-to { font-size: 13.5px; fill: var(--hielo-texto); font-style: normal; }
.fg-svg .fg-sub { font-size: .72em; }

/* ejes, rejilla y guías */
.fg-svg .fg-eje { stroke: var(--crema-3); stroke-width: 1; fill: none; }
.fg-svg .fg-eje-fino { stroke: var(--crema-3); stroke-width: 1; stroke-dasharray: 2 3; opacity: .75; }
.fg-svg .fg-rej { stroke: var(--crema); stroke-opacity: .07; stroke-width: 1; }
.fg-svg .fg-g { stroke: var(--crema-3); stroke-width: 1; stroke-dasharray: 4 4; fill: none; }
.fg-svg .fg-gv { stroke: var(--acento); stroke-width: 1.2; stroke-dasharray: 4 4; fill: none; }
.fg-svg .fg-ga { stroke: var(--lila); stroke-width: 1.2; stroke-dasharray: 4 4; fill: none; }
.fg-svg .fg-gl { stroke: var(--hielo); stroke-width: 1.4; stroke-dasharray: 5 4; fill: none; }
.fg-svg .fg-rayo { stroke: var(--hielo); stroke-width: 1; opacity: .55; fill: none; }

/* trazos: uno por papel */
.fg-svg .fg-c1, .fg-svg .fg-c2, .fg-svg .fg-c3, .fg-svg .fg-c4, .fg-svg .fg-c5 {
  fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round;
}
.fg-svg .fg-c1 { stroke: var(--crema); }
.fg-svg .fg-c2 { stroke: var(--acento); stroke-width: 2.2; }
.fg-svg .fg-c3 { stroke: var(--hielo); stroke-width: 2; }
.fg-svg .fg-c4 { stroke: var(--lila); }
.fg-svg .fg-c5 { stroke: var(--alerta); }
.fg-svg .fg-fino { stroke-width: 1.1; }
.fg-svg .fg-grueso { stroke-width: 3; }
.fg-svg .fg-punteado { stroke-dasharray: 5 4; }
.fg-svg .fg-tenue { opacity: .45; }

/* áreas */
.fg-svg .fg-a1, .fg-svg .fg-a2, .fg-svg .fg-a3, .fg-svg .fg-a4, .fg-svg .fg-a5 { stroke: none; }
.fg-svg .fg-a1 { fill: var(--acento); fill-opacity: .16; }
.fg-svg .fg-a2 { fill: var(--lila); fill-opacity: .14; }
.fg-svg .fg-a3 { fill: var(--hielo); fill-opacity: .2; }
.fg-svg .fg-a4 { fill: var(--crema); fill-opacity: .06; }
.fg-svg .fg-a5 { fill: var(--alerta); fill-opacity: .16; }
.fg-svg .fg-borde-v { stroke: var(--acento); stroke-width: 1.2; }
.fg-svg .fg-borde-a { stroke: var(--lila); stroke-width: 1.2; }
.fg-svg .fg-borde-c { stroke: var(--crema); stroke-width: 1.2; }
.fg-svg .fg-marco { fill: none; stroke: var(--filete); stroke-width: 1; }
.fg-svg .fg-barra-c { fill: var(--crema); fill-opacity: .75; stroke: none; }
.fg-svg .fg-barra-v { fill: var(--acento); fill-opacity: .7; }
.fg-svg .fg-barra-a { fill: var(--lila); fill-opacity: .7; }
.fg-svg .fg-barra-x { fill: var(--alerta); fill-opacity: .75; }
.fg-svg .fg-barra-act { fill: var(--hielo); }
.fg-svg .fg-barra-tenue { fill: var(--crema); fill-opacity: .1; }

/* puntos y asas */
.fg-svg .fg-pt { fill: var(--hielo); stroke: var(--fg-fondo); stroke-width: 2; }
.fg-svg .fg-asa { cursor: grab; }
.fg-svg .fg-anillo { fill: none; stroke: var(--hielo); stroke-width: 1.2; opacity: .7; }
.fg-svg .fg-hueco { fill: var(--fg-fondo); stroke: var(--crema); stroke-width: 1.6; }
.fg-svg .fg-lleno { fill: var(--crema); stroke: var(--fg-fondo); stroke-width: 1.2; }
.fg-svg .fg-pv { fill: var(--acento); stroke: var(--fg-fondo); stroke-width: 1.5; }
.fg-svg .fg-pa { fill: var(--lila); stroke: var(--fg-fondo); stroke-width: 1.5; }
.fg-svg .fg-px { fill: var(--alerta); stroke: var(--fg-fondo); stroke-width: 1.5; }
.fg-svg .fg-err { stroke: var(--alerta); stroke-width: 2.2; stroke-linecap: round; fill: none; }

/* ---------------------------------------------------------------- lecturas */

.b-fig sup, .b-fig sub { font-size: .72em; line-height: 0; }

.fg-lect {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: .5rem 1rem; margin: .8rem 0 0;
}
.fg-l { margin: 0; min-width: 0; }
.fg-l dt {
  display: flex; align-items: center; gap: .45rem;
  font-style: normal;
  font-size: .92rem; color: var(--crema-2); line-height: 1.25;
}
.fg-l dd { margin: .1rem 0 0; font-size: 1.15rem; color: var(--crema); font-variant-numeric: lining-nums tabular-nums; overflow-wrap: anywhere; }
.fg-sw { flex: none; display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--crema-3); }
.fg-sw-c1 { background: var(--crema); }
.fg-sw-v  { background: var(--acento); }
.fg-sw-l  { background: var(--hielo); }
.fg-sw-a  { background: var(--lila); }
.fg-sw-x  { background: var(--alerta); }

/* La línea de uso: una frase, encima de la figura. */
.fg-uso { margin: 0 0 .6rem; font-size: .95rem; color: var(--crema-2); font-style: normal; }

/* ---------------------------------------------------------------- controles */

.fg-controles {
  display: flex; flex-wrap: wrap; align-items: center; gap: .55rem 1.2rem;
  margin-top: .85rem; padding-top: .75rem;
  border-top: 1px solid var(--filete-2);
}
.fg-ctl { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.fg-ctl-rango { flex: 1 1 240px; }
.fg-ctl-opc { flex-wrap: wrap; }
.fg-etq { font-style: normal; color: var(--crema-2); white-space: nowrap; font-size: .98rem; }
.fg-valor { flex: none; min-width: 4.4em; text-align: right; color: var(--crema); font-variant-numeric: lining-nums tabular-nums; }

.fg-rango {
  flex: 1; min-width: 90px; height: 24px; margin: 0; cursor: pointer;
  -webkit-appearance: none; appearance: none; background: transparent; accent-color: var(--hielo);
}
.fg-rango::-webkit-slider-runnable-track { height: 2px; background: var(--linea); border-radius: 2px; }
.fg-rango::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; margin-top: -6.5px; border-radius: 50%;
  background: var(--hoja); border: 1.5px solid var(--hielo); box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.fg-rango::-moz-range-track { height: 2px; background: var(--linea); border-radius: 2px; }
.fg-rango::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--hoja); border: 1.5px solid var(--hielo); }

.fg-seg { display: inline-flex; flex-wrap: wrap; }
.fg-op, .fg-btn {
  font: inherit;
  letter-spacing: .01em; font-size: .95rem;
  color: var(--crema-2); background: none; cursor: pointer;
  border: 1px solid var(--filete); padding: .18rem .7rem .26rem;
  transition: background .15s, color .15s, border-color .15s;
}
.fg-op { margin: 0 -1px -1px 0; }
.fg-op:first-child { border-radius: 0; padding-left: .85rem; }
.fg-op:last-child { border-radius: 0; padding-right: .85rem; }
.fg-op:only-child { border-radius: 0; }
.fg-op:hover, .fg-btn:hover { color: var(--acento); border-color: var(--linea); }
.fg-op[aria-pressed="true"] { background: var(--acento); border-color: var(--acento); color: var(--noche); }
.fg-btn { border-radius: 0; }
.fg-btn.fg-play { border-color: var(--acento); color: var(--acento); padding: .18rem .95rem .26rem; }
.fg-btn.fg-play[aria-pressed="true"] { background: var(--acento); color: var(--noche); }
.fg-play-ico { display: inline-block; min-width: 1em; font-size: .8em; }
.fg-reiniciar { padding: .18rem .6rem .26rem; }
.fg-btn:disabled, .fg-op:disabled { opacity: .4; cursor: not-allowed; }

.fg-int { cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.fg-int input { accent-color: var(--acento); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.fg-int-txt { font-style: normal; color: var(--crema-2); }
.fg-int:hover .fg-int-txt { color: var(--acento); }

.fg-op:focus-visible, .fg-btn:focus-visible, .fg-rango:focus-visible, .fg-int input:focus-visible {
  outline: 2px solid var(--hielo); outline-offset: 2px;
}

@media (max-width: 560px) {
  .b-estudio { padding: .75rem .7rem .85rem; }
  .fg-ctl-rango { flex-basis: 100%; }
  .fg-lect { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fg-l dd { font-size: 1.05rem; }
}

/* ============================================================
   Lo nuevo: los estados de una cadena y las piezas de estas figuras
   ============================================================ */

.b-estudio { border-left-color: var(--lila); background: var(--lila-velo); }
.b-estudio-cab .etq { color: var(--lila); display: inline-flex; align-items: center; gap: .4rem; }
.b-estudio.tono-visual { background: color-mix(in srgb, var(--lila-velo) 60%, transparent); }

/* Un color por estado: trazo, relleno y texto. */
.fg-svg .fg-e0 { stroke: var(--e0); } .fg-svg .fg-e1 { stroke: var(--e1); } .fg-svg .fg-e2 { stroke: var(--e2); }
.fg-svg .fg-e3 { stroke: var(--e3); } .fg-svg .fg-e4 { stroke: var(--e4); } .fg-svg .fg-e5 { stroke: var(--e5); }
.fg-svg .fg-ef0 { fill: var(--e0); } .fg-svg .fg-ef1 { fill: var(--e1); } .fg-svg .fg-ef2 { fill: var(--e2); }
.fg-svg .fg-ef3 { fill: var(--e3); } .fg-svg .fg-ef4 { fill: var(--e4); } .fg-svg .fg-ef5 { fill: var(--e5); }
.fg-svg [class*="fg-ef"] { fill-opacity: .78; stroke: none; }
.fg-svg .fg-te0 { fill: var(--e0); } .fg-svg .fg-te1 { fill: var(--e1); } .fg-svg .fg-te2 { fill: var(--e2); }
.fg-svg .fg-te3 { fill: var(--e3); } .fg-svg .fg-te4 { fill: var(--e4); } .fg-svg .fg-te5 { fill: var(--e5); }

.fg-svg .fg-escalon { stroke-width: 3.4; stroke-linecap: round; fill: none; }
.fg-svg .fg-salto-v { stroke: var(--crema-3); stroke-width: 1; stroke-dasharray: 2 3; }
.fg-svg .fg-pi { stroke: var(--acento); stroke-width: 2; stroke-dasharray: 3 2; }
.fg-svg .fg-caja-e { stroke: none; }
.fg-svg .fg-caja-act { stroke: var(--crema); stroke-width: 1.5; }
.fg-svg .fg-tcaja { font-size: 11.5px; font-family: var(--f-mono); font-weight: 700; fill: var(--noche); stroke: none; }

/* Tableros de matrices. */
.fg-svg .fg-celda { fill: var(--acento); fill-opacity: calc(.06 + .8 * var(--o, 0)); stroke: var(--filete); stroke-width: 1; }
.fg-svg .fg-celda-sel { stroke: var(--hielo); stroke-width: 1.4; }
.fg-svg .fg-celda-act { stroke: var(--oro); stroke-width: 2.4; }
.fg-svg .fg-tcelda, .fg-svg .fg-tcelda-osc { font-size: 11.5px; font-family: var(--f-mono); stroke: none; }
.fg-svg .fg-tcelda { fill: var(--crema); }
.fg-svg .fg-tcelda-osc { fill: var(--noche); font-weight: 700; }
.fg-svg .fg-corchete { fill: none; stroke: var(--crema-2); stroke-width: 1.3; }

/* Relojes que compiten. */
.fg-svg .fg-reloj-corre { fill: var(--hielo); fill-opacity: .55; }
.fg-svg .fg-reloj-gana { fill: var(--acento); fill-opacity: .9; }
.fg-svg .fg-reloj-tarde { fill: var(--crema-3); fill-opacity: .35; }
.fg-svg .fg-anillo-gana { fill: none; stroke: var(--oro); stroke-width: 2.4; }

/* El diagrama de la cadena. */
.fg-svg .fg-flecha { fill: none; stroke: var(--crema-3); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.fg-svg .fg-flecha-act { fill: none; stroke: var(--oro); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.fg-svg .fg-tq { font-size: 12.5px; font-family: var(--f-mono); fill: var(--crema); }
.fg-svg .fg-nodo { fill: var(--hoja); stroke-width: 2; }
.fg-svg .fg-nodo-e0 { stroke: var(--e0); } .fg-svg .fg-nodo-e1 { stroke: var(--e1); } .fg-svg .fg-nodo-e2 { stroke: var(--e2); }
.fg-svg .fg-nodo-e3 { stroke: var(--e3); } .fg-svg .fg-nodo-e4 { stroke: var(--e4); } .fg-svg .fg-nodo-e5 { stroke: var(--e5); }
.fg-svg .fg-nodo.on { stroke-width: 3.4; fill: var(--noche-3); }
.fg-svg .fg-tnodo { font-family: var(--f-mono); font-weight: 700; font-size: 15px; fill: var(--crema); }
.fg-svg .fg-particula { fill: var(--hielo); stroke: var(--fg-fondo); stroke-width: 2; filter: drop-shadow(0 0 6px var(--hielo)); }
.fg-svg .fg-reloj-anillo { fill: none; stroke: var(--hielo); stroke-width: 1.5; opacity: .6; transform-box: fill-box; transform-origin: center; animation: respirar 1.6s ease-in-out infinite; }
@keyframes respirar { 0%, 100% { opacity: .2; transform: scale(.94); } 50% { opacity: .75; transform: scale(1.04); } }

.fg-sw-v { background: var(--acento); }
.fg-sw-l { background: var(--hielo); }
.fg-sw-a { background: var(--lila); }
.fg-op[aria-pressed="true"] { color: var(--sobre-acento); }
.fg-svg .fg-c6 { fill: none; stroke: var(--oro); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.fg-svg .fg-po { fill: var(--oro); stroke: var(--fg-fondo); stroke-width: 1.5; }
.fg-sw-o { background: var(--oro); }
