/* ==========================================================================
   LABORATORIO DE ROBÓTICA — REDI / TSJ Tomatlán
   Estilo: laboratorio tecnologico / HUD moderado / software STEM.
   ========================================================================== */

:root {
  --bg: #060a13;
  --bg-panel: #0c1322;
  --bg-panel-alt: #101a2e;
  --bg-elevado: #141f38;
  --borde: rgba(140, 190, 255, 0.14);
  --borde-fuerte: rgba(80, 200, 255, 0.35);
  --cian: #2fd8ff;
  --azul: #3d7fff;
  --violeta: #8b6bff;
  --texto: #e7f0fb;
  --texto-tenue: #82a0c4;
  --texto-muy-tenue: #4d6187;
  --verde: #33e6a6;
  --amarillo: #ffcc4d;
  --rojo: #ff4d6d;
  --fuente-mono: 'Consolas', 'SFMono-Regular', 'Courier New', monospace;
  --fuente-base: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radio: 10px;
  --duracion-paso: 480ms;
}

* { box-sizing: border-box; }

html {
  /* Base un poco mas grande que el default del navegador (16px) para que
     todo el texto (que en este proyecto usa rem) se lea mejor en pantalla
     compartida/proyector. */
  font-size: 18px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--texto);
  font-family: var(--fuente-base);
  min-height: 100vh;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

h1, h2, h3 { margin: 0; }

.fondo-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(80, 160, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 160, 255, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  pointer-events: none;
}
.fondo-grid::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 20%, rgba(61, 127, 255, 0.10), transparent 60%);
}
.fondo-grid--final::after {
  background: radial-gradient(ellipse at 50% 30%, rgba(51, 230, 166, 0.10), transparent 60%);
}

/* ==========================================================================
   Pantallas (una a la vez)
   ========================================================================== */

.pantalla {
  display: none;
  min-height: 100vh;
  position: relative;
}
.pantalla--activa { display: block; }

/* ---- Carga / Boot ---- */
#pantalla-carga.pantalla--activa,
#pantalla-intro.pantalla--activa {
  display: flex;
  align-items: center;
  justify-content: center;
}

.carga__contenido, .intro__contenido {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 560px;
  padding: 2rem;
}

.carga__logos {
  display: flex;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 1.2rem;
  margin-bottom: 1.8rem;
}
.carga__logo-badge {
  width: 100px;
  height: 100px;
  flex: 0 0 auto;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: rebote-logo-carga 1.8s ease-in-out infinite;
}
.carga__logo-badge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
}
.carga__logo-badge:nth-child(1) { animation-delay: 0s; }
.carga__logo-badge:nth-child(2) { animation-delay: 0.18s; }
.carga__logo-badge:nth-child(3) { animation-delay: 0.36s; }
.carga__logo-badge:nth-child(4) { animation-delay: 0.54s; }
/* REDI (1) y TSJ (4) tienen mas margen vacio dentro de su propio PNG que
   DIF (2) e ISC (3), por lo que su area de imagen visible se ve mas chica
   aunque el badge mida lo mismo. Se agranda su img para igualar el
   tamaño visual percibido de los 4 logos. */
.carga__logo-badge:nth-child(1) img,
.carga__logo-badge:nth-child(4) img {
  transform: scale(1.3);
}
@keyframes rebote-logo-carga {
  0%, 55%, 100% { transform: scale(1); }
  27% { transform: scale(1.3); }
}

.carga__equipo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.6rem;
}
.carga__equipo label {
  font-family: var(--fuente-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--texto-muy-tenue);
}
.carga__equipo input {
  width: min(320px, 80vw);
  text-align: center;
  padding: 0.7rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--borde-fuerte);
  border-radius: 8px;
  color: var(--texto);
  font-family: var(--fuente-mono);
  font-size: 0.95rem;
}
.carga__equipo input:focus { outline: none; border-color: var(--cian); box-shadow: 0 0 0 3px rgba(47, 216, 255, 0.15); }

.carga__eyebrow {
  font-family: var(--fuente-mono);
  color: var(--cian);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 0.8rem;
}

