.fila-nivel {
    position: relative;
    display: flex;
    gap: clamp(15px, 3vw, 30px);
    margin: 30px 0;
    width: 100%;
    padding-left: clamp(60px, 8vw, 100px);
    flex-wrap: wrap;
    justify-content: center;
    z-index: 1;
}

.etiqueta-semestre {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: clamp(18px, 2.5vw, 28px);
    font-weight: 800;
    color: rgba(0, 242, 255, 0.4);
    letter-spacing: 2px;
    border-left: 3px solid #00f2ff;
    padding-left: 12px;
}

.etiqueta-semestre::before {
    content: "SEMESTRE";
    font-size: clamp(7px, 1vw, 10px);
    color: #94a3b8;
    letter-spacing: 3px;
    margin-bottom: 2px;
    display: block;
}

.nodo-ramo {
    /* Fondo sólido para que las líneas que pasan por detrás no se transparenten. */
    background: rgba(18, 24, 38, 0.92);
    border: 2px solid rgba(255, 255, 255, 0.22);
    color: white;
    padding: clamp(8px, 1.2vw, 14px) clamp(10px, 1.5vw, 16px);
    border-radius: 10px;
    cursor: pointer;
    width: clamp(110px, 14vw, 160px);
    min-width: 100px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.nodo-ramo.locked {
    opacity: 0.4;
    border-color: rgba(255, 255, 255, 0.08);
}

.nodo-ramo.locked .nombre {
    color: #666;
}

.nodo-ramo.aprobado {
    background: rgba(22, 78, 52, 0.92);
    border-color: #22c55e;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

.nodo-ramo:hover {
    border-color: #00f2ff;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
    transform: translateY(-2px);
}

.nodo-ramo.aprobado:hover {
    border-color: #4ade80;
}

.nodo-ramo.locked:hover {
    border-color: #f87171;
}

.nodo-ramo .sigla {
    font-weight: bold;
    font-size: 0.95em;
    display: block;
}

.nodo-ramo .nombre {
    font-size: 0.7em;
    color: #aaa;
    display: block;
    margin-top: 4px;
    line-height: 1.3;
}

.nodo-ramo.par::after {
    content: "PAR";
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 0.5em;
    color: rgba(255, 255, 255, 0.2);
    letter-spacing: 1px;
}

.nodo-ramo.impar::after {
    content: "IMPAR";
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 0.5em;
    color: rgba(255, 255, 255, 0.2);
    letter-spacing: 1px;
}

.lienzo-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.tree-container {
    position: relative;
    width: 100%;
}

.linea-conexion {
    fill: none;
    stroke: #00f2ff;
    stroke-width: 2.5px;
    stroke-dasharray: 8 5;
    filter: drop-shadow(0 0 5px rgba(0, 242, 255, 0.7));
    opacity: 0.6;
    animation: fluirEnergia 3s linear infinite;
}

.linea-apagada {
    display: none !important;
}

.linea-coreq {
    fill: none;
    stroke: #fbbf24;
    stroke-width: 2.5px;
    stroke-dasharray: 6 4;
    filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.8));
    opacity: 0.8;
    animation: fluirEnergiaAmarilla 2.5s linear infinite;
}

@keyframes fluirEnergia {
    to { stroke-dashoffset: -52; }
}

@keyframes fluirEnergiaAmarilla {
    to { stroke-dashoffset: -40; }
}

.tree-container.modo-enfoque .nodo-ramo {
    opacity: 0.22;
    filter: grayscale(0.6);
}

.tree-container.modo-enfoque .nodo-ramo.highlight-path,
.tree-container.modo-enfoque .nodo-ramo.highlight-unlock,
.tree-container.modo-enfoque .nodo-ramo.highlight-active {
    opacity: 1;
    filter: none;
}

.nodo-ramo.highlight-path {
    border-color: #fbbf24 !important;
    background: rgba(60, 45, 8, 0.95) !important;
    box-shadow: 0 0 28px rgba(251, 191, 36, 0.75), inset 0 0 14px rgba(251, 191, 36, 0.25) !important;
    transform: scale(1.08);
    z-index: 5;
}

.nodo-ramo.highlight-unlock {
    border-color: #22c55e !important;
    background: rgba(12, 55, 32, 0.95) !important;
    box-shadow: 0 0 28px rgba(34, 197, 94, 0.75), inset 0 0 14px rgba(34, 197, 94, 0.25) !important;
    transform: scale(1.05);
    z-index: 5;
}

.nodo-ramo.highlight-active {
    border-color: #00f2ff !important;
    background: rgba(6, 48, 60, 0.95) !important;
    box-shadow: 0 0 34px rgba(0, 242, 255, 0.85), inset 0 0 16px rgba(0, 242, 255, 0.3) !important;
    transform: scale(1.12);
    z-index: 6;
}

.nodo-ramo.highlight-path::before,
.nodo-ramo.highlight-unlock::before,
.nodo-ramo.highlight-active::before {
    position: absolute;
    top: -10px;
    left: 8px;
    font-size: 0.5em;
    font-weight: 800;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 5px;
    color: #000;
    white-space: nowrap;
    z-index: 7;
}

.nodo-ramo.highlight-path::before {
    content: "REQUISITO";
    background: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.8);
}

.nodo-ramo.highlight-unlock::before {
    content: "DESBLOQUEA";
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
}

.nodo-ramo.highlight-active::before {
    content: "SELECCIONADO";
    background: #00f2ff;
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.8);
}

/* En móvil la malla se desplaza como un mapa, sin envolver las filas. */
@media (max-width: 768px) {
    .tree-container {
        width: max-content;
        min-width: 100%;
        padding-bottom: 90px;
    }

    .fila-nivel {
        width: max-content;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 14px;
        margin: 22px 0;
        padding-left: 66px;
    }

    .etiqueta-semestre {
        font-size: 18px;
    }

    .nodo-ramo {
        width: 132px;
        min-width: 132px;
        padding: 11px 13px;
    }

    .nodo-ramo .sigla {
        font-size: 0.9em;
    }

    .nodo-ramo .nombre {
        font-size: 0.68em;
    }
}