.carga__titulo {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--texto), var(--cian));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 1.4rem;
}

.carga__estado {
  font-family: var(--fuente-mono);
  color: var(--texto-tenue);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  margin-bottom: 1.6rem;
  animation: parpadeo 1.6s infinite;
}
@keyframes parpadeo { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.carga__checklist {
  list-style: none;
  margin: 0 0 2rem;
  padding: 1.2rem 1.4rem;
  background: rgba(12, 19, 34, 0.7);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  text-align: left;
  font-family: var(--fuente-mono);
  font-size: 0.85rem;
}
.carga__checklist li {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0;
  color: var(--texto-tenue);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.carga__checklist li:last-child { border-bottom: none; }
.carga__check-estado { color: var(--texto-muy-tenue); }
.carga__check-estado--ok { color: var(--verde); font-weight: 700; }

.intro__texto {
  font-size: 1.15rem;
  color: var(--texto-tenue);
  margin: 0 0 0.6rem;
  line-height: 1.5;
}
.intro__texto--acento {
  color: var(--texto);
  font-weight: 600;
}
.intro__contenido .btn { margin-top: 1.6rem; }

/* ==========================================================================
   Botones
   ========================================================================== */

.btn {
  font-family: var(--fuente-mono);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.85rem 1.8rem;
  border-radius: 8px;
  border: 1px solid var(--borde-fuerte);
  background: rgba(47, 216, 255, 0.08);
  color: var(--cian);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { background: rgba(47, 216, 255, 0.18); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn--primario {
  background: linear-gradient(120deg, var(--azul), var(--cian));
  color: #04101f;
  border-color: transparent;
  font-weight: 700;
}
.btn--primario:hover:not(:disabled) { filter: brightness(1.08); }

.btn--secundario {
  background: transparent;
  color: var(--texto-tenue);
  border-color: var(--borde);
}
.btn--secundario:hover:not(:disabled) { color: var(--texto); border-color: var(--borde-fuerte); }

.btn-icono {
  font-family: var(--fuente-mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: rgba(255, 255, 255, 0.03);
  color: var(--texto-tenue);
}
.btn-icono:hover { color: var(--texto); border-color: var(--borde-fuerte); }
.btn-icono--apagado { color: var(--texto-muy-tenue); }
.btn-icono--tenue { opacity: 0.55; font-size: 0.68rem; }
.btn-icono--tenue:hover { opacity: 1; }

/* ==========================================================================
   Pantalla de juego — layout general
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 0.9rem 1.4rem;
  background: rgba(9, 14, 26, 0.9);
  border-bottom: 1px solid var(--borde);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(6px);
}

.topbar__marca { display: flex; flex-direction: column; line-height: 1.25; }
.topbar__titulo {
  font-family: var(--fuente-mono);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--texto);
}
.topbar__sub { font-size: 0.68rem; color: var(--texto-muy-tenue); letter-spacing: 0.03em; }

.topbar__acciones { display: flex; gap: 0.6rem; }

.barra-niveles { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.barra-niveles__item {
  font-family: var(--fuente-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: transparent;
  color: var(--texto-muy-tenue);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.barra-niveles__item--activo { border-color: var(--cian); color: var(--cian); background: rgba(47, 216, 255, 0.08); }
.barra-niveles__item--completo:not(.barra-niveles__item--activo) { color: var(--verde); border-color: rgba(51, 230, 166, 0.35); }
.barra-niveles__item--bloqueado { opacity: 0.4; cursor: not-allowed; }
.barra-niveles__item--reto:not(.barra-niveles__item--activo){ border-color: rgba(139, 107, 255, 0.3); color: #b8a6ff; }
.barra-niveles__separador { width: 1px; align-self: stretch; background: var(--borde-fuerte); margin: 0 0.3rem; }
.barra-niveles__candado { font-size: 0.65rem; }

.layout-juego {
  position: relative;
  z-index: 1;
  display: grid;
  /* El tablero tiene celdas de tamaño fijo en px (ver --celda). El minimo
     de la primera columna debe cubrir ese ancho siempre (incluye el caso
     --celda:66px de pantallas anchas) o el grid la fuerza a crecer y le
     roba espacio a la ultima columna, dejandola "mocha". */
  grid-template-columns: minmax(562px, 1.3fr) minmax(420px, 1.55fr) minmax(260px, 0.85fr);
  gap: 1.1rem;
  padding: 1.1rem 1.4rem;
  max-width: 1600px;
  margin: 0 auto;
}

.zona {
  background: rgba(12, 19, 34, 0.72);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.zona__cabecera { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; }
.zona__cabecera--separada { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--borde); }
.zona__cabecera h2 {
  font-family: var(--fuente-mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: var(--texto-tenue);
  text-transform: uppercase;
}

.pie-institucional {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1rem;
  font-family: var(--fuente-mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--texto-muy-tenue);
}
.pie-institucional__sep { margin: 0 0.4rem; }
.pie-institucional__logos {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.2rem;
}
.pie-institucional__logo-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.pie-institucional__logo-img { height: 46px; width: auto; opacity: 0.95; }
.pie-institucional__sub { margin: 0.35rem 0 0; font-size: 0.64rem; opacity: 0.75; }

/* ==========================================================================
   Zona 1 — Tablero
   ========================================================================== */

.objetivo-caja {
  background: rgba(61, 127, 255, 0.08);
  border: 1px solid rgba(61, 127, 255, 0.25);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.9rem;
}
.objetivo-caja__etiqueta {
  display: block;
  font-family: var(--fuente-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--azul);
  margin-bottom: 0.25rem;
}
#objetivo-texto { margin: 0; font-size: 0.88rem; color: var(--texto); }

.tablero-wrap { display: flex; justify-content: center; margin-bottom: 0.9rem; }

.tablero {
  position: relative;
  border: 1px solid var(--borde-fuerte);
  border-radius: 8px;
  background: radial-gradient(ellipse at center, rgba(61, 127, 255, 0.06), transparent 70%), var(--bg-panel);
  box-shadow: inset 0 0 40px rgba(47, 216, 255, 0.04);
  overflow: hidden;
}

.tablero-celdas {
  display: grid;
  grid-template-columns: repeat(var(--columnas), var(--celda, 58px));
  grid-template-rows: repeat(var(--filas), var(--celda, 58px));
}

.tablero-capa-robot {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.celda {
  border: 1px solid rgba(140, 190, 255, 0.06);
  position: relative;
}
.celda--inicio::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(139, 107, 255, 0.4);
  border-radius: 6px;
}
.celda--obstaculo { background: rgba(255, 77, 109, 0.07); }
.celda__icono-obstaculo {
  position: absolute;
  inset: 12%;
  background: repeating-linear-gradient(45deg, rgba(255, 77, 109, 0.55), rgba(255, 77, 109, 0.55) 4px, transparent 4px, transparent 9px);
  border: 1px solid rgba(255, 77, 109, 0.55);
  border-radius: 4px;
}
/* Destello cuando un obstaculo oculto (retos) se acaba de descubrir con el sensor */
.celda--recien-descubierto { animation: destello-descubierto 0.9s ease-out; }
@keyframes destello-descubierto {
  0% { background: rgba(255, 204, 77, 0.75); box-shadow: 0 0 22px rgba(255, 204, 77, 0.8); }
  100% { background: rgba(255, 77, 109, 0.07); box-shadow: none; }
}
.celda--meta { background: rgba(51, 230, 166, 0.06); }
.celda__icono-meta {
  position: absolute;
  inset: 18%;
  border: 2px solid var(--verde);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(51, 230, 166, 0.45);
  animation: pulso-meta 1.8s infinite ease-in-out;
}
.celda__icono-meta::after {
  content: '';
  position: absolute;
  inset: 32%;
  background: var(--verde);
  border-radius: 50%;
  opacity: 0.8;
}
@keyframes pulso-meta {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.6; }
}

.celda--sensor-bloqueado { background: rgba(255, 77, 109, 0.22) !important; transition: background 0.15s; }
.celda--sensor-libre { background: rgba(51, 230, 166, 0.16) !important; transition: background 0.15s; }

/* ==========================================================================
   Robot
   ========================================================================== */

.robot {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 5;
  will-change: transform;
}
.robot__svg { width: 100%; height: 100%; display: block; overflow: visible; }

.robot__rueda { fill: #1a2743; }
.robot__chasis {
  fill: url(#none);
  fill: #16223c;
  stroke: var(--cian);
  stroke-width: 2;
}
.robot__panel { fill: #0b1424; stroke: rgba(80, 160, 255, 0.3); stroke-width: 1; }
.robot__luz-estado { fill: var(--verde); filter: drop-shadow(0 0 4px rgba(51, 230, 166, 0.8)); }
.robot__sensor-ojo { fill: var(--cian); filter: drop-shadow(0 0 3px rgba(47, 216, 255, 0.7)); }
.robot__indicador-frontal { fill: var(--cian); }
.robot__haz-sensor { fill: rgba(47, 216, 255, 0); transition: fill 0.2s; }

.robot--sensor-activo .robot__haz-sensor { fill: rgba(47, 216, 255, 0.16); }
.robot--sensor-activo .robot__sensor-ojo { fill: var(--amarillo); }

.robot--colision .robot__chasis { stroke: var(--rojo); }
.robot--colision .robot__luz-estado { fill: var(--rojo); filter: drop-shadow(0 0 6px rgba(255, 77, 109, 0.9)); }
.robot--colision { animation: sacudida 0.35s; }
@keyframes sacudida {
  0%, 100% { margin-left: 0; }
  25% { margin-left: -3px; }
  75% { margin-left: 3px; }
}

.robot--meta .robot__luz-estado { fill: var(--verde); }
.robot--meta .robot__chasis { stroke: var(--verde); }

.robot--moviendo .robot__luz-estado,
.robot--girando .robot__luz-estado {
  animation: parpadeo-luz 0.4s infinite alternate;
}
@keyframes parpadeo-luz { from { opacity: 1; } to { opacity: 0.4; } }

/* ==========================================================================
   Consola del robot
   ========================================================================== */

.consola-robot {
  background: #050a14;
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  flex: 1;
  min-height: 110px;
  display: flex;
  flex-direction: column;
}
.consola-robot__titulo {
  font-family: var(--fuente-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--texto-muy-tenue);
  margin-bottom: 0.4rem;
}
.consola-robot__salida {
  font-family: var(--fuente-mono);
  font-size: 0.76rem;
  color: var(--cian);
  overflow-y: auto;
  max-height: 130px;
  flex: 1;
}
.consola-robot__linea { padding: 0.1rem 0; opacity: 0.9; }
.consola-robot__linea:last-child { color: var(--texto); font-weight: 600; }

/* ==========================================================================
   Zona 2 — Programacion
   ========================================================================== */

.controles-ejecucion { display: flex; gap: 0.5rem; }
.btn-control {
  font-family: var(--fuente-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: rgba(255, 255, 255, 0.03);
  color: var(--texto-tenue);
}
.btn-control:hover:not(:disabled) { color: var(--texto); }
.btn-control:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-control--ejecutar { color: var(--verde); border-color: rgba(51, 230, 166, 0.35); }
.btn-control--detener { color: var(--rojo); border-color: rgba(255, 77, 109, 0.35); }

.paleta {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.8rem;
  margin-bottom: 0.9rem;
}
.paleta__grupo { display: flex; flex-direction: column; gap: 0.4rem; }
.paleta__titulo {
  font-family: var(--fuente-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--texto-muy-tenue);
  margin: 0;
}

.bloque {
  display: flex;
  flex-direction: column;
  border-radius: 7px;
  font-family: var(--fuente-mono);
  font-size: 0.86rem;
  user-select: none;
  border: 1px solid transparent;
}
.bloque--paleta { cursor: grab; padding: 0.5rem 0.7rem; flex-direction: row; align-items: center; gap: 0.5rem; }
.bloque--paleta:active { cursor: grabbing; }

.bloque--movimiento { background: rgba(61, 127, 255, 0.14); border-color: rgba(61, 127, 255, 0.35); color: #bcd3ff; }
.bloque--control { background: rgba(139, 107, 255, 0.14); border-color: rgba(139, 107, 255, 0.35); color: #d8ccff; }
.bloque--sensor { background: rgba(47, 216, 255, 0.12); border-color: rgba(47, 216, 255, 0.35); color: #b8f2ff; }

.bloque__icono { font-size: 0.9rem; line-height: 1; }
.bloque__etiqueta { flex: 1; letter-spacing: 0.02em; }
.bloque__etiqueta--tenue { flex: none; opacity: 0.7; font-size: 0.68rem; }

.zona-hijos {
  min-height: 34px;
  border-left: 2px dashed rgba(255, 255, 255, 0.12);
  margin: 0.3rem 0 0.2rem 0.9rem;
  padding: 0.3rem 0 0.3rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.zona-hijos:empty::after {
  content: 'suelta bloques aquí';
  color: var(--texto-muy-tenue);
  font-size: 0.68rem;
  font-style: italic;
}
.zona-hijos--activa { background: rgba(47, 216, 255, 0.06); border-radius: 6px; }
.zona-hijos--raiz {
  min-height: 220px;
  /* Tope de altura: si se agregan muchos bloques, esta caja hace scroll
     por su cuenta en vez de estirar toda la pagina. El resto de la
     pantalla (controles arriba, boton de pista abajo) siempre se queda en
     su lugar. Esta columna ahora es dedicada solo al algoritmo, asi que
     tiene mas alto disponible que antes. */
  max-height: min(62vh, 620px);
  overflow-y: auto;
  border-left: none;
  margin: 0;
  padding: 0.6rem;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
}
.zona-hijos--raiz:empty::after { content: 'Arrastra bloques aquí para construir tu algoritmo'; }

.zona-programa-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; margin-bottom: 0.7rem; }
.zona-programa-titulo {
  display: flex;
  justify-content: space-between;
  font-family: var(--fuente-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--texto-muy-tenue);
  margin-bottom: 0.4rem;
}
.zona-programa-contador { color: var(--cian); }

.bloque:not(.bloque--paleta) {
  background: rgba(255, 255, 255, 0.03);
  padding: 0.1rem;
}
.bloque__cabecera {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.6rem;
  border-radius: 6px;
  cursor: grab;
}
.bloque--movimiento .bloque__cabecera { background: rgba(61, 127, 255, 0.16); }
.bloque--control .bloque__cabecera { background: rgba(139, 107, 255, 0.16); }
.bloque--sensor .bloque__cabecera { background: rgba(47, 216, 255, 0.14); }

.bloque__campo-veces {
  width: 2.6rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--borde);
  border-radius: 4px;
  color: var(--texto);
  font-family: var(--fuente-mono);
  padding: 0.15rem 0.3rem;
  text-align: center;
}

.bloque__campo-direccion {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--borde);
  border-radius: 4px;
  color: var(--texto);
  font-family: var(--fuente-mono);
  font-size: 0.68rem;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
}

.bloque__borrar {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--texto-muy-tenue);
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.bloque__borrar:hover { color: var(--rojo); background: rgba(255, 77, 109, 0.12); }

.bloque__rama { padding-left: 0.3rem; }
.bloque__rama-etiqueta {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--texto-muy-tenue);
  padding-left: 0.5rem;
}

.bloque--arrastrando { opacity: 0.35; }
.bloque--activo > .bloque__cabecera {
  box-shadow: 0 0 0 2px var(--cian), 0 0 14px rgba(47, 216, 255, 0.45);
}

.marcador-drop {
  height: 3px;
  background: var(--cian);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(47, 216, 255, 0.7);
  /* Puramente visual: nunca debe interceptar el evento de soltar que le
     corresponde al contenedor que esta debajo. */
  pointer-events: none;
}

.btn-pista {
  align-self: flex-start;
  font-family: var(--fuente-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 204, 77, 0.35);
  background: rgba(255, 204, 77, 0.08);
  color: var(--amarillo);
}
.btn-pista:hover { background: rgba(255, 204, 77, 0.16); }

/* ==========================================================================
   Zona 3 — Bloques disponibles + Panel del robot
   ========================================================================== */

.panel-robot { display: flex; flex-direction: column; gap: 0.55rem; font-family: var(--fuente-mono); }
.panel-robot__fila { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; font-size: 0.88rem; }
.panel-robot__etiqueta { color: var(--texto-muy-tenue); font-size: 0.66rem; letter-spacing: 0.06em; }
.panel-robot__valor { color: var(--texto); font-weight: 600; text-align: right; }
.panel-robot__valor--alerta { color: var(--rojo); }
.panel-robot__fila--objetivo .panel-robot__valor { color: var(--verde); font-size: 0.7rem; text-align: right; }
.panel-robot__separador { height: 1px; background: var(--borde); margin: 0.3rem 0; }

/* ==========================================================================
   Overlays / modales
   ========================================================================== */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 6, 13, 0.82);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(3px);
}
.overlay--activo { display: flex; }

.overlay__caja {
  background: linear-gradient(165deg, var(--bg-elevado), var(--bg-panel));
  border: 1px solid var(--borde-fuerte);
  border-radius: 14px;
  padding: 2rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.overlay__caja--exito { border-color: rgba(51, 230, 166, 0.4); }
.overlay__caja--error { border-color: rgba(255, 77, 109, 0.45); }
.overlay__caja--advertencia { border-color: rgba(255, 204, 77, 0.4); }
.overlay__caja--autonomo { border-color: var(--cian); box-shadow: 0 0 60px rgba(47, 216, 255, 0.25); }

.overlay__eyebrow {
  font-family: var(--fuente-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--verde);
  margin: 0 0 0.5rem;
}
.overlay__eyebrow--error { color: var(--rojo); }
.overlay__eyebrow--advertencia { color: var(--amarillo); }
.overlay__titulo { font-size: 1.4rem; margin-bottom: 1.1rem; }
.overlay__texto { color: var(--texto-tenue); font-size: 0.92rem; line-height: 1.5; }
.overlay__texto--tenue { font-size: 0.78rem; color: var(--texto-muy-tenue); margin-top: 0.8rem; }

.overlay__concepto {
  background: rgba(47, 216, 255, 0.06);
  border: 1px solid rgba(47, 216, 255, 0.25);
  border-radius: 8px;
  padding: 0.9rem;
  margin: 1rem 0;
}
.overlay__concepto-nombre {
  display: block;
  font-family: var(--fuente-mono);
  color: var(--cian);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}
.overlay__concepto p { margin: 0; font-size: 0.85rem; color: var(--texto-tenue); }

.overlay__stats { display: flex; justify-content: space-around; margin: 1.1rem 0; }
.overlay__stat { display: flex; flex-direction: column; }
.overlay__stat span { font-family: var(--fuente-mono); font-size: 1.4rem; font-weight: 700; color: var(--texto); }
.overlay__stat label { font-size: 0.62rem; letter-spacing: 0.08em; color: var(--texto-muy-tenue); }

.overlay__eficiencia { display: flex; justify-content: center; align-items: baseline; gap: 0.6rem; font-family: var(--fuente-mono); font-size: 0.75rem; color: var(--texto-tenue); margin-bottom: 1.4rem; letter-spacing: 0.08em; }
.estrellas { font-size: 1.2rem; color: var(--amarillo); letter-spacing: 0.15em; }

.overlay__comparacion { display: flex; align-items: center; justify-content: center; gap: 1.2rem; margin: 1.1rem 0; }
.overlay__comparacion-col { display: flex; flex-direction: column; align-items: center; }
.overlay__comparacion-numero { font-family: var(--fuente-mono); font-size: 1.8rem; font-weight: 700; }
.overlay__comparacion-numero--acento { color: var(--cian); }
.overlay__comparacion-col label { font-size: 0.62rem; letter-spacing: 0.06em; color: var(--texto-muy-tenue); margin-top: 0.2rem; }
.overlay__comparacion-flecha { color: var(--texto-muy-tenue); font-size: 1.2rem; }

.overlay__acciones { display: flex; gap: 0.7rem; justify-content: center; margin-top: 1.3rem; }

/* Modales pequenos (pista / instructor) */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(3, 6, 13, 0.82);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.modal-overlay--activo { display: flex; }
.modal-caja {
  background: var(--bg-elevado);
  border: 1px solid var(--borde-fuerte);
  border-radius: 12px;
  padding: 1.6rem;
  max-width: 420px;
  width: 100%;
}
.modal-caja--ancha { max-width: 480px; }
.modal-caja h3 { font-family: var(--fuente-mono); font-size: 0.95rem; letter-spacing: 0.05em; margin-bottom: 0.8rem; color: var(--cian); }
.modal-caja p { color: var(--texto-tenue); font-size: 0.86rem; line-height: 1.5; }
.modal-texto-tenue { font-size: 0.78rem; color: var(--texto-muy-tenue); }
.modal-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--borde);
  border-radius: 6px;
  color: var(--texto);
  font-family: var(--fuente-mono);
  margin: 0.6rem 0;
}
.modal-error { color: var(--rojo); font-size: 0.78rem; min-height: 1.1em; }
.modal-acciones { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; }
.instructor-panel { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.6rem; }
.instructor-panel .btn { width: 100%; }

/* ==========================================================================
   Pantallas: codigo / IA / final
   ========================================================================== */

.codigo__contenido, .ia__contenido, .final__contenido {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 3rem 1.6rem;
  text-align: center;
}

.codigo__eyebrow, .final__eyebrow { font-family: var(--fuente-mono); color: var(--cian); font-size: 0.75rem; letter-spacing: 0.12em; margin-bottom: 0.6rem; }
.codigo__titulo { font-size: clamp(1.1rem, 2.4vw, 1.5rem); line-height: 1.4; margin-bottom: 1.8rem; }

.codigo__columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; text-align: left; margin-bottom: 1.5rem; }
.editor { background: #060a14; border: 1px solid var(--borde); border-radius: 10px; overflow: hidden; }
.editor__barra { display: flex; align-items: center; gap: 0.4rem; padding: 0.55rem 0.8rem; background: #0b1120; border-bottom: 1px solid var(--borde); }
.editor__barra span:not(.editor__nombre) { width: 9px; height: 9px; border-radius: 50%; background: #384a6b; }
.editor__nombre { margin-left: 0.6rem; font-family: var(--fuente-mono); font-size: 0.68rem; color: var(--texto-muy-tenue); }
.editor__cuerpo {
  margin: 0;
  padding: 1rem 1.1rem;
  font-family: var(--fuente-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--cian);
  white-space: pre-wrap;
  min-height: 220px;
  max-height: 340px;
  overflow: auto;
}

.codigo__nota { color: var(--texto-muy-tenue); font-size: 0.8rem; margin-bottom: 1.6rem; }

.ia__titulo { font-size: clamp(1.2rem, 2.6vw, 1.6rem); margin-bottom: 2rem; }
.ia__diagrama { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; margin-bottom: 2rem; }
.ia__paso {
  font-family: var(--fuente-mono);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  padding: 0.7rem 1.6rem;
  border: 1px solid var(--borde-fuerte);
  border-radius: 8px;
  background: rgba(47, 216, 255, 0.06);
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.ia__paso-num {
  width: 1.5rem; height: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--cian);
  color: #04101f;
  font-weight: 700;
  font-size: 0.75rem;
}
.ia__flecha { color: var(--texto-muy-tenue); }
.ia__texto { color: var(--texto-tenue); font-size: 0.92rem; margin: 0 0 0.5rem; line-height: 1.55; }
.ia__texto--acento { color: var(--texto); font-weight: 600; }
.ia__texto--flujo { font-family: var(--fuente-mono); color: var(--cian); letter-spacing: 0.06em; margin: 0.8rem 0; }
.ia__texto--tenue { font-size: 0.78rem; color: var(--texto-muy-tenue); margin-top: 1.2rem; }

.final__titulo { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0.3rem 0 1rem; }

.final__equipo { margin: 0 0 1.4rem; font-family: var(--fuente-mono); }
.final__equipo-etiqueta { font-size: 0.65rem; letter-spacing: 0.1em; color: var(--texto-muy-tenue); margin-right: 0.6rem; }
.final__equipo #final-equipo-nombre { font-size: 1.05rem; font-weight: 700; color: var(--texto); letter-spacing: 0.02em; }

.final__logos-destacados {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.8rem;
  margin-bottom: 1.8rem;
}
.final__logo-destacado {
  height: 68px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.5));
}

.final__rango {
  display: inline-flex;
  flex-direction: column;
  padding: 1rem 2rem;
  border: 1px solid var(--borde-fuerte);
  border-radius: 10px;
  background: rgba(47, 216, 255, 0.06);
  margin-bottom: 1.8rem;
}
.final__rango-etiqueta { font-family: var(--fuente-mono); font-size: 0.65rem; letter-spacing: 0.1em; color: var(--texto-muy-tenue); }
.final__rango-valor { font-family: var(--fuente-mono); font-size: 1.5rem; font-weight: 700; color: var(--cian); letter-spacing: 0.04em; }

.final__puntaje {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.8rem;
}
.final__puntaje-etiqueta { font-family: var(--fuente-mono); font-size: 0.68rem; letter-spacing: 0.1em; color: var(--texto-muy-tenue); margin-bottom: 0.2rem; }
.final__puntaje-valor {
  font-family: var(--fuente-mono);
  font-size: clamp(4rem, 11vw, 6.5rem);
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(120deg, var(--verde), var(--cian));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(51, 230, 166, 0.25);
}

.final__stats { display: flex; justify-content: center; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.8rem; }
.final__stat { display: flex; flex-direction: column; }
.final__stat span { font-family: var(--fuente-mono); font-size: 1.6rem; font-weight: 700; }
.final__stat label { font-size: 0.62rem; letter-spacing: 0.08em; color: var(--texto-muy-tenue); }

.confeti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.confeti__pieza {
  position: absolute;
  top: -24px;
  width: 8px;
  height: 14px;
  opacity: 0.85;
  animation-name: caer-confeti;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes caer-confeti {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 0.9; }
  100% { transform: translateY(112vh) rotate(420deg); opacity: 0.7; }
}

.final__texto { color: var(--texto-tenue); font-size: 0.95rem; line-height: 1.6; margin: 0 auto 0.5rem; max-width: 620px; }
.final__texto--acento { color: var(--texto); font-weight: 600; margin-top: 1rem; }
.final__acciones { display: flex; gap: 0.8rem; justify-content: center; margin: 1.8rem 0; }
.pie-institucional--final { margin-top: 1rem; }

/* ==========================================================================
   Responsive
   ========================================================================== */

:root { --celda: 58px; }

@media (min-width: 1600px) { :root { --celda: 66px; } }

@media (max-width: 1360px) {
  .layout-juego { grid-template-columns: minmax(434px, 1.2fr) minmax(360px, 1.5fr) minmax(230px, 0.8fr); }
  :root { --celda: 50px; }
}

@media (max-width: 1180px) {
  .layout-juego { grid-template-columns: 1fr; }
  .zona-tablero, .zona-algoritmo, .zona-herramientas { grid-column: 1 / -1; }
  .zona-hijos--raiz { max-height: min(42vh, 420px); }
  :root { --celda: 46px; }
}

@media (max-width: 860px) {
  .layout-juego { grid-template-columns: 1fr; padding: 0.9rem; }
  .zona-tablero, .zona-algoritmo, .zona-herramientas { grid-column: 1 / -1; }
  .topbar { flex-direction: column; align-items: stretch; }
  .barra-niveles { justify-content: center; }
  .codigo__columnas { grid-template-columns: 1fr; }
  :root { --celda: 42px; }
}
